From 93217d7cce249854248ce68d455705253cf63a65 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Mon, 1 Nov 2021 16:51:04 -0400 Subject: Clean up test directory structure --- docs/running.html | 2 +- running.md | 2 +- test/README.txt | 44 ++++++++++++++++++++++++-------------------- test/dc.bqn | 2 -- test/dz_comp | 34 ---------------------------------- test/dz_wasm.js | 27 --------------------------- test/dzaima | 34 ++++++++++++++++++++++++++++++++++ test/wasm.js | 27 +++++++++++++++++++++++++++ 8 files changed, 87 insertions(+), 85 deletions(-) mode change 100755 => 100644 test/dc.bqn delete mode 100755 test/dz_comp delete mode 100755 test/dz_wasm.js create mode 100755 test/dzaima create mode 100755 test/wasm.js diff --git a/docs/running.html b/docs/running.html index 98e6ce01..fc91a006 100644 --- a/docs/running.html +++ b/docs/running.html @@ -5,7 +5,7 @@

How to run BQN

-

CBQN is now the primary offline implementation. However, dzaima/BQN still works, and is used for some testing. Scripts in this repository use bqn in the #! line if any BQN can run them, and dbqn if only dzaima/BQN works.

+

CBQN is now the primary offline implementation, and can be used everywhere in this repository, except test/dzaima which is specifically for testing with dzaima/BQN. Scripts start with #! /usr/bin/env bqn in order to look up the user's bqn executable.

For Nix users, nixpkgs now has repositories for several implementations; cbqn is recommended for general use.

Self-hosted BQN

See the subsections below for instructions on specific implementations.

