Reset progress

This commit is contained in:
plondon 2021-10-23 14:35:08 -04:00
parent 1868c9461e
commit 45b2a66e19
3 changed files with 55 additions and 77 deletions

View File

@ -1,4 +1,4 @@
import { spawn, spawnSync } from "child_process"; import { spawn } from "child_process";
import path from "path"; import path from "path";
import process from "process"; import process from "process";
@ -12,6 +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!\n'
export class Session { export class Session {
get homedir() { get homedir() {
return "/home/riju/src"; return "/home/riju/src";
@ -233,7 +234,8 @@ export class Session {
this.logBadMessage(msg); this.logBadMessage(msg);
break; break;
} }
await this.runCode(msg.code, msg.expectedOutput); await this.runCode(msg.code, true, msg.expectedOutput);
this.term.pty.stdin.write(TEST_RUN_FINISHED);
break; break;
case "formatCode": case "formatCode":
if (typeof msg.code !== "string") { if (typeof msg.code !== "string") {
@ -285,18 +287,14 @@ export class Session {
await this.run(this.privilegedExec(`cat > ${file}`), { input: code }); await this.run(this.privilegedExec(`cat > ${file}`), { input: code });
}; };
runCode = async (code, expectedOutput) => { runCode = async (code, isTest = false, expectedOutput) => {
try { try {
const { name, repl, suffix, createEmpty, compile, run, template } = const { name, repl, suffix, createEmpty, compile, run, template } =
this.config; this.config;
if (this.term) { if (this.term) {
try { try {
process.kill(this.term.pty.pid, "SIGKILL"); process.kill(this.term.pty.pid);
} catch (err) { } catch (err) {
this.send({
event: "error doing process.kill",
err,
});
// process might have already exited // process might have already exited
} }
// Signal to terminalOutput message generator using closure. // Signal to terminalOutput message generator using closure.
@ -313,7 +311,7 @@ export class Session {
} else if (repl) { } else if (repl) {
cmdline = repl; cmdline = repl;
} else { } else {
cmdline = `Press Run to see your code in action!`; cmdline = `echo '${name} has no REPL, press Run to see it in action'`;
} }
if (code === undefined) { if (code === undefined) {
code = createEmpty !== undefined ? createEmpty : template + "\n"; code = createEmpty !== undefined ? createEmpty : template + "\n";
@ -323,67 +321,50 @@ export class Session {
} }
await this.writeCode(code); await this.writeCode(code);
const termArgs = this.privilegedPty(cmdline); const termArgs = this.privilegedPty(cmdline);
const result = spawnSync(termArgs[0], termArgs.slice(1), { const term = {
encoding: "utf-8", pty: spawn(termArgs[0], termArgs.slice(1)),
}); live: true,
};
this.term = term;
if (result.stderr) { 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) {
this.send({
event: "terminalOutput",
output: data.toString(),
});
}
});
this.term.pty.stderr.on("data", (data) => {
if (term.live) {
this.send({ this.send({
event: "serviceLog", event: "serviceLog",
service: "pty", service: "pty",
output: data.stderr, output: data.toString("utf8"),
});
}
});
this.term.pty.on("close", (code, signal) => {
if (term.live) {
this.send({
event: "serviceFailed",
service: "terminal",
error: `Exited with status ${signal || code}`,
code: signal || code,
});
}
});
this.term.pty.on("error", (err) => {
if (term.live) {
this.send({
event: "serviceFailed",
service: "terminal",
error: `${err}`,
}); });
return;
} }
this.send({
event: "terminalOutput",
expectedOutput,
output: result.stdout,
}); });
// 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("utf8");
// this.send({
// event: "terminalOutput",
// expectedOutput,
// output,
// });
// }
// });
// this.term.pty.stderr.on("data", (data) => {
// if (term.live) {
// this.send({
// event: "serviceLog",
// service: "pty",
// output: data.toString("utf8"),
// });
// }
// });
// this.term.pty.on("close", (code, signal) => {
// if (term.live) {
// this.send({
// event: "serviceFailed",
// service: "terminal",
// error: `Exited with status ${signal || code}`,
// expectedOutput,
// code: signal || code,
// });
// }
// });
// this.term.pty.on("error", (err) => {
// if (term.live) {
// this.send({
// event: "serviceFailed",
// service: "terminal",
// error: `${err}`,
// });
// }
// });
} catch (err) { } catch (err) {
logError(err); logError(err);
this.sendError(err); this.sendError(err);

View File

@ -81,7 +81,6 @@ class Test {
}; };
run = async () => { run = async () => {
return "skipped";
if ((this.config.skip || []).includes(this.type)) { if ((this.config.skip || []).includes(this.type)) {
return "skipped"; return "skipped";
} }

View File

@ -130,6 +130,7 @@ async function main() {
return; return;
} }
if ( if (
DEBUG &&
message && message &&
message.event !== "lspOutput" && message.event !== "lspOutput" &&
message.event !== "serviceLog" message.event !== "serviceLog"
@ -149,8 +150,11 @@ async function main() {
return; return;
} }
term.write(message.output); term.write(message.output);
if (message.expectedOutput) {
testData.push(message.output); testData.push(message.output);
if (testData.join("").includes("Test run!")) {
postTestResults(testData, message.expectedOutput);
testData = [];
} }
return; return;
case "lspStopped": case "lspStopped":
@ -197,12 +201,6 @@ async function main() {
serviceLogLines[message.service] = lines; serviceLogLines[message.service] = lines;
return; return;
case "serviceFailed": case "serviceFailed":
if (message.expectedOutput) {
postTestResults(testData, message.expectedOutput);
}
testData = [];
if ( if (
typeof message.service !== "string" || typeof message.service !== "string" ||
typeof message.error !== "string" typeof message.error !== "string"