diff --git a/backend/api.js b/backend/api.js index 5b9b621..6fdb882 100644 --- a/backend/api.js +++ b/backend/api.js @@ -12,7 +12,7 @@ import * as util from "./util.js"; import { bash, getUUID, logError } from "./util.js"; const allSessions = new Set(); - +const TEST_RUN_FINISHED = "Test run finished!"; export class Session { get homedir() { return "/home/riju/src"; @@ -234,9 +234,8 @@ export class Session { this.logBadMessage(msg); break; } - await this.runCode(msg.code) - await this.runCode(msg.code, true, msg.expectedOutput); - await this.runCode(msg.code, true, msg.expectedOutput); + await this.runCode(msg.code, msg.expectedOutput); + this.term.pty.stdin.write(TEST_RUN_FINISHED); break; case "formatCode": if (typeof msg.code !== "string") { @@ -288,7 +287,7 @@ export class Session { await this.run(this.privilegedExec(`cat > ${file}`), { input: code }); }; - runCode = async (code, isTest = false, expectedOutput, testData = []) => { + runCode = async (code, expectedOutput) => { try { const { name, repl, suffix, createEmpty, compile, run, template } = this.config; @@ -328,21 +327,23 @@ export class Session { }; this.term = term; - this.term.pty.stdout.on("end", () => { - this.send({ - event: "stdout end", - expectedOutput, - isTest, - }); - }); this.term.pty.stdout.on("data", (data) => { // Capture term in closure so that we don't keep sending output // from the old pty even after it's been killed (see ghci). if (term.live) { + const output = data.toString(); + this.send({ event: "terminalOutput", - output: data.toString(), + output, }); + + if (output.includes(TEST_RUN_FINISHED)) { + this.send({ + event: "testRunFinished", + expectedOutput + }) + } } }); this.term.pty.stderr.on("data", (data) => { diff --git a/frontend/src/app.js b/frontend/src/app.js index 0350f12..2ea098c 100644 --- a/frontend/src/app.js +++ b/frontend/src/app.js @@ -115,12 +115,10 @@ async function main() { testData.push(message.output); console.log("writing to term"); return; - case "stdout end": - console.log("stdout ended"); + case "testRunFinished": + console.log("testRunFinished"); console.log(testData); - console.log(message.isTest); console.log(message.expectedOutput); - console.log(testData); testData = []; return; case "testTerminalOutput":