diff --git a/running.md b/running.md index 51b6f1a0..9582ce53 100644 --- a/running.md +++ b/running.md @@ -2,7 +2,7 @@ # How to run BQN -[CBQN](https://github.com/dzaima/CBQN) is now the primary offline implementation. However, dzaima/BQN still works, and is used for some testing. Scripts in this repository use `bqn` in the `#!` line if any BQN can run them, and `dbqn` if only dzaima/BQN works. +[CBQN](https://github.com/dzaima/CBQN) is now the primary offline implementation, and can be used everywhere in this repository, except test/dzaima which is specifically for testing with dzaima/BQN. Scripts start with `#! /usr/bin/env bqn` in order to look up the user's `bqn` executable. For Nix users, nixpkgs now has repositories for several implementations; `cbqn` is recommended for general use. diff --git a/test/README.txt b/test/README.txt index f11502b9..97a9d6da 100644 --- a/test/README.txt +++ b/test/README.txt @@ -1,26 +1,30 @@ -Test scripts: +Does your BQN work? Run - Script Compiler host Output host/VM -- this.bqn Any Same -- unit.bqn Any Same + repo -- js Self-host Javascript -- dz_comp dzaima/BQN dzaima/BQN + repo -- dz_wasm.js dzaima/BQN WebAssembly +$ bqn test/this.bqn + +to see. There are additional tests here used for development: + + Script Compiler host Output host/VM +- this.bqn bqn Self +- js docs/bqn.js Self +- unit.bqn bqn Self + repo +- dzaima dzaima/BQN Self + repo +- wasm.js bqn WebAssembly this.bqn can be run in any implementation that supports the necessary -system functions (•file.List, •file.Lines, •args, •Out, •BQN, •Repr). It -runs all tests by default, and can be run on a subset by passing their -names as arguments. +system functions (•file.List, •file.Lines, •args, •Out, •BQN, •Repr). -dz_comp uses the self-hosted compiler ../src/c.bqn by default but not -the runtime ../src/r*.bqn. Pass -rt to test with the runtime, and -nocomp -to test dzaima/BQN only (this doesn't pass as of the time of writing). +unit.bqn and dz_comp use the self-hosted compiler ../src/c.bqn by +default but not the runtime ../src/r*.bqn. Pass -rt to test with the +runtime, and -nocomp to test dzaima/BQN only (this doesn't pass as of +the time of writing). -Test cases (cases/): - js dz_comp dz_wasm.js -- simple.bqn * * * -- syntax.bqn * * -- prim.bqn * +Every script but wasm.js can be run on a specified set of tests by +passing the test names as arguments. this.bqn and unit.bqn run on all +tests by default; other scripts use the following default tests: -js or dz_comp can be run on a specified set of tests by passing the test -names as arguments. +Test cases (cases/): + js dzaima wasm.js +- simple.bqn * * * +- syntax.bqn * * +- prim.bqn * diff --git a/test/dc.bqn b/test/dc.bqn old mode 100755 new mode 100644 index 5a0ccae8..0607dc99 --- a/test/dc.bqn +++ b/test/dc.bqn @@ -1,5 +1,3 @@ -#! /usr/bin/env dbqn - # dzaima/BQN block headers have a different format to account for # multiple bodies, and use variable names instead of counts. # Rearrange and make up some names so the bytecode can be run. diff --git a/test/dz_comp b/test/dz_comp deleted file mode 100755 index e9bf1c06..00000000 --- a/test/dz_comp +++ /dev/null @@ -1,34 +0,0 @@ -#! /usr/bin/env dbqn - -nc‿rt‿ref ← "-nocomp"‿"-rt"‿"-ref" ∊ •args -files ← "simple"‿"syntax"‿"prim"⍟(0=≠) ('-'≠⊑)¨⊸/ •args -"Can't test runtime without the compiler!" ! ¬nc∧rt∨ref - -Native ← •BQN -exec ← { - nc ? Native ; - # Otherwise compiled - ⟨DRun⟩ ← •Import "dc.bqn" - r ← { - ref ? •Import "ref.bqn" ; # Reference implementations - rt ? •Import "dzrt.bqn" ; # Self-hosted - •BQN∘⥊¨ ∾ •Import "../src/glyphs.bqn" # Native runtime - } - r⊸DRun -} - -Cases ← (0<≠)◶0‿('#'≠⊑)¨⊸/ · •FLines "cases/"∾∾⟜".bqn" -c ← ∾ Cases¨ files -Trim ← ((∨`∧∨`⌾⌽)' '⊸≠)⊸/ -M ← {e‿b: - Msg ← {∾⟨ - """",b,""": expected " - "to fail"⍟("!"⊸≡)e - " but " - 0⊸≡◶⟨"received "∾2•Fmt⊑,"evaluation failed"⟩𝕩 - ⥊@+10 - ⟩} - ("!"⊸≡◶⟨require('fs').readFileSync(__dirname+'/'+f,'utf8') - , runWasm=w=>new WebAssembly.Instance(new WebAssembly.Module(Uint8Array.from(w))) - .exports.fn() - -const t=load('cases/simple.bqn').split('\n').filter(x=>x).map(x=>x.split(' % ')) - , test=t.map(e=> e[1]) - , expt=t.map(e=>+e[0]) - -var compiler = execFile( - __dirname+'/../wc.bqn', - test, - function (error, stdout, stderr) { - const rslt=stdout.split('\n').filter(a=>a.length) - .map(a=>runWasm(a.split(" ").map(n=>+n))) - , pass=expt.map((e,i)=>e===rslt[i]) - , fail=pass.map((p,i)=>p?-1:i).filter(i=>i>=0) - console.log( - fail.length - ? fail.map(i=>'"'+t[i][1]+'": expected '+expt[i]+' but received '+rslt[i]) - : "All passed!" - ) - process.exit(+(fail.length>0)) - } -); diff --git a/test/dzaima b/test/dzaima new file mode 100755 index 00000000..e9bf1c06 --- /dev/null +++ b/test/dzaima @@ -0,0 +1,34 @@ +#! /usr/bin/env dbqn + +nc‿rt‿ref ← "-nocomp"‿"-rt"‿"-ref" ∊ •args +files ← "simple"‿"syntax"‿"prim"⍟(0=≠) ('-'≠⊑)¨⊸/ •args +"Can't test runtime without the compiler!" ! ¬nc∧rt∨ref + +Native ← •BQN +exec ← { + nc ? Native ; + # Otherwise compiled + ⟨DRun⟩ ← •Import "dc.bqn" + r ← { + ref ? •Import "ref.bqn" ; # Reference implementations + rt ? •Import "dzrt.bqn" ; # Self-hosted + •BQN∘⥊¨ ∾ •Import "../src/glyphs.bqn" # Native runtime + } + r⊸DRun +} + +Cases ← (0<≠)◶0‿('#'≠⊑)¨⊸/ · •FLines "cases/"∾∾⟜".bqn" +c ← ∾ Cases¨ files +Trim ← ((∨`∧∨`⌾⌽)' '⊸≠)⊸/ +M ← {e‿b: + Msg ← {∾⟨ + """",b,""": expected " + "to fail"⍟("!"⊸≡)e + " but " + 0⊸≡◶⟨"received "∾2•Fmt⊑,"evaluation failed"⟩𝕩 + ⥊@+10 + ⟩} + ("!"⊸≡◶⟨require('fs').readFileSync(__dirname+'/'+f,'utf8') + , runWasm=w=>new WebAssembly.Instance(new WebAssembly.Module(Uint8Array.from(w))) + .exports.fn() + +const t=load('cases/simple.bqn').split('\n').filter(x=>x).map(x=>x.split(' % ')) + , test=t.map(e=> e[1]) + , expt=t.map(e=>+e[0]) + +var compiler = execFile( + __dirname+'/../wc.bqn', + test, + function (error, stdout, stderr) { + const rslt=stdout.split('\n').filter(a=>a.length) + .map(a=>runWasm(a.split(" ").map(n=>+n))) + , pass=expt.map((e,i)=>e===rslt[i]) + , fail=pass.map((p,i)=>p?-1:i).filter(i=>i>=0) + console.log( + fail.length + ? fail.map(i=>'"'+t[i][1]+'": expected '+expt[i]+' but received '+rslt[i]) + : "All passed!" + ) + process.exit(+(fail.length>0)) + } +); -- cgit v1.2.3