Rearrange configuration to integrate tests better

This commit is contained in:
Radon Rosborough 2020-07-30 09:22:26 -06:00
parent 785acda4a9
commit e19d6a2c06
4 changed files with 133 additions and 137 deletions

View File

@ -129,10 +129,10 @@ export class Session {
} }
} }
if (this.config.lsp) { if (this.config.lsp) {
if (this.config.lspSetup) { if (this.config.lsp.setup) {
await this.run(this.privilegedSpawn(bash(this.config.lspSetup))); await this.run(this.privilegedSpawn(bash(this.config.lsp.setup)));
} }
const lspArgs = this.privilegedSpawn(bash(this.config.lsp)); const lspArgs = this.privilegedSpawn(bash(this.config.lsp.start));
const lspProc = spawn(lspArgs[0], lspArgs.slice(1)); const lspProc = spawn(lspArgs[0], lspArgs.slice(1));
this.lsp = { this.lsp = {
proc: lspProc, proc: lspProc,
@ -256,11 +256,11 @@ export class Session {
this.lsp.writer.write(msg.input); this.lsp.writer.write(msg.input);
break; break;
case "ensure": case "ensure":
if (!(this.config.test && this.config.test.ensure)) { if (!this.config.ensure) {
this.log(`ensure ignored because of missing configuration`); this.log(`ensure ignored because of missing configuration`);
break; break;
} }
await this.ensure(); await this.ensure(this.config.ensure);
default: default:
this.logBadMessage(msg); this.logBadMessage(msg);
break; break;
@ -371,7 +371,7 @@ export class Session {
this.formatter = null; this.formatter = null;
} }
await this.writeCode(code); await this.writeCode(code);
const args = this.privilegedSpawn(bash(this.config.format)); 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)),
live: true, live: true,
@ -422,13 +422,10 @@ export class Session {
} }
}; };
ensure = async () => { ensure = async (cmd: string) => {
const code = await this.run( const code = await this.run(this.privilegedSpawn(bash(cmd)), {
this.privilegedSpawn(bash(this.config.test!.ensure!)), check: false,
{ });
check: false,
}
);
this.send({ event: "ensured", code }); this.send({ event: "ensured", code });
}; };

View File

