@@ -66,6 +66,35 @@ function initTestcasesPane(parentDivId) {
6666 $ ( "#addNewTestCase" ) . click ( ) ; // for testing
6767}
6868
69+ function getCombinedCode ( id ) {
70+ var userCod = pyInputGetValue ( ) ;
71+ var testCod = ace . edit ( 'testCaseEditor_' + id ) . getValue ( ) ;
72+ // for reporting syntax errors separately for user and test code
73+ var userCodNumLines = userCod . split ( '\n' ) . length ;
74+
75+ var bufferCod = '\n\n### Test code ###\n' ;
76+ var bufferCodNumLines = bufferCod . split ( '\n' ) . length ;
77+
78+ var combinedCod = userCod + bufferCod + testCod ;
79+ return { cod : combinedCod ,
80+ firstTestLine : userCodNumLines + bufferCodNumLines - 1 } ;
81+ }
82+
83+ function startRunningTest ( ) {
84+ $ ( "#runAllTestsButton,.runTestCase,.vizTestCase" ) . attr ( 'disabled' , true ) ;
85+ }
86+
87+ function doneRunningTest ( ) {
88+ $ ( "#runAllTestsButton,.runTestCase,.vizTestCase" ) . attr ( 'disabled' , false ) ;
89+ $ ( ".runTestCase" ) . html ( 'Run' ) ;
90+ $ ( ".vizTestCase" ) . html ( 'Visualize' ) ;
91+ }
92+
93+ function runTestFinishSuccessfulExecution ( ) {
94+ optFinishSuccessfulExecution ( ) ;
95+ doneRunningTest ( ) ;
96+ }
97+
6998function addTestcase ( id ) {
7099 var newTr = $ ( '<tr/>' ) . attr ( 'id' , 'testCaseRow_' + id ) ;
71100 $ ( "#testCasesTable tbody" ) . append ( newTr ) ;
@@ -76,9 +105,9 @@ function addTestcase(id) {
76105 var deleteTd = $ ( '<td/>' ) ;
77106
78107 editorTd . append ( '<div id="testCaseEditor_' + id + '" class="testCaseEditor">' ) ;
79- runBtnTd . append ( '<button id="runTestCase_' + id + '" type="button">Run</button>' ) ;
108+ runBtnTd . append ( '<button id="runTestCase_' + id + '" class="runTestCase" type="button">Run</button>' ) ;
80109 outputTd . attr ( 'id' , 'outputTd_' + id ) ;
81- visualizeTd . append ( '<button id="vizTestCase_' + id + '" type="button">Visualize</button>' ) ;
110+ visualizeTd . append ( '<button id="vizTestCase_' + id + '" class="vizTestCase" type="button">Visualize</button>' ) ;
82111 deleteTd . append ( '<a id="delTestCase_' + id + '" href="javascript:void(0);">Delete test</a></td>' ) ;
83112
84113 newTr . append ( editorTd ) ;
@@ -89,20 +118,43 @@ function addTestcase(id) {
89118
90119 $ ( '#runTestCase_' + id ) . click ( function ( ) {
91120 $ ( this ) . html ( "Running ..." ) ;
92- $ ( this ) . attr ( 'disabled' , true ) ;
93- startExecutingCode ( ) ;
94- var userCod = pyInputGetValue ( ) ;
95- var testCod = ace . edit ( 'testCaseEditor_' + id ) . getValue ( ) ;
96- // for reporting syntax errors separately for user and test code
97- var userCodNumLines = userCod . split ( '\n' ) . length ;
98-
99- var bufferCod = '\n\n# Test code:\n' ;
100- var bufferCodNumLines = bufferCod . split ( '\n' ) . length ;
101-
102- var combinedCod = userCod + bufferCod + testCod ;
103- console . log ( combinedCod ) ;
121+ startRunningTest ( ) ;
122+ var dat = getCombinedCode ( id ) ;
123+ console . log ( dat . cod ) ;
124+ console . log ( dat . firstTestLine ) ;
125+ } ) ;
126+
127+ $ ( '#vizTestCase_' + id ) . click ( function ( ) {
128+ $ ( this ) . html ( "Visualizing ..." ) ;
129+ startRunningTest ( ) ;
130+ var dat = getCombinedCode ( id ) ;
131+ console . log ( dat . cod ) ;
132+ console . log ( dat . firstTestLine ) ;
133+
134+ // adapted from executeCode in opt-frontend.js
135+ var backend_script = langToBackendScript ( $ ( '#pythonVersionSelector' ) . val ( ) ) ;
136+ var backendOptionsObj = getBaseBackendOptionsObj ( ) ;
137+ var frontendOptionsObj = getBaseFrontendOptionsObj ( ) ;
138+ frontendOptionsObj . jumpToEnd = true ;
139+
140+ 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)
145+ handleUncaughtExceptionFunc ( trace ) ;
146+ doneRunningTest ( ) ;
147+ }
148+
149+ executeCodeAndCreateViz ( dat . cod ,
150+ backend_script , backendOptionsObj ,
151+ frontendOptionsObj ,
152+ 'pyOutputPane' ,
153+ runTestFinishSuccessfulExecution ,
154+ runTestHandleUncaughtExceptionFunc ) ;
104155 } ) ;
105156
157+
106158 $ ( '#delTestCase_' + id ) . click ( function ( ) {
107159 var res = confirm ( "Press OK to delete this test." ) ;
108160 if ( res ) {
0 commit comments