Write test run finished to stdin

This commit is contained in:
plondon 2021-10-17 09:18:18 -04:00
parent 5715561c4f
commit 4e44fa3f60
2 changed files with 16 additions and 17 deletions

View File

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

View File

@ -115,12 +115,10 @@ async function main() {
testData.push(message.output); testData.push(message.output);
console.log("writing to term"); console.log("writing to term");
return; return;
case "stdout end": case "testRunFinished":
console.log("stdout ended"); console.log("testRunFinished");
console.log(testData); console.log(testData);
console.log(message.isTest);
console.log(message.expectedOutput); console.log(message.expectedOutput);
console.log(testData);
testData = []; testData = [];
return; return;
case "testTerminalOutput": case "testTerminalOutput":