@@ -50,6 +50,9 @@ function parseBuildError(stdout) {
5050 // Error running the command: cmake --build
5151 const regex = / c m a k e - - b u i l d [ \s \S ] * ?c m a k e - - b u i l d / ;
5252 const match = stdout . match ( regex ) ;
53+ if ( ! match || match . length === 0 ) {
54+ return stdout ;
55+ }
5356 const buildError = match [ 0 ] . split ( '\n' ) . slice ( 1 , - 1 ) . join ( '\n' ) ;
5457
5558 return buildError ;
@@ -124,7 +127,7 @@ function setTestResults(results) {
124127 document . getElementById ( 'tab-test-results-button' ) . click ( ) ;
125128}
126129
127- function run ( ) {
130+ function run ( callback , testcase = 'All' ) {
128131 saveSolution ( 'cpp' , editor . getValue ( ) ) ;
129132 const pathsFile = DirectoryManager . getPathsFile ( ) ;
130133 if ( ! file . existsSync ( pathsFile ) ) {
@@ -139,8 +142,11 @@ function run() {
139142 `--problem_builds_dir ${ problemBuildsDir } ` +
140143 `--language cpp ` +
141144 `--problem ${ activeProblem } ` +
145+ `--testcase ${ testcase } ` +
142146 `--verbose` ;
143147
148+ console . log ( "Running command: " + command ) ;
149+
144150 var resultsFilename ;
145151 exec ( command , ( error , stdout , stderr ) => {
146152 if ( error ) {
@@ -165,10 +171,54 @@ function run() {
165171 const results = file . readFileSync ( resultsFilename , 'utf8' ) ;
166172 console . log ( results ) ;
167173 const resultsJson = JSON . parse ( results ) ;
168- setTestResults ( resultsJson ) ;
174+ callback ( resultsJson ) ;
169175 } ) ;
170176}
171177
178+ function setCustomTestcaseResults ( results ) {
179+ if ( ! validateResults ( results ) ) {
180+ return ;
181+ }
182+
183+ if ( results . tests . length !== 1 ) {
184+ console . error ( "Expected 1 custom test results, got " +
185+ results . tests . length ) ;
186+ return ;
187+ }
188+
189+ if ( results . tests [ 0 ] . status !== "Skipped" ) {
190+ console . error ( "Expected custom test status to be skipped, got " +
191+ results . tests [ 0 ] . status ) ;
192+ }
193+
194+ document . getElementById ( 'testcase-stdout' ) . textContent = results . stdout ;
195+ document . getElementById ( 'testcase-output' ) . textContent =
196+ results . tests [ 0 ] . actual ;
197+ }
198+
199+ function runCustomTestcase ( ) {
200+ console . log ( "Running custom testcase for " + activeProblem ) ;
201+
202+ const input = document . getElementById ( 'input-container' ) . value + "\n*" ;
203+ const customTestcaseFilename =
204+ directoryManager . getCustomTestcaseFilename ( activeProblem ) ;
205+ if ( ! file . existsSync ( path . dirname ( customTestcaseFilename ) ) ) {
206+ console . log ( 'The directory does not exist. Directory: ' + path . dirname ( customTestcaseFilename ) ) ;
207+ return ;
208+ }
209+
210+ file . writeFileSync ( customTestcaseFilename , input ) ;
211+ if ( ! file . existsSync ( customTestcaseFilename ) ) {
212+ throw new Error ( `Failed to write custom testcase to ` +
213+ `${ customTestcaseFilename } ` ) ;
214+ }
215+
216+ console . log ( 'Custom testcase written to ' + customTestcaseFilename ) ;
217+ console . log ( 'Testcase input: ' + input ) ;
218+
219+ run ( setCustomTestcaseResults , directoryManager . getCustomTestcaseName ( ) ) ;
220+ }
221+
172222function setDescription ( problemName ) {
173223 var element =
174224 document . querySelector ( '.markdown-content#description-content' ) ;
@@ -229,13 +279,26 @@ function initializeSaveCommand() {
229279function initializeRunCommand ( ) {
230280 ipcRenderer . on ( 'run-command' , ( ) => {
231281 console . log ( 'Received run command' ) ;
232- run ( ) ;
282+ run ( setTestResults ) ;
233283 } ) ;
234284
235285 document . getElementById ( 'run-button' )
236286 . addEventListener ( 'click' , function ( ) {
237287 console . log ( 'Run button clicked' ) ;
238- run ( ) ;
288+ run ( setTestResults ) ;
289+ } ) ;
290+ }
291+
292+ function initializeCustomTestcaseCommand ( ) {
293+ ipcRenderer . on ( 'custom-testcase-command' , ( ) => {
294+ console . log ( 'Received custom testcase command' ) ;
295+ runCustomTestcase ( ) ;
296+ } ) ;
297+
298+ document . getElementById ( 'custom-testcase-button' )
299+ . addEventListener ( 'click' , function ( ) {
300+ console . log ( 'Custom testcase button clicked' ) ;
301+ runCustomTestcase ( ) ;
239302 } ) ;
240303}
241304
@@ -247,6 +310,7 @@ document.addEventListener('DOMContentLoaded', (event) => {
247310 initializeProblemsCombo ( problemNames ) ;
248311 initializeSaveCommand ( ) ;
249312 initializeRunCommand ( ) ;
313+ initializeCustomTestcaseCommand ( ) ;
250314
251315 amdRequire ( [ 'vs/editor/editor.main' ] , function ( ) {
252316 monaco . editor . setTheme ( 'vs-dark' ) ;
0 commit comments