@@ -116,12 +116,54 @@ function addTestcase(id) {
116116 newTr . append ( visualizeTd ) ;
117117 newTr . append ( deleteTd ) ;
118118
119+
120+ // initialize testCaseEditor with Ace:
121+ var te = ace . edit ( 'testCaseEditor_' + id ) ;
122+ // set the size and value ASAP to get alignment working well ...
123+ te . setOptions ( { minLines : 2 , maxLines : 4 } ) ; // keep this SMALL
124+ te . setHighlightActiveLine ( false ) ;
125+ te . setShowPrintMargin ( false ) ;
126+ te . setBehavioursEnabled ( false ) ;
127+ te . setFontSize ( 10 ) ;
128+ //te.setReadOnly(true);
129+
130+ var s = te . getSession ( ) ;
131+ s . setTabSize ( 2 ) ;
132+ s . setUseSoftTabs ( true ) ;
133+ // disable extraneous indicators:
134+ s . setFoldStyle ( 'manual' ) ; // no code folding indicators
135+ // don't do real-time syntax checks:
136+ // https://github.com/ajaxorg/ace/wiki/Syntax-validation
137+ s . setOption ( "useWorker" , false ) ;
138+
139+ // TODO: change syntax highlighting mode if the user changes languages:
140+ var lang = $ ( '#pythonVersionSelector' ) . val ( ) ;
141+ var mod = 'python' ;
142+ if ( lang === 'java' ) {
143+ mod = 'java' ;
144+ } else if ( lang === 'js' ) {
145+ mod = 'javascript' ;
146+ } else if ( lang === 'ts' ) {
147+ mod = 'typescript' ;
148+ } else if ( lang === 'ruby' ) {
149+ mod = 'ruby' ;
150+ }
151+ s . setMode ( "ace/mode/" + mod ) ;
152+
153+
119154 $ ( '#runTestCase_' + id ) . click ( function ( ) {
120155 $ ( this ) . html ( "Running ..." ) ;
121156 startRunningTest ( ) ;
122157 var dat = getCombinedCode ( id ) ;
123158 console . log ( dat . cod ) ;
124159 console . log ( dat . firstTestLine ) ;
160+
161+ // adapted from executeCode in opt-frontend.js
162+ var backend_script = langToBackendScript ( $ ( '#pythonVersionSelector' ) . val ( ) ) ;
163+ var backendOptionsObj = getBaseBackendOptionsObj ( ) ;
164+ backendOptionsObj . run_test_case = true ; // just so we can see this in server logs
165+ var frontendOptionsObj = getBaseFrontendOptionsObj ( ) ;
166+ frontendOptionsObj . jumpToEnd = true ;
125167 } ) ;
126168
127169 $ ( '#vizTestCase_' + id ) . click ( function ( ) {
@@ -134,14 +176,27 @@ function addTestcase(id) {
134176 // adapted from executeCode in opt-frontend.js
135177 var backend_script = langToBackendScript ( $ ( '#pythonVersionSelector' ) . val ( ) ) ;
136178 var backendOptionsObj = getBaseBackendOptionsObj ( ) ;
179+ backendOptionsObj . viz_test_case = true ; // just so we can see this in server logs
137180 var frontendOptionsObj = getBaseFrontendOptionsObj ( ) ;
138181 frontendOptionsObj . jumpToEnd = true ;
139182
140183 function runTestHandleUncaughtExceptionFunc ( trace ) {
141- // TODO: use dat.firstTestLine to see if the syntax error is in
142- // the test code, and if it is, then display error indicator in
143- // the test code gutter and in the 'results' table cell
144- // (remember to clear marks on edit, though)
184+ if ( trace . length == 1 && trace [ 0 ] . line ) {
185+ var errorLineNo = trace [ 0 ] . line ;
186+ // highlight the faulting line in the test case pane itself
187+ if ( errorLineNo !== undefined &&
188+ errorLineNo != NaN &&
189+ errorLineNo >= dat . firstTestLine ) {
190+ var adjustedErrorLineNo = errorLineNo - dat . firstTestLine ;
191+ s . setAnnotations ( [ { row : adjustedErrorLineNo ,
192+ type : 'error' ,
193+ text : trace [ 0 ] . exception_msg } ] ) ;
194+ te . gotoLine ( adjustedErrorLineNo + 1 /* one-indexed */ ) ;
195+
196+ $ ( '#outputTd_' + id ) . html ( 'Error in test code' ) ;
197+ }
198+ }
199+
145200 handleUncaughtExceptionFunc ( trace ) ;
146201 doneRunningTest ( ) ;
147202 }
@@ -163,38 +218,6 @@ function addTestcase(id) {
163218 return false ; // to prevent link from being followed
164219 } ) ;
165220
166- // initialize testCaseEditor with Ace:
167- var te = ace . edit ( 'testCaseEditor_' + id ) ;
168- // set the size and value ASAP to get alignment working well ...
169- te . setOptions ( { minLines : 2 , maxLines : 4 } ) ; // keep this SMALL
170- te . setHighlightActiveLine ( false ) ;
171- te . setShowPrintMargin ( false ) ;
172- te . setBehavioursEnabled ( false ) ;
173- te . setFontSize ( 10 ) ;
174- //te.setReadOnly(true);
175-
176- var s = te . getSession ( ) ;
177- s . setTabSize ( 2 ) ;
178- s . setUseSoftTabs ( true ) ;
179- // disable extraneous indicators:
180- s . setFoldStyle ( 'manual' ) ; // no code folding indicators
181- // don't do real-time syntax checks:
182- // https://github.com/ajaxorg/ace/wiki/Syntax-validation
183- s . setOption ( "useWorker" , false ) ;
184-
185- // TODO: change syntax highlighting mode if the user changes languages:
186- var lang = $ ( '#pythonVersionSelector' ) . val ( ) ;
187- var mod = 'python' ;
188- if ( lang === 'java' ) {
189- mod = 'java' ;
190- } else if ( lang === 'js' ) {
191- mod = 'javascript' ;
192- } else if ( lang === 'ts' ) {
193- mod = 'typescript' ;
194- } else if ( lang === 'ruby' ) {
195- mod = 'ruby' ;
196- }
197- s . setMode ( "ace/mode/" + mod ) ;
198221}
199222
200223// returns a list of strings, each of which is a test case
0 commit comments