@ -5,51 +5,45 @@ export interface LangConfig {
daemon?: string; daemon?: string;
setup?: string; setup?: string;
repl?: string; repl?: string;
input?: string;
output?: string;
main: string; main: string;
prefix?: string; prefix?: string;
suffix?: string; suffix?: string;
createEmpty?: string; createEmpty?: string;
compile?: string; compile?: string;
run: string; run: string;
format?: string; hello?: string;
scope?: {
code: string;
after?: string;
input?: string;
output?: string;
};
ensure?: string;
format?: {
run: string;
input?: string; // FIXME
output?: string;
};
pkg?: { pkg?: {
install: string; install: string;
uninstall?: string; uninstall?: string;
all?: string; all?: string;
search?: string; search?: string;
}; };
lspSetup?: string; lsp?: {
lsp?: string; setup?: string;
lspDisableDynamicRegistration?: boolean; start: string;
lspInit?: any; disableDynamicRegistration?: boolean;
lspConfig?: any; init?: any;
lspLang?: string; config?: any;
template: string; lang?: string;
test?: { code?: string;
ensure?: string; after?: string;
hello?: { item?: string; // FIXME
pattern?: string;
};
repl?: {
input?: string;
output?: string;
};
scope?: {
code: string;
after?: string;
input?: string;
output?: string;
};
format?: {
input: string;
output?: string;
};
lsp?: {
after?: string;
code?: string;
item: string;
};
}; };
template: string;
} }
export const langs: { [key: string]: LangConfig } = { export const langs: { [key: string]: LangConfig } = {
@ -68,7 +62,7 @@ export const langs: { [key: string]: LangConfig } = {
main: "main.adb", main: "main.adb",
compile: "x86_64-linux-gnu-gnatmake-9 main.adb", compile: "x86_64-linux-gnu-gnatmake-9 main.adb",
run: "./main", run: "./main",
lsp: "ada_language_server", lsp: { start: "ada_language_server" },
template: `with Ada.Text_IO; template: `with Ada.Text_IO;
procedure Main is procedure Main is
@ -149,7 +143,7 @@ implement main0 () = ()
repl: "bash --rcfile /dev/null", repl: "bash --rcfile /dev/null",
main: "main.bash", main: "main.bash",
run: "bash --rcfile main.bash", run: "bash --rcfile main.bash",
lsp: "bash-language-server start", lsp: { start: "bash-language-server start" },
template: `echo "Hello, world!" template: `echo "Hello, world!"
`, `,
}, },
@ -323,9 +317,11 @@ Nude pagoda careens.
main: "main.c", main: "main.c",
compile: "clang -Wall -Wextra main.c -o main", compile: "clang -Wall -Wextra main.c -o main",
run: "./main", run: "./main",
format: "clang-format main.c", format: { run: "clang-format main.c" },
lspSetup: `echo '-Wall -Wextra' | sed -E 's/\\s+/\\n/g' > compile_flags.txt`, lsp: {
lsp: "clangd", setup: `echo '-Wall -Wextra' | sed -E 's/\\s+/\\n/g' > compile_flags.txt`,
start: "clangd",
},
template: `#include <stdio.h> template: `#include <stdio.h>
int main() { int main() {
@ -460,9 +456,11 @@ Refrigerate for 1 hour.
main: "main.cpp", main: "main.cpp",
compile: "clang++ -Wall -Wextra main.cpp -o main", compile: "clang++ -Wall -Wextra main.cpp -o main",
run: "./main", run: "./main",
format: "clang-format main.cpp", format: { run: "clang-format main.cpp" },
lspSetup: `echo '-Wall -Wextra' | sed -E 's/\\s+/\\n/g' > compile_flags.txt`, lsp: {
lsp: "clangd", setup: `echo '-Wall -Wextra' | sed -E 's/\\s+/\\n/g' > compile_flags.txt`,
start: "clangd",
},
template: `#include <iostream> template: `#include <iostream>
int main() { int main() {
@ -486,7 +484,9 @@ int main() {
main: "main.cs", main: "main.cs",
compile: "mcs main.cs", compile: "mcs main.cs",
run: "mono main.exe", run: "mono main.exe",
format: `clang-format --style="{BasedOnStyle: llvm, IndentWidth: 4}" main.cs`, format: {
run: `clang-format --style="{BasedOnStyle: llvm, IndentWidth: 4}" main.cs`,
},
template: `class main { template: `class main {
static void Main(string[] args) { static void Main(string[] args) {
System.Console.WriteLine("Hello, world!"); System.Console.WriteLine("Hello, world!");
@ -501,7 +501,7 @@ int main() {
repl: "clojure", repl: "clojure",
main: "main.clj", main: "main.clj",
run: "clojure -i main.clj -r", run: "clojure -i main.clj -r",
lsp: "clojure-lsp", lsp: { start: "clojure-lsp" },
template: `(println "Hello, world!") template: `(println "Hello, world!")
`, `,
}, },
@ -548,7 +548,7 @@ require("/usr/lib/node_modules/coffeescript/repl").start()
main: "main.d", main: "main.d",
compile: "dmd main.d", compile: "dmd main.d",
run: "./main", run: "./main",
format: "dfmt main.d", format: { run: "dfmt main.d" },
template: `import std.stdio; template: `import std.stdio;
void main() void main()
@ -599,7 +599,7 @@ void main()
repl: "iex", repl: "iex",
main: "main.exs", main: "main.exs",
run: "iex main.exs", run: "iex main.exs",
lsp: "/opt/elixir-ls/language_server.sh", lsp: { start: "/opt/elixir-ls/language_server.sh" },
template: `IO.puts("Hello, world!") template: `IO.puts("Hello, world!")
`, `,
}, },
@ -608,8 +608,10 @@ void main()
repl: "elm repl", repl: "elm repl",
main: "Main.elm", main: "Main.elm",
run: "cp /opt/elm/elm.json elm.json && run-elm Main.elm; elm repl", run: "cp /opt/elm/elm.json elm.json && run-elm Main.elm; elm repl",
lsp: "elm-language-server --stdio", lsp: {
lspSetup: "cp /opt/elm/elm.json elm.json", setup: "cp /opt/elm/elm.json elm.json",
start: "elm-language-server --stdio",
},
template: `module Main exposing (..) template: `module Main exposing (..)
output : String output : String
@ -669,7 +671,7 @@ output = "Hello, world!"
main: "main.erl", main: "main.erl",
compile: "erl -compile main", compile: "erl -compile main",
run: "erl -s main main", run: "erl -s main main",
lsp: "erlang_ls", lsp: { start: "erlang_ls" },
template: `-module(main). template: `-module(main).
-export([main/0]). -export([main/0]).
@ -728,7 +730,7 @@ main() ->
main: "main.f", main: "main.f",
compile: "flang main.f -o main", compile: "flang main.f -o main",
run: "./main", run: "./main",
lsp: "fortls", lsp: { start: "fortls" },
template: ` program hello template: ` program hello
print *, "Hello, world!" print *, "Hello, world!"
end program hello end program hello
@ -751,8 +753,8 @@ main() ->
main: "main.go", main: "main.go",
compile: "go build main.go", compile: "go build main.go",
run: "./main", run: "./main",
format: "cat main.go | gofmt", format: { run: "cat main.go | gofmt" },
lsp: "gopls", lsp: { start: "gopls" },
template: `package main template: `package main
import "fmt" import "fmt"
@ -795,11 +797,13 @@ function main(): void {
repl: "rm -f .ghci && ghci", repl: "rm -f .ghci && ghci",
main: "Main.hs", main: "Main.hs",
run: "(echo ':load Main' && echo 'main') > .ghci && ghci", run: "(echo ':load Main' && echo 'main') > .ghci && ghci",
format: "brittany Main.hs", format: { run: "brittany Main.hs" },
lspSetup: "cp /opt/haskell/hie.yaml hie.yaml", lsp: {
lsp: "HIE_HOOGLE_DATABASE=/opt/haskell/hoogle.hoo hie --lsp", setup: "cp /opt/haskell/hie.yaml hie.yaml",
lspInit: { start: "HIE_HOOGLE_DATABASE=/opt/haskell/hoogle.hoo hie --lsp",
languageServerHaskell: {}, init: {
languageServerHaskell: {},
},
}, },
template: `module Main where template: `module Main where
@ -905,7 +909,9 @@ PLEASE GIVE UP
main: "Main.java", main: "Main.java",
compile: "javac Main.java", compile: "javac Main.java",
run: "java Main", run: "java Main",
format: `clang-format --style="{BasedOnStyle: llvm, IndentWidth: 4}" Main.java`, format: {
run: `clang-format --style="{BasedOnStyle: llvm, IndentWidth: 4}" Main.java`,
},
template: `public class Main { template: `public class Main {
public static void main(String[] args) { public static void main(String[] args) {
System.out.println("Hello, world!"); System.out.println("Hello, world!");
@ -919,8 +925,10 @@ PLEASE GIVE UP
repl: "julia", repl: "julia",
main: "main.jl", main: "main.jl",
run: "julia -L main.jl", run: "julia -L main.jl",
lsp: `JULIA_DEPOT_PATH=:/opt/julia julia -e 'using LanguageServer; run(LanguageServerInstance(stdin, stdout))'`, lsp: {
lspConfig: null, start: `JULIA_DEPOT_PATH=:/opt/julia julia -e 'using LanguageServer; run(LanguageServerInstance(stdin, stdout))'`,
config: null,
},
template: `println("Hello, world!") template: `println("Hello, world!")
`, `,
}, },
@ -971,7 +979,7 @@ PLEASE GIVE UP
monacoLang: "less", monacoLang: "less",
main: "main.less", main: "main.less",
run: "lessc main.less", run: "lessc main.less",
format: "prettier --no-config main.less", format: { run: "prettier --no-config main.less" },
template: `body:before { template: `body:before {
content: "Hello, world!"; content: "Hello, world!";
} }
@ -1030,7 +1038,7 @@ KTHXBYE
repl: "lua", repl: "lua",
main: "main.lua", main: "main.lua",
run: "lua -i main.lua", run: "lua -i main.lua",
lsp: "java -cp /usr/lib/EmmyLua-LS.jar com.tang.vscode.MainKt", lsp: { start: "java -cp /usr/lib/EmmyLua-LS.jar com.tang.vscode.MainKt" },
template: `print("Hello, world!") template: `print("Hello, world!")
`, `,
}, },
@ -1068,7 +1076,7 @@ KTHXBYE
main: "main.md", main: "main.md",
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: "prettier --no-config main.md", format: { run: "prettier --no-config main.md" },
template: `Hello, world! template: `Hello, world!
`, `,
}, },
@ -1151,7 +1159,7 @@ message:
eval.apply(this, [require("fs").readFileSync("main.js", {encoding: "utf-8"})]) eval.apply(this, [require("fs").readFileSync("main.js", {encoding: "utf-8"})])
require("repl").start() require("repl").start()
'`, '`,
format: "prettier --no-config main.js", format: { run: "prettier --no-config main.js" },
pkg: { pkg: {
install: "yarn add NAME", install: "yarn add NAME",
uninstall: "yarn remove NAME", uninstall: "yarn remove NAME",
@ -1169,9 +1177,11 @@ require("repl").start()
compile: compile:
"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: "clang-format main.m", format: { run: "clang-format main.m" },
lspSetup: `(gnustep-config --objc-flags && gnustep-config --base-libs) | sed -E 's/\\s+/\\n/g' > compile_flags.txt`, lsp: {
lsp: "clangd", setup: `(gnustep-config --objc-flags && gnustep-config --base-libs) | sed -E 's/\\s+/\\n/g' > compile_flags.txt`,
start: "clangd",
},
template: `#import <Foundation/Foundation.h> template: `#import <Foundation/Foundation.h>
int main() { int main() {
@ -1187,9 +1197,8 @@ int main() {
main: "main.ml", main: "main.ml",
repl: "ocaml", repl: "ocaml",
run: "ocaml -init main.ml", run: "ocaml -init main.ml",
format: "ocamlformat main.ml", format: { run: "ocamlformat main.ml" },
lsp: "ocamllsp", lsp: { start: "ocamllsp", lang: "ocaml" },
lspLang: "ocaml",
template: `print_string "Hello, world!\\n";; template: `print_string "Hello, world!\\n";;
`, `,
}, },
@ -1263,7 +1272,7 @@ end.
repl: "re.pl", repl: "re.pl",
main: "main.pl", main: "main.pl",
run: "re.pl --rcfile ./main.pl", run: "re.pl --rcfile ./main.pl",
format: "cat main.pl | perltidy", format: { run: "cat main.pl | perltidy" },
template: `print("Hello, world!\\n") template: `print("Hello, world!\\n")
`, `,
}, },
@ -1274,7 +1283,7 @@ end.
repl: "php -a", repl: "php -a",
main: "main.php", main: "main.php",
run: "php -d auto_prepend_file=main.php -a", run: "php -d auto_prepend_file=main.php -a",
lsp: "intelephense --stdio", lsp: { start: "intelephense --stdio" },
template: `<?php template: `<?php
echo "Hello, world!\\n"; echo "Hello, world!\\n";
@ -1322,7 +1331,9 @@ pipi pikachu
repl: "SHELL=/usr/bin/pwsh pwsh", repl: "SHELL=/usr/bin/pwsh pwsh",
main: "main.ps1", main: "main.ps1",
run: "SHELL=/usr/bin/pwsh pwsh -NoExit main.ps1", run: "SHELL=/usr/bin/pwsh pwsh -NoExit main.ps1",
lsp: `pwsh -NoLogo -NoProfile -Command "/opt/powershell-editor-services/PowerShellEditorServices/Start-EditorServices.ps1 -BundledModulesPath /opt/powershell-editor-services -LogPath '$PWD/.powershell-editor-services/lsp.log' -SessionDetailsPath '$PWD/.powershell-editor-services/session.json' -FeatureFlags @() -AdditionalModules @() -HostName Riju -HostProfileId 'riju' -HostVersion 0.0 -Stdio -LogLevel Normal"`, lsp: {
start: `pwsh -NoLogo -NoProfile -Command "/opt/powershell-editor-services/PowerShellEditorServices/Start-EditorServices.ps1 -BundledModulesPath /opt/powershell-editor-services -LogPath '$PWD/.powershell-editor-services/lsp.log' -SessionDetailsPath '$PWD/.powershell-editor-services/session.json' -FeatureFlags @() -AdditionalModules @() -HostName Riju -HostProfileId 'riju' -HostVersion 0.0 -Stdio -LogLevel Normal"`,
},
template: `Write-Host "Hello, world!" template: `Write-Host "Hello, world!"
`, `,
}, },
@ -1374,28 +1385,28 @@ main = do
repl: "python3 -u", repl: "python3 -u",
main: "main.py", main: "main.py",
run: "python3 -u -i main.py", run: "python3 -u -i main.py",
format: "cat main.py | black -", format: {
run: "cat main.py | black -",
input: `print('Hello, world!')
`,
},
pkg: { pkg: {
install: "pip3 install --user NAME", install: "pip3 install --user NAME",
uninstall: "pip3 uninstall NAME", uninstall: "pip3 uninstall NAME",
search: `python3 -c 'import json; from xmlrpc import client; print(json.dumps(client.ServerProxy("https://pypi.org/pypi").search({"name": "NAME"})))' | jq -r 'map(.name) | .[]'`, search: `python3 -c 'import json; from xmlrpc import client; print(json.dumps(client.ServerProxy("https://pypi.org/pypi").search({"name": "NAME"})))' | jq -r 'map(.name) | .[]'`,
}, },
lsp: "Microsoft.Python.LanguageServer", lsp: {
lspInit: { start: "Microsoft.Python.LanguageServer",
interpreter: { init: {
properties: { interpreter: {
InterpreterPath: "/usr/bin/python3", properties: {
InterpreterPath: "/usr/bin/python3",
},
}, },
}, },
}, },
template: `print("Hello, world!") template: `print("Hello, world!")
`, `,
test: {
format: {
input: `print('Hello, world!')
`,
},
},
}, },
قلب: { قلب: {
aliases: ["qalb"], aliases: ["qalb"],
@ -1440,9 +1451,11 @@ main = do
main: "main.re", main: "main.re",
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: "ocamlformat main.re", format: { run: "ocamlformat main.re" },
lspSetup: `cp -a /opt/reasonml/project-template/* ./`, lsp: {
lsp: "reason-language-server", setup: `cp -a /opt/reasonml/project-template/* ./`,
start: "reason-language-server",
},
template: `print_string("Hello, world!\\n") template: `print_string("Hello, world!\\n")
`, `,
}, },
@ -1528,18 +1541,16 @@ binding_irb = IRB::Irb.new(workspace)
binding_irb.run(IRB.conf) binding_irb.run(IRB.conf)
`, `,
run: "ruby main.rb", run: "ruby main.rb",
format: "cat main.rb | rufo -x", ensure: `ruby -e 'raise "version mismatch, expected #{RUBY_VERSION}" unless ENV["PATH"].include? ".gem/ruby/#{RUBY_VERSION}/bin"'`,
format: { run: "cat main.rb | rufo -x" },
pkg: { pkg: {
install: "gem install --user-install NAME", install: "gem install --user-install NAME",
uninstall: "gem uninstall --user-install NAME", uninstall: "gem uninstall --user-install NAME",
search: `curl -sS 'https://rubygems.org/api/v1/search.json?query=NAME' | jq -r 'map(.name) | .[]'`, search: `curl -sS 'https://rubygems.org/api/v1/search.json?query=NAME' | jq -r 'map(.name) | .[]'`,
}, },
lsp: "solargraph stdio", lsp: { start: "solargraph stdio" },
template: `puts "Hello, world!" template: `puts "Hello, world!"
`, `,
test: {
ensure: `ruby -e 'raise "version mismatch, expected #{RUBY_VERSION}" unless ENV["PATH"].include? ".gem/ruby/#{RUBY_VERSION}/bin"'`,
},
}, },
rust: { rust: {
aliases: ["rs", "rustc"], aliases: ["rs", "rustc"],
@ -1548,7 +1559,7 @@ binding_irb.run(IRB.conf)
main: "main.rs", main: "main.rs",
compile: "rustc main.rs", compile: "rustc main.rs",
run: "./main", run: "./main",
lsp: "rls", lsp: { start: "rls" },
template: `fn main() { template: `fn main() {
println!("Hello, world!"); println!("Hello, world!");
} }
@ -1587,7 +1598,7 @@ binding_irb.run(IRB.conf)
monacoLang: "scss", monacoLang: "scss",
main: "main.scss", main: "main.scss",
run: "sass main.scss", run: "sass main.scss",
format: "prettier --no-config main.scss", format: { run: "prettier --no-config main.scss" },
template: `body:before { template: `body:before {
content: "Hello, world!"; content: "Hello, world!";
} }
@ -1762,7 +1773,7 @@ END
main: "main.swift", main: "main.swift",
compile: "swiftc main.swift", compile: "swiftc main.swift",
run: "./main", run: "./main",
lsp: "sourcekit-lsp", lsp: { start: "sourcekit-lsp" },
template: `print("Hello, world!") template: `print("Hello, world!")
`, `,
}, },
@ -1794,8 +1805,7 @@ END
repl: "tex", repl: "tex",
main: "main.tex", main: "main.tex",
run: "tex main.tex", run: "tex main.tex",
lsp: "digestif", lsp: { start: "digestif", lang: "tex" },
lspLang: "tex",
template: `\\message{Hello, world!} template: `\\message{Hello, world!}
`, `,
}, },
@ -1849,7 +1859,7 @@ a
repl: "ts-node", repl: "ts-node",
main: "main.ts", main: "main.ts",
run: `ts-node -i -e "$(< main.ts)"`, run: `ts-node -i -e "$(< main.ts)"`,
format: "prettier --no-config main.ts", format: { run: "prettier --no-config main.ts" },
template: `console.log("Hello, world!"); template: `console.log("Hello, world!");
`, `,
}, },
@ -1867,7 +1877,7 @@ a
repl: "vim", repl: "vim",
main: "main.vim", main: "main.vim",
run: `vim -c "$(< main.vim)"`, run: `vim -c "$(< main.vim)"`,
lsp: "vim-language-server --stdio", lsp: { start: "vim-language-server --stdio" },
template: `:echo "Hello, world!" template: `:echo "Hello, world!"
`, `,
}, },
@ -1946,7 +1956,7 @@ message:
main: "main.yaml", main: "main.yaml",
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: "prettier --no-config main.yaml", format: { run: "prettier --no-config main.yaml" },
template: `output: "Hello, world!" template: `output: "Hello, world!"
`, `,
}, },

