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";
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) => {

View File

@ -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":