Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Testing Framework #177

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 37 additions & 39 deletions webapp/src/app/live-edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,48 +32,46 @@ 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) {
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);
}
Expand Down
3 changes: 2 additions & 1 deletion webapp/src/app/sys-global-observables.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('');
Expand Down
3 changes: 0 additions & 3 deletions webapp/src/app/sys-runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,12 @@
Run It<br>
<span class="glyphicon glyphicon-play"></span>
</button>
<button id="test-btn"
data-bind="enable: compileBtnEnable, css: { 'btn-success': compileBtnEnable }, attr: { 'data-content': compileBtnTooltip }"
data-toggle="popover" data-placement="top" data-trigger="hover focus" data-container="body"
type="button" class="btn btn-xs pull-right col-sm-2" disabled="disabled">
Test It<br>
<span class="glyphicon glyphicon-play"></span>
</button>
</div>
</div>
12 changes: 12 additions & 0 deletions webapp/src/components/compiler-controls/compiler-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ class CompilerControls {
$compileBtn.popover('hide');
});

const $testBtn = $('#test-btn');
$testBtn.click(() => {
params.testCallback();
$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
Expand Down
30 changes: 29 additions & 1 deletion webapp/src/components/play-activity-page/play-activity-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -63,6 +64,17 @@ class PlayActivityPage {
}
this.compilerParams.execCmd(execCmd);

let testCmd = defaultTestCmd;
this.compilerParams.enableTest = true;
if (typeof playActivity.testCmd !== 'undefined') {
testCmd = playActivity.testCmd
} else if (typeof playActivity.testLocation !== 'undefined') {
testCmd = `${playActivity.testLocation}`
} else {
this.compilerParams.enableTest = false;
}
this.compilerParams.testCmd(testCmd);

if (playActivity.docFile) {
this.doc = {
url: 'https://cs-education.github.io/sysassets/' + playActivity.docFile,
Expand All @@ -80,6 +92,7 @@ class PlayActivityPage {
this.editorParams.initialEditorText = defaultEditorText;
this.compilerParams.buildCmd(defaultBuildCmd);
this.compilerParams.execCmd(defaultExecCmd);
this.compilerParams.testCmd(defaultTestCmd)

this.doc = {
text: '# Welcome\n' +
Expand Down Expand Up @@ -129,6 +142,7 @@ class PlayActivityPage {
this.compilerParams = {
buildCmd: SysGlobalObservables.buildCmd,
execCmd: SysGlobalObservables.execCmd,
testCmd: SysGlobalObservables.testCmd,
compileStatus: SysGlobalObservables.compileStatus,
lastGccOutput: SysGlobalObservables.lastGccOutput,
gccOptsError: SysGlobalObservables.gccOptsError,
Expand All @@ -155,11 +169,25 @@ class PlayActivityPage {
this.autoIncluder.addMissingHeaders(this.editorParams.editorTextGetter);
}
const buildCmd = this.compilerParams.buildCmd();
(SysGlobalObservables.runCode())(buildCmd);
const execCmd = this.compilerParams.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();

(SysGlobalObservables.runCode())(buildCmd, testCmd);
};

this.compilerParams.testCallback = compileAndTest;

this.editorParams.keyboardShortcuts.push([
'compileAndRunShortcut',
compileShortcut,
Expand Down