From 88231549732606721b887f50adbfce373cdbc9aa Mon Sep 17 00:00:00 2001 From: rhiannon morris Date: Sun, 14 Apr 2024 20:47:59 +0200 Subject: [PATCH] add golden test stuff --- .gitignore | 2 ++ golden-tests/Tests.idr | 15 +++++++++++++++ golden-tests/quox-golden-tests.ipkg | 4 ++++ golden-tests/run-tests.sh | 10 ++++++++++ golden-tests/tests/empty/empty.quox | 0 golden-tests/tests/empty/expected | 0 golden-tests/tests/empty/run | 2 ++ golden-tests/tests/file-not-found/expected | 3 +++ golden-tests/tests/file-not-found/run | 2 ++ golden-tests/tests/hello/expected | 12 ++++++++++++ golden-tests/tests/hello/hello.quox | 7 +++++++ golden-tests/tests/hello/run | 2 ++ golden-tests/tests/ill-typed-main/expected | 3 +++ .../tests/ill-typed-main/ill-typed-main.quox | 2 ++ golden-tests/tests/ill-typed-main/run | 2 ++ golden-tests/tests/it-5/expected | 4 ++++ golden-tests/tests/it-5/five.quox | 1 + golden-tests/tests/it-5/run | 2 ++ golden-tests/tests/lib.sh | 18 ++++++++++++++++++ golden-tests/tests/load/expected | 16 ++++++++++++++++ golden-tests/tests/load/lib.quox | 8 ++++++++ golden-tests/tests/load/main.quox | 4 ++++ golden-tests/tests/load/run | 2 ++ pack.toml | 5 +++++ 24 files changed, 126 insertions(+) create mode 100644 golden-tests/Tests.idr create mode 100644 golden-tests/quox-golden-tests.ipkg create mode 100755 golden-tests/run-tests.sh create mode 100644 golden-tests/tests/empty/empty.quox create mode 100644 golden-tests/tests/empty/expected create mode 100644 golden-tests/tests/empty/run create mode 100644 golden-tests/tests/file-not-found/expected create mode 100644 golden-tests/tests/file-not-found/run create mode 100644 golden-tests/tests/hello/expected create mode 100644 golden-tests/tests/hello/hello.quox create mode 100644 golden-tests/tests/hello/run create mode 100644 golden-tests/tests/ill-typed-main/expected create mode 100644 golden-tests/tests/ill-typed-main/ill-typed-main.quox create mode 100644 golden-tests/tests/ill-typed-main/run create mode 100644 golden-tests/tests/it-5/expected create mode 100644 golden-tests/tests/it-5/five.quox create mode 100644 golden-tests/tests/it-5/run create mode 100644 golden-tests/tests/lib.sh create mode 100644 golden-tests/tests/load/expected create mode 100644 golden-tests/tests/load/lib.quox create mode 100644 golden-tests/tests/load/main.quox create mode 100644 golden-tests/tests/load/run diff --git a/.gitignore b/.gitignore index 221f1d8..683c569 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ result *~ quox quox-tests +quox-golden-tests/tests/*/output +quox-golden-tests/tests/*/*.ss diff --git a/golden-tests/Tests.idr b/golden-tests/Tests.idr new file mode 100644 index 0000000..60c7895 --- /dev/null +++ b/golden-tests/Tests.idr @@ -0,0 +1,15 @@ +module Tests + +import Test.Golden +import Language.Reflection +import System +import System.Path + +%language ElabReflection + +projDir = %runElab idrisDir ProjectDir +testDir = projDir "tests" + +tests = testsInDir { poolName = "quox golden tests", dirName = testDir } + +main = runner [!tests] diff --git a/golden-tests/quox-golden-tests.ipkg b/golden-tests/quox-golden-tests.ipkg new file mode 100644 index 0000000..cd89728 --- /dev/null +++ b/golden-tests/quox-golden-tests.ipkg @@ -0,0 +1,4 @@ +package quox-golden-tests +depends = quox, contrib, test +executable = quox-golden-tests +main = Tests diff --git a/golden-tests/run-tests.sh b/golden-tests/run-tests.sh new file mode 100755 index 0000000..67d86a1 --- /dev/null +++ b/golden-tests/run-tests.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +set -e + +quox="$PWD/../exe/build/exec/quox" +run_tests="$PWD/build/exec/quox-golden-tests" +test -f "$quox" || pack build quox +test -f "$run_tests" || pack build quox-golden-tests + +"$run_tests" "$quox" "$@" diff --git a/golden-tests/tests/empty/empty.quox b/golden-tests/tests/empty/empty.quox new file mode 100644 index 0000000..e69de29 diff --git a/golden-tests/tests/empty/expected b/golden-tests/tests/empty/expected new file mode 100644 index 0000000..e69de29 diff --git a/golden-tests/tests/empty/run b/golden-tests/tests/empty/run new file mode 100644 index 0000000..195c208 --- /dev/null +++ b/golden-tests/tests/empty/run @@ -0,0 +1,2 @@ +. ../lib.sh +scheme "$1" empty.quox diff --git a/golden-tests/tests/file-not-found/expected b/golden-tests/tests/file-not-found/expected new file mode 100644 index 0000000..33ee368 --- /dev/null +++ b/golden-tests/tests/file-not-found/expected @@ -0,0 +1,3 @@ +no location: +couldn't load file nonexistent.quox +File Not Found diff --git a/golden-tests/tests/file-not-found/run b/golden-tests/tests/file-not-found/run new file mode 100644 index 0000000..b164730 --- /dev/null +++ b/golden-tests/tests/file-not-found/run @@ -0,0 +1,2 @@ +. ../lib.sh +check "$1" nonexistent.quox diff --git a/golden-tests/tests/hello/expected b/golden-tests/tests/hello/expected new file mode 100644 index 0000000..7aea232 --- /dev/null +++ b/golden-tests/tests/hello/expected @@ -0,0 +1,12 @@ +0.IO : 1.★ → ★ +ω.print : 1.String → IO {ok} +ω.main : IO {ok} +IO = □ +print = scheme:(lambda (str) (builtin-io (display str) (newline))) +#[main] main = print "hello 🐉" +;; IO erased +(define print + (lambda (str) (builtin-io (display str) (newline)))) +(define main + (print "hello \x1f409;")) +hello 🐉 diff --git a/golden-tests/tests/hello/hello.quox b/golden-tests/tests/hello/hello.quox new file mode 100644 index 0000000..3b45067 --- /dev/null +++ b/golden-tests/tests/hello/hello.quox @@ -0,0 +1,7 @@ +def0 IO : ★ → ★ = λ A ⇒ IOState → A × IOState + +#[compile-scheme "(lambda (str) (builtin-io (display str) (newline)))"] +postulate print : String → IO {ok} + +#[main] +def main = print "hello 🐉" diff --git a/golden-tests/tests/hello/run b/golden-tests/tests/hello/run new file mode 100644 index 0000000..db7f834 --- /dev/null +++ b/golden-tests/tests/hello/run @@ -0,0 +1,2 @@ +. ../lib.sh +compile_run "$1" hello.quox hello.ss diff --git a/golden-tests/tests/ill-typed-main/expected b/golden-tests/tests/ill-typed-main/expected new file mode 100644 index 0000000..25498fb --- /dev/null +++ b/golden-tests/tests/ill-typed-main/expected @@ -0,0 +1,3 @@ +ill-typed-main.quox:1:11-1:12: + when checking a function declared as #[main] has type 1.IOState → {𝑎} × IOState + expected a function type, but got ℕ diff --git a/golden-tests/tests/ill-typed-main/ill-typed-main.quox b/golden-tests/tests/ill-typed-main/ill-typed-main.quox new file mode 100644 index 0000000..9ead5b5 --- /dev/null +++ b/golden-tests/tests/ill-typed-main/ill-typed-main.quox @@ -0,0 +1,2 @@ +#[main] +def main : ℕ = 5 diff --git a/golden-tests/tests/ill-typed-main/run b/golden-tests/tests/ill-typed-main/run new file mode 100644 index 0000000..5ad1fb7 --- /dev/null +++ b/golden-tests/tests/ill-typed-main/run @@ -0,0 +1,2 @@ +. ../lib.sh +check "$1" ill-typed-main.quox diff --git a/golden-tests/tests/it-5/expected b/golden-tests/tests/it-5/expected new file mode 100644 index 0000000..3644760 --- /dev/null +++ b/golden-tests/tests/it-5/expected @@ -0,0 +1,4 @@ +ω.five : ℕ +five = 5 +(define five + 5) diff --git a/golden-tests/tests/it-5/five.quox b/golden-tests/tests/it-5/five.quox new file mode 100644 index 0000000..365c1a7 --- /dev/null +++ b/golden-tests/tests/it-5/five.quox @@ -0,0 +1 @@ +def five : ℕ = 5 diff --git a/golden-tests/tests/it-5/run b/golden-tests/tests/it-5/run new file mode 100644 index 0000000..bb90a15 --- /dev/null +++ b/golden-tests/tests/it-5/run @@ -0,0 +1,2 @@ +. ../lib.sh +scheme "$1" five.quox diff --git a/golden-tests/tests/lib.sh b/golden-tests/tests/lib.sh new file mode 100644 index 0000000..7dbfb7b --- /dev/null +++ b/golden-tests/tests/lib.sh @@ -0,0 +1,18 @@ +FLAGS="--dump-check - --dump-erase - --dump-scheme - --color=none --width=100000" + +check() { + $1 $FLAGS "$2" -P check 2>&1 +} + +erase() { + $1 $FLAGS "$2" -P erase 2>&1 +} + +scheme() { + $1 $FLAGS "$2" -P scheme 2>&1 +} + +compile_run() { + $1 $FLAGS "$2" -o "$3" 2>&1 + chezscheme --program "$3" +} diff --git a/golden-tests/tests/load/expected b/golden-tests/tests/load/expected new file mode 100644 index 0000000..b7dd6c9 --- /dev/null +++ b/golden-tests/tests/load/expected @@ -0,0 +1,16 @@ +0.lib.IO : 1.★ → ★ +ω.lib.print : 1.String → lib.IO {ok} +ω.lib.main : lib.IO {ok} +ω.main : lib.IO {ok} +lib.IO = □ +lib.print = scheme:(lambda (str) (builtin-io (display str) (newline))) +lib.main = lib.print "hello 🐉" +#[main] main = lib.main +;; lib.IO erased +(define lib.print + (lambda (str) (builtin-io (display str) (newline)))) +(define lib.main + (lib.print "hello \x1f409;")) +(define main + lib.main) +hello 🐉 diff --git a/golden-tests/tests/load/lib.quox b/golden-tests/tests/load/lib.quox new file mode 100644 index 0000000..5ba4344 --- /dev/null +++ b/golden-tests/tests/load/lib.quox @@ -0,0 +1,8 @@ +namespace lib { +def0 IO : ★ → ★ = λ A ⇒ IOState → A × IOState + +#[compile-scheme "(lambda (str) (builtin-io (display str) (newline)))"] +postulate print : String → IO {ok} + +def main = print "hello 🐉" +} diff --git a/golden-tests/tests/load/main.quox b/golden-tests/tests/load/main.quox new file mode 100644 index 0000000..c53d261 --- /dev/null +++ b/golden-tests/tests/load/main.quox @@ -0,0 +1,4 @@ +load "lib.quox" + +#[main] +def main = lib.main diff --git a/golden-tests/tests/load/run b/golden-tests/tests/load/run new file mode 100644 index 0000000..677a01b --- /dev/null +++ b/golden-tests/tests/load/run @@ -0,0 +1,2 @@ +. ../lib.sh +compile_run "$1" main.quox load.ss diff --git a/pack.toml b/pack.toml index 61d7373..c323cad 100644 --- a/pack.toml +++ b/pack.toml @@ -20,3 +20,8 @@ ipkg = "quox.ipkg" type = "local" path = "./tests" ipkg = "quox-tests.ipkg" + +[custom.all.quox-golden-tests] +type = "local" +path = "./golden-tests" +ipkg = "quox-golden-tests.ipkg"