Format tests are all passing

No thanks to Node.js making the "exit" event be totally unusable due
to a subtle "intended" race condition that prevents you from all the
process output sometimes. Great.
This commit is contained in:
Radon Rosborough 2020-07-31 10:02:34 -06:00
parent 8e63afb8a0
commit 559efbdf8f
4 changed files with 25 additions and 25 deletions

View File

@ -112,7 +112,7 @@ export class Session {
output: data.toString("utf8"), output: data.toString("utf8"),
}) })
); );
daemonProc.on("exit", (code, signal) => daemonProc.on("close", (code, signal) =>
this.send({ this.send({
event: "serviceFailed", event: "serviceFailed",
service: "daemon", service: "daemon",
@ -149,7 +149,7 @@ export class Session {
output: data.toString("utf8"), output: data.toString("utf8"),
}) })
); );
lspProc.on("exit", (code, signal) => lspProc.on("close", (code, signal) =>
this.send({ this.send({
event: "serviceFailed", event: "serviceFailed",
service: "lsp", service: "lsp",
@ -372,7 +372,6 @@ export class Session {
this.formatter.live = false; this.formatter.live = false;
this.formatter = null; this.formatter = null;
} }
await this.writeCode(code);
const args = this.privilegedSpawn(bash(this.config.format.run)); const args = this.privilegedSpawn(bash(this.config.format.run));
const formatter = { const formatter = {
proc: spawn(args[0], args.slice(1)), proc: spawn(args[0], args.slice(1)),
@ -380,6 +379,7 @@ export class Session {
input: code, input: code,
output: "", output: "",
}; };
formatter.proc.stdin!.end(code);
formatter.proc.stdout!.on("data", (data) => { formatter.proc.stdout!.on("data", (data) => {
if (!formatter.live) return; if (!formatter.live) return;
formatter.output += data.toString("utf8"); formatter.output += data.toString("utf8");
@ -392,7 +392,7 @@ export class Session {
output: data.toString("utf8"), output: data.toString("utf8"),
}); });
}); });
formatter.proc.on("exit", (code, signal) => { formatter.proc.on("close", (code, signal) => {
if (!formatter.live) return; if (!formatter.live) return;
if (code === 0) { if (code === 0) {
this.send({ this.send({

View File

@ -331,7 +331,7 @@ Nude pagoda careens.
compile: "clang -Wall -Wextra main.c -o main", compile: "clang -Wall -Wextra main.c -o main",
run: "./main", run: "./main",
format: { format: {
run: "clang-format main.c", run: "clang-format --assume-filename=format.c",
input: `#include <stdio.h> input: `#include <stdio.h>
int main() int main()
@ -485,7 +485,7 @@ Refrigerate for 1 hour.
compile: "clang++ -Wall -Wextra main.cpp -o main", compile: "clang++ -Wall -Wextra main.cpp -o main",
run: "./main", run: "./main",
format: { format: {
run: "clang-format main.cpp", run: "clang-format --assume-filename=format.cpp",
input: `#include <iostream> input: `#include <iostream>
int main() int main()
@ -524,7 +524,7 @@ int main() {
compile: "mcs main.cs", compile: "mcs main.cs",
run: "mono main.exe", run: "mono main.exe",
format: { format: {
run: `clang-format --style="{BasedOnStyle: llvm, IndentWidth: 4}" main.cs`, run: `clang-format --style="{BasedOnStyle: llvm, IndentWidth: 4}" --assume-filename=format.cs`,
input: `class main input: `class main
{ {
static void Main(string[] args) static void Main(string[] args)
@ -598,7 +598,7 @@ require("/usr/lib/node_modules/coffeescript/repl").start()
compile: "dmd main.d", compile: "dmd main.d",
run: "./main", run: "./main",
format: { format: {
run: "dfmt main.d", run: "dfmt",
input: `import std.stdio; input: `import std.stdio;
void main() { void main() {
@ -822,7 +822,7 @@ main() ->
compile: "go build main.go", compile: "go build main.go",
run: "./main", run: "./main",
format: { format: {
run: "cat main.go | gofmt", run: "gofmt",
input: `package main input: `package main
import "fmt" import "fmt"
@ -879,7 +879,7 @@ function main(): void {
main: "Main.hs", main: "Main.hs",
run: "(echo ':load Main' && echo 'main') > .ghci && ghci", run: "(echo ':load Main' && echo 'main') > .ghci && ghci",
format: { format: {
run: "brittany Main.hs", run: "brittany",
input: `module Main where input: `module Main where
main :: IO () main :: IO ()
@ -1001,7 +1001,7 @@ PLEASE GIVE UP
compile: "javac Main.java", compile: "javac Main.java",
run: "java Main", run: "java Main",
format: { format: {
run: `clang-format --style="{BasedOnStyle: llvm, IndentWidth: 4}" Main.java`, run: `clang-format --style="{BasedOnStyle: llvm, IndentWidth: 4}" --assume-filename=Format.java`,
input: `public class Main input: `public class Main
{ {
public static void main(String[] args) public static void main(String[] args)
@ -1029,7 +1029,7 @@ eval.apply(this, [require("fs").readFileSync("main.js", {encoding: "utf-8"})])
require("repl").start() require("repl").start()
'`, '`,
format: { format: {
run: "prettier --no-config main.js", run: "prettier --no-config --stdin-filepath=format.js",
input: `console.log('Hello, world!'); input: `console.log('Hello, world!');
`, `,
}, },
@ -1107,7 +1107,7 @@ require("repl").start()
main: "main.less", main: "main.less",
run: "lessc main.less", run: "lessc main.less",
format: { format: {
run: "prettier --no-config main.less", run: "prettier --no-config --stdin-filepath=format.less",
input: `body:before { input: `body:before {
content: "Hello, world!"; content: "Hello, world!";
} }
@ -1202,7 +1202,7 @@ KTHXBYE
compile: "pandoc main.md -o main.html", compile: "pandoc main.md -o main.html",
run: "prettier --no-config main.html", run: "prettier --no-config main.html",
format: { format: {
run: "prettier --no-config main.md", run: "prettier --no-config --stdin-filepath=format.md",
input: `Hello, world! input: `Hello, world!
`, `,
@ -1290,7 +1290,7 @@ message:
"gcc $(gnustep-config --objc-flags) main.m $(gnustep-config --base-libs) -o main", "gcc $(gnustep-config --objc-flags) main.m $(gnustep-config --base-libs) -o main",
run: "./main", run: "./main",
format: { format: {
run: "clang-format main.m", run: "clang-format --assume-filename=format.m",
input: `#import <Foundation/Foundation.h> input: `#import <Foundation/Foundation.h>
int main() { int main() {
@ -1322,7 +1322,7 @@ int main() {
input: "123 * 234 ;;", input: "123 * 234 ;;",
run: "ocaml -init main.ml", run: "ocaml -init main.ml",
format: { format: {
run: "touch .ocamlformat; ocamlformat main.ml", run: "touch .ocamlformat; ocamlformat --name=format.ml -",
input: `print_string "Hello, world!\\n";; input: `print_string "Hello, world!\\n";;
`, `,
}, },
@ -1402,7 +1402,7 @@ end.
main: "main.pl", main: "main.pl",
run: "re.pl --rcfile ./main.pl", run: "re.pl --rcfile ./main.pl",
format: { format: {
run: "cat main.pl | perltidy", run: "perltidy",
input: `print ("Hello, world!\\n") input: `print ("Hello, world!\\n")
`, `,
}, },
@ -1527,7 +1527,7 @@ main = do
main: "main.py", main: "main.py",
run: "python3 -u -i main.py", run: "python3 -u -i main.py",
format: { format: {
run: "cat main.py | black -", run: "black -",
input: `print('Hello, world!') input: `print('Hello, world!')
`, `,
}, },
@ -1598,7 +1598,7 @@ main = do
compile: "bsc main.re > main.js", compile: "bsc main.re > main.js",
run: "NODE_PATH=/usr/lib/node_modules node main.js", run: "NODE_PATH=/usr/lib/node_modules node main.js",
format: { format: {
run: "refmt main.re", run: "refmt",
input: `print_string("Hello, world!\\n") input: `print_string("Hello, world!\\n")
`, `,
}, },
@ -1695,7 +1695,7 @@ binding_irb.run(IRB.conf)
run: "ruby main.rb", run: "ruby main.rb",
ensure: `ruby -e 'raise "version mismatch, expected #{RUBY_VERSION}" unless ENV["PATH"].include? ".gem/ruby/#{RUBY_VERSION}/bin"'`, ensure: `ruby -e 'raise "version mismatch, expected #{RUBY_VERSION}" unless ENV["PATH"].include? ".gem/ruby/#{RUBY_VERSION}/bin"'`,
format: { format: {
run: "cat main.rb | rufo -x", run: "rufo -x",
input: `puts "Hello, world!"; input: `puts "Hello, world!";
`, `,
}, },
@ -1758,7 +1758,7 @@ binding_irb.run(IRB.conf)
main: "main.scss", main: "main.scss",
run: "sass main.scss", run: "sass main.scss",
format: { format: {
run: "prettier --no-config main.scss", run: "prettier --no-config --stdin-filepath=format.scss",
input: `body:before { input: `body:before {
content: "Hello, world!"; content: "Hello, world!";
} }
@ -2044,7 +2044,7 @@ a
main: "main.ts", main: "main.ts",
run: `ts-node -i -e "$(< main.ts)"`, run: `ts-node -i -e "$(< main.ts)"`,
format: { format: {
run: "prettier --no-config main.ts", run: "prettier --no-config --stdin-filepath=format.ts",
input: `console.log('Hello, world!'); input: `console.log('Hello, world!');
`, `,
}, },
@ -2151,7 +2151,7 @@ message:
compile: "cat main.yaml | yj -yj > main.json", compile: "cat main.yaml | yj -yj > main.json",
run: "cat main.json | jq .", run: "cat main.json | jq .",
format: { format: {
run: "prettier --no-config main.yaml", run: "prettier --no-config --stdin-filepath=format.yaml",
input: `output: 'Hello, world!' input: `output: 'Hello, world!'
`, `,
}, },

View File

@ -36,7 +36,7 @@ console.error(quote(cmdline));
const proc = child_process.spawn(cmdline[0], cmdline.slice(1)); const proc = child_process.spawn(cmdline[0], cmdline.slice(1));
proc.stderr.on("data", (data) => process.stderr.write(data)); proc.stderr.on("data", (data) => process.stderr.write(data));
proc.on("exit", (code, signal) => { proc.on("close", (code, signal) => {
if (code) { if (code) {
console.error(`Language server exited with code ${code}`); console.error(`Language server exited with code ${code}`);
process.exit(code); process.exit(code);

View File

@ -47,7 +47,7 @@ async function main() {
}); });
await new Promise((resolve, reject) => { await new Promise((resolve, reject) => {
proc.on("error", reject); proc.on("error", reject);
proc.on("exit", resolve); proc.on("close", resolve);
}); });
await run(privilegedTeardown({ uid, uuid }), log); await run(privilegedTeardown({ uid, uuid }), log);
await returnUID(); await returnUID();