From 55ded30eb46955014823362f34148fc90d1e4e84 Mon Sep 17 00:00:00 2001 From: Joshua Day Date: Tue, 18 Dec 2018 23:09:54 -0600 Subject: [PATCH 1/5] add testing button --- webapp/src/app/live-edit.js | 78 +++++++++---------- webapp/src/app/sys-global-observables.js | 3 +- webapp/src/app/sys-runtime.js | 3 - .../compiler-controls/compiler-controls.html | 7 ++ .../compiler-controls/compiler-controls.js | 6 ++ .../play-activity-page/play-activity-page.js | 31 +++++++- 6 files changed, 84 insertions(+), 44 deletions(-) diff --git a/webapp/src/app/live-edit.js b/webapp/src/app/live-edit.js index 99802c08..c631c44c 100644 --- a/webapp/src/app/live-edit.js +++ b/webapp/src/app/live-edit.js @@ -32,48 +32,48 @@ class LiveEdit { .replace(/'/g, '''); } - processGccCompletion(result) { - SysGlobalObservables.gccErrorCount(0); - SysGlobalObservables.gccWarningCount(0); - - if (!result) { - // cancelled - SysGlobalObservables.compileStatus('Cancelled'); - return; - } - - // null if cancelled - // result = { 'exitcode':gcc_exit_code, 'stats':stats,'annotations':annotations,'gcc_ouput':gcc_output} - - this.runtime.sendKeys('tty0', 'clear\n'); - - const aceAnnotations = []; - const buildCmdErrors = []; - result.annotations.forEach((annotation) => { - if (annotation.isBuildCmdError) { - buildCmdErrors.push(annotation); + runCode(buildCmd, execCmd) { + console.log("in run code with next command"); + console.log(execCmd); + SysGlobalObservables.fileBrowser.saveActiveFile(); + const callback = (result) => { + SysGlobalObservables.gccErrorCount(0); + SysGlobalObservables.gccWarningCount(0); + + if (!result) { + // cancelled + SysGlobalObservables.compileStatus('Cancelled'); + return; + } + + // null if cancelled + // result = { 'exitcode':gcc_exit_code, 'stats':stats,'annotations':annotations,'gcc_ouput':gcc_output} + + this.runtime.sendKeys('tty0', 'clear\n'); + + const aceAnnotations = []; + const buildCmdErrors = []; + result.annotations.forEach((annotation) => { + if (annotation.isBuildCmdError) { + buildCmdErrors.push(annotation); + } else { + aceAnnotations.push(annotation); + } + }); + + SysGlobalObservables.editorAnnotations(aceAnnotations); + SysGlobalObservables.lastGccOutput(result.gccOutput); + SysGlobalObservables.gccErrorCount(result.stats.error); + SysGlobalObservables.gccWarningCount(result.stats.warning); + SysGlobalObservables.gccOptsError(buildCmdErrors.map((error) => error.text).join('\n')); + + if (result.exitCode === 0) { + SysGlobalObservables.compileStatus(result.stats.warning > 0 ? 'Warnings' : 'Success'); + this.runtime.sendExecCmd(execCmd); } else { - aceAnnotations.push(annotation); + SysGlobalObservables.compileStatus('Failed'); } - }); - - SysGlobalObservables.editorAnnotations(aceAnnotations); - SysGlobalObservables.lastGccOutput(result.gccOutput); - SysGlobalObservables.gccErrorCount(result.stats.error); - SysGlobalObservables.gccWarningCount(result.stats.warning); - SysGlobalObservables.gccOptsError(buildCmdErrors.map((error) => error.text).join('\n')); - - if (result.exitCode === 0) { - SysGlobalObservables.compileStatus(result.stats.warning > 0 ? 'Warnings' : 'Success'); - this.runtime.sendExecCmd(SysGlobalObservables.execCmd()); - } else { - SysGlobalObservables.compileStatus('Failed'); } - } - - runCode(buildCmd) { - SysGlobalObservables.fileBrowser.saveActiveFile(); - const callback = this.processGccCompletion.bind(this); SysGlobalObservables.compileStatus('Compiling'); this.runtime.startBuild(buildCmd, callback); } diff --git a/webapp/src/app/sys-global-observables.js b/webapp/src/app/sys-global-observables.js index dc1b8090..28dabe62 100644 --- a/webapp/src/app/sys-global-observables.js +++ b/webapp/src/app/sys-global-observables.js @@ -4,10 +4,11 @@ export const vmState = ko.observable(''); export const compileStatus = ko.observable(''); export const focusTerm = ko.observable((tty) => {}); -export const runCode = ko.observable((gccOptions) => {}); +export const runCode = ko.observable((gccOptions, nextCommand) => {}); export const buildCmd = ko.observable(''); export const execCmd = ko.observable(''); +export const testCmd = ko.observable(''); export const lastGccOutput = ko.observable(''); export const gccOptsError = ko.observable(''); diff --git a/webapp/src/app/sys-runtime.js b/webapp/src/app/sys-runtime.js index 270c3a55..95b89167 100644 --- a/webapp/src/app/sys-runtime.js +++ b/webapp/src/app/sys-runtime.js @@ -226,9 +226,6 @@ class SysRuntime { if (!cmd) { return; } - if (cmd[0] !== '/' && cmd[0] !== '.') { - cmd = './' + cmd.replace(' ', '\\ '); - } cmd = cmd.replace('\\', '\\\\').replace('\n', '\\n'); // Don't \x03 ; it interrupts the clear command this.sendKeys('tty0', '\n' + cmd + '\n'); diff --git a/webapp/src/components/compiler-controls/compiler-controls.html b/webapp/src/components/compiler-controls/compiler-controls.html index b5413a3a..dedd71e8 100644 --- a/webapp/src/components/compiler-controls/compiler-controls.html +++ b/webapp/src/components/compiler-controls/compiler-controls.html @@ -23,5 +23,12 @@ Run It
+ diff --git a/webapp/src/components/compiler-controls/compiler-controls.js b/webapp/src/components/compiler-controls/compiler-controls.js index 63638730..edf4f86d 100644 --- a/webapp/src/components/compiler-controls/compiler-controls.js +++ b/webapp/src/components/compiler-controls/compiler-controls.js @@ -29,6 +29,12 @@ class CompilerControls { $compileBtn.popover('hide'); }); + const $testBtn = $('#test-btn'); + $testBtn.click(() => { + params.testCallback(); + $testBtn.popover('hide'); + }); + // Initialize Bootstrap popovers $compileBtn.popover(); // We don't want the "gcc opts errors" popover to be dismissed when clicked diff --git a/webapp/src/components/play-activity-page/play-activity-page.js b/webapp/src/components/play-activity-page/play-activity-page.js index 329493a5..d0571813 100644 --- a/webapp/src/components/play-activity-page/play-activity-page.js +++ b/webapp/src/components/play-activity-page/play-activity-page.js @@ -23,6 +23,7 @@ int main() { `; const defaultBuildCmd = 'gcc -lm -Wall -fmax-errors=10 -Wextra program.c -o program'; const defaultExecCmd = './program'; +const defaultTestCmd = 'echo "No tests!"'; class PlayActivityPage { @@ -63,6 +64,14 @@ class PlayActivityPage { } this.compilerParams.execCmd(execCmd); + let testCmd = defaultTestCmd; + if (typeof playActivity.testCmd !== 'undefined') { + testCmd = playActivity.testCmd; + } else if (typeof playActivity.programCommandLineArgs !== 'undefined') { + testCmd = `./program ${playActivity.programCommandLineArgs}`; + } + this.compilerParams.testCmd(testCmd); + if (playActivity.docFile) { this.doc = { url: 'https://cs-education.github.io/sysassets/' + playActivity.docFile, @@ -80,6 +89,7 @@ class PlayActivityPage { this.editorParams.initialEditorText = defaultEditorText; this.compilerParams.buildCmd(defaultBuildCmd); this.compilerParams.execCmd(defaultExecCmd); + this.compilerParams.testCmd(defaultTestCmd) this.doc = { text: '# Welcome\n' + @@ -129,6 +139,7 @@ class PlayActivityPage { this.compilerParams = { buildCmd: SysGlobalObservables.buildCmd, execCmd: SysGlobalObservables.execCmd, + testCmd: SysGlobalObservables.testCmd, compileStatus: SysGlobalObservables.compileStatus, lastGccOutput: SysGlobalObservables.lastGccOutput, gccOptsError: SysGlobalObservables.gccOptsError, @@ -155,11 +166,29 @@ class PlayActivityPage { this.autoIncluder.addMissingHeaders(this.editorParams.editorTextGetter); } const buildCmd = this.compilerParams.buildCmd(); - (SysGlobalObservables.runCode())(buildCmd); + const execCmd = this.compilerParams.execCmd(); + + console.log(execCmd); + + (SysGlobalObservables.runCode())(buildCmd, execCmd); }; this.compilerParams.compileCallback = compile; + const compileAndTest = () => { + if (this.editorParams.autoInclude()) { + this.autoIncluder.addMissingHeaders(this.editorParams.editorTextGetter); + } + const buildCmd = this.compilerParams.buildCmd(); + const testCmd = this.compilerParams.testCmd(); + + console.log(testCmd); + + (SysGlobalObservables.runCode())(buildCmd, testCmd); + }; + + this.compilerParams.testCallback = compileAndTest; + this.editorParams.keyboardShortcuts.push([ 'compileAndRunShortcut', compileShortcut, From 7366731abde6cb8428041ed877a462e7c4b7c294 Mon Sep 17 00:00:00 2001 From: Joshua Day Date: Wed, 19 Dec 2018 01:17:36 -0600 Subject: [PATCH 2/5] Removed debuggging log statements --- webapp/src/app/live-edit.js | 2 -- .../src/components/play-activity-page/play-activity-page.js | 4 ---- 2 files changed, 6 deletions(-) diff --git a/webapp/src/app/live-edit.js b/webapp/src/app/live-edit.js index c631c44c..41cf355f 100644 --- a/webapp/src/app/live-edit.js +++ b/webapp/src/app/live-edit.js @@ -33,8 +33,6 @@ class LiveEdit { } runCode(buildCmd, execCmd) { - console.log("in run code with next command"); - console.log(execCmd); SysGlobalObservables.fileBrowser.saveActiveFile(); const callback = (result) => { SysGlobalObservables.gccErrorCount(0); diff --git a/webapp/src/components/play-activity-page/play-activity-page.js b/webapp/src/components/play-activity-page/play-activity-page.js index d0571813..8c496e93 100644 --- a/webapp/src/components/play-activity-page/play-activity-page.js +++ b/webapp/src/components/play-activity-page/play-activity-page.js @@ -168,8 +168,6 @@ class PlayActivityPage { const buildCmd = this.compilerParams.buildCmd(); const execCmd = this.compilerParams.execCmd(); - console.log(execCmd); - (SysGlobalObservables.runCode())(buildCmd, execCmd); }; @@ -182,8 +180,6 @@ class PlayActivityPage { const buildCmd = this.compilerParams.buildCmd(); const testCmd = this.compilerParams.testCmd(); - console.log(testCmd); - (SysGlobalObservables.runCode())(buildCmd, testCmd); }; From 97e000888532dd6222649c5e8bfe616ad00b99ca Mon Sep 17 00:00:00 2001 From: Joshua Day Date: Wed, 19 Dec 2018 02:58:16 -0600 Subject: [PATCH 3/5] implemented basic autograder selection and hiding test button --- .../compiler-controls/compiler-controls.js | 6 ++++++ .../play-activity-page/play-activity-page.js | 17 +++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/webapp/src/components/compiler-controls/compiler-controls.js b/webapp/src/components/compiler-controls/compiler-controls.js index edf4f86d..3df62c40 100644 --- a/webapp/src/components/compiler-controls/compiler-controls.js +++ b/webapp/src/components/compiler-controls/compiler-controls.js @@ -35,6 +35,12 @@ class CompilerControls { $testBtn.popover('hide'); }); + if (params.enableTest) { + $testBtn.show(); + } else { + $testBtn.hide(); + } + // Initialize Bootstrap popovers $compileBtn.popover(); // We don't want the "gcc opts errors" popover to be dismissed when clicked diff --git a/webapp/src/components/play-activity-page/play-activity-page.js b/webapp/src/components/play-activity-page/play-activity-page.js index 8c496e93..49e5db04 100644 --- a/webapp/src/components/play-activity-page/play-activity-page.js +++ b/webapp/src/components/play-activity-page/play-activity-page.js @@ -65,10 +65,19 @@ class PlayActivityPage { this.compilerParams.execCmd(execCmd); let testCmd = defaultTestCmd; - if (typeof playActivity.testCmd !== 'undefined') { - testCmd = playActivity.testCmd; - } else if (typeof playActivity.programCommandLineArgs !== 'undefined') { - testCmd = `./program ${playActivity.programCommandLineArgs}`; + this.compilerParams.enableTest = true; + if (typeof playActivity.testType !== 'undefined') { + if (playActivity.testType == "cmd") { + testCmd = playActivity.testCmd; + } else if (playActivity.testType == "returnValue") { + testCmd = `output=$(${execCmd}); status=$?; correctStatus=${playActivity.returnValue}; if [ $status = $correctStatus ]; then echo "Looks Good!"; else echo "Return value wrong!"; echo returned $status when expected $correctStatus fi` + } else if (playActivity.testType == "stdout") { + testCmd = `output=$(${execCmd}); status=$?; correctOut="${playActivity.stdout}"; if [ $output = $correctOut ]; then echo "Looks Good!"; else echo "Output wrong!"; echo returned; echo $output; echo expected; echo $correctOut fi` + } else if (playActivity.test == "returnValueAndStdout") { + testCmd = `output=$(${execCmd}); status=$?; correctStatus=${playActivity.returnValue}; correctOut="${playActivity.stdout}"; if [ $status = $correctStatus ]; then echo "Looks Good!"; else echo "Return value wrong!"; echo returned $status when expected $correctStatus fi; if [ $output = $correctOut ]; then echo "Looks Good!"; else echo "Output wrong!"; echo returned; echo $output; echo expected; echo $correctOut fi` + } + } else { + this.compilerParams.enableTest = false; } this.compilerParams.testCmd(testCmd); From cb3a3f40b2fc6260f52162122382b266da533f98 Mon Sep 17 00:00:00 2001 From: Joshua Day Date: Fri, 21 Dec 2018 09:09:03 -0600 Subject: [PATCH 4/5] fixed test function --- .../play-activity-page/play-activity-page.js | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/webapp/src/components/play-activity-page/play-activity-page.js b/webapp/src/components/play-activity-page/play-activity-page.js index 49e5db04..dc5557d2 100644 --- a/webapp/src/components/play-activity-page/play-activity-page.js +++ b/webapp/src/components/play-activity-page/play-activity-page.js @@ -66,16 +66,10 @@ class PlayActivityPage { let testCmd = defaultTestCmd; this.compilerParams.enableTest = true; - if (typeof playActivity.testType !== 'undefined') { - if (playActivity.testType == "cmd") { - testCmd = playActivity.testCmd; - } else if (playActivity.testType == "returnValue") { - testCmd = `output=$(${execCmd}); status=$?; correctStatus=${playActivity.returnValue}; if [ $status = $correctStatus ]; then echo "Looks Good!"; else echo "Return value wrong!"; echo returned $status when expected $correctStatus fi` - } else if (playActivity.testType == "stdout") { - testCmd = `output=$(${execCmd}); status=$?; correctOut="${playActivity.stdout}"; if [ $output = $correctOut ]; then echo "Looks Good!"; else echo "Output wrong!"; echo returned; echo $output; echo expected; echo $correctOut fi` - } else if (playActivity.test == "returnValueAndStdout") { - testCmd = `output=$(${execCmd}); status=$?; correctStatus=${playActivity.returnValue}; correctOut="${playActivity.stdout}"; if [ $status = $correctStatus ]; then echo "Looks Good!"; else echo "Return value wrong!"; echo returned $status when expected $correctStatus fi; if [ $output = $correctOut ]; then echo "Looks Good!"; else echo "Output wrong!"; echo returned; echo $output; echo expected; echo $correctOut fi` - } + if (typeof playActivity.testCmd !== 'undefined') { + testCmd = playActivity.testCmd + } else if (typeof playActivity.testLocation !== 'undefined') { + testCmd = `curl -s ${playActivity.testLocation} | bash -s` } else { this.compilerParams.enableTest = false; } From 1920b87a5a7de05fc5fd6e74dc8c61250b61aa56 Mon Sep 17 00:00:00 2001 From: Joshua Day Date: Sat, 22 Dec 2018 03:03:28 -0600 Subject: [PATCH 5/5] Changed test call from curl to running script --- webapp/src/components/play-activity-page/play-activity-page.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webapp/src/components/play-activity-page/play-activity-page.js b/webapp/src/components/play-activity-page/play-activity-page.js index dc5557d2..d01bd463 100644 --- a/webapp/src/components/play-activity-page/play-activity-page.js +++ b/webapp/src/components/play-activity-page/play-activity-page.js @@ -69,7 +69,7 @@ class PlayActivityPage { if (typeof playActivity.testCmd !== 'undefined') { testCmd = playActivity.testCmd } else if (typeof playActivity.testLocation !== 'undefined') { - testCmd = `curl -s ${playActivity.testLocation} | bash -s` + testCmd = `${playActivity.testLocation}` } else { this.compilerParams.enableTest = false; }