View File

@ -31,7 +31,7 @@ if (
langs[args[0]] && langs[args[0]] &&
typeof langs[args[0]].lsp === "string" typeof langs[args[0]].lsp === "string"
) { ) {
cmdline = ["bash", "-c", langs[args[0]].lsp as string]; cmdline = ["bash", "-c", langs[args[0]].lsp!.start];
} else { } else {
cmdline = args; cmdline = args;
} }

View File

@ -155,31 +155,28 @@ class Test {
} }
}; };
testHello = async () => { testHello = async () => {
const pattern = const pattern = this.config.hello || "Hello, world!";
((this.config.test || {}).hello || {}).pattern || "Hello, world!";
this.send({ event: "runCode", code: this.config.template }); this.send({ event: "runCode", code: this.config.template });
await this.waitForOutput(pattern); await this.waitForOutput(pattern);
}; };
testRepl = async () => { testRepl = async () => {
const input = const input = this.config.input || "111111 + 111111";
((this.config.test || {}).repl || {}).input || "111111 + 111111"; const output = this.config.output || "222222";
const output = ((this.config.test || {}).repl || {}).output || "222222";
this.send({ event: "terminalInput", input: input + "\r" }); this.send({ event: "terminalInput", input: input + "\r" });
await this.waitForOutput(output); await this.waitForOutput(output);
}; };
testRunRepl = async () => { testRunRepl = async () => {
const input = const input = this.config.input || "111111 + 111111";
((this.config.test || {}).repl || {}).input || "111111 + 111111"; const output = this.config.output || "222222";
const output = ((this.config.test || {}).repl || {}).output || "222222";
this.send({ event: "runCode", code: this.config.template }); this.send({ event: "runCode", code: this.config.template });
this.send({ event: "terminalInput", input: input + "\r" }); this.send({ event: "terminalInput", input: input + "\r" });
await this.waitForOutput(output); await this.waitForOutput(output);
}; };
testScope = async () => { testScope = async () => {
const code = this.config.test!.scope!.code; const code = this.config.scope!.code;
const after = this.config.test!.scope!.after; const after = this.config.scope!.after;
const input = this.config.test!.scope!.input || "x"; const input = this.config.scope!.input || "x";
const output = this.config.test!.scope!.output || "222222"; const output = this.config.scope!.output || "222222";
let allCode = this.config.template; let allCode = this.config.template;
if (!allCode.endsWith("\n")) { if (!allCode.endsWith("\n")) {
allCode += "\n"; allCode += "\n";
@ -194,10 +191,8 @@ class Test {
await this.waitForOutput(output); await this.waitForOutput(output);
}; };
testFormat = async () => { testFormat = async () => {
const input = this.config.test!.format!.input; const input = this.config.format!.input;
const output = const output = this.config.format!.output || this.config.template;
((this.config.test || {}).format || { output: undefined }).output ||
this.config.template;
this.send({ event: "formatCode", code: input }); this.send({ event: "formatCode", code: input });
const result = await this.wait((msg: any) => { const result = await this.wait((msg: any) => {
if (msg.event === "formattedCode") { if (msg.event === "formattedCode") {
@ -216,12 +211,6 @@ function lint(lang: string) {
if (!config.template.endsWith("\n")) { if (!config.template.endsWith("\n")) {
throw new Error("template is missing a trailing newline"); throw new Error("template is missing a trailing newline");
} }
if (config.format && !(config.test && config.test.format)) {
throw new Error("formatter is missing test");
}
if (config.lsp && !(config.test && config.test.lsp)) {
throw new Error("LSP is missing test");
}
} }
const testTypes: { const testTypes: {
@ -230,7 +219,7 @@ const testTypes: {
}; };
} = { } = {
ensure: { ensure: {
pred: ({ test }) => (test && test.ensure ? true : false), pred: ({ ensure }) => (ensure ? true : false),
}, },
hello: { pred: (config) => true }, hello: { pred: (config) => true },
repl: { repl: {
@ -240,7 +229,7 @@ const testTypes: {
pred: ({ repl }) => (repl ? true : false), pred: ({ repl }) => (repl ? true : false),
}, },
scope: { scope: {
pred: ({ test }) => (test && test.scope ? true : false), pred: ({ scope }) => (scope ? true : false),
}, },
format: { format: {
pred: ({ format }) => (format ? true : false), pred: ({ format }) => (format ? true : false),