diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2021-10-31 18:08:32 -0400 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2021-10-31 20:00:03 -0400 |
| commit | ae3be51b576657d68130040251f15e74ee6bdfcf (patch) | |
| tree | 924e6fc75652a26c9a5d5186dfad47b4f03817f3 /test/unit.bqn | |
| parent | 05466cf34faedfb9aa46395c41da9b860f1f0f9d (diff) | |
Add tests based on vm.bqn
Diffstat (limited to 'test/unit.bqn')
| -rwxr-xr-x | test/unit.bqn | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/test/unit.bqn b/test/unit.bqn new file mode 100755 index 00000000..df2bfcf1 --- /dev/null +++ b/test/unit.bqn @@ -0,0 +1,42 @@ +#! /usr/bin/env bqn + +# Tests for components of BQN: compiler, runtime, primitive spec + +files‿opts ← 2 ↑ ('-'=⊑)¨⊸⊔ •args +files ↩ (0<≠)◶⟨1,∨´"all"⊸≡¨⟩◶⟨∾⟜".bqn"¨, •file.List∘"cases"⟩ files +nc‿rt‿ref‿noerr ← "-nocomp"‿"-rt"‿"-ref"‿"-noerr" ∊ opts +"Can't test runtime without the compiler!" ! ¬nc∧rt∨ref + +Native ← •BQN +ReBQN ← {𝕊 rt: + compile ← (•Import "../src/glyphs.bqn") •Import "../src/c.bqn" + vm ← •Import "../vm.bqn" + BQN ← ⟨rt,{𝕊"bqn":BQN}¨⟩⊸(VM Compile) +} +exec ← ((rt⌈2×ref)¬nc)◶⟨ + Native˙ # Native + {𝕤⋄ ReBQN •BQN∘⥊¨ ∾•Import "../src/glyphs.bqn"} # Compiled; native runtime + {𝕤⋄ ReBQN •Import "../rt.bqn"} # Self-hosted + {𝕤⋄ ReBQN •Import "ref.bqn"} # Reference implementations +⟩ @ + +c ← ∾ ((0<≠)◶0‿('#'≠⊑)¨⊸/ · •file.Lines "cases/"⊸∾)¨ files +c ↩ ('!'≠⊑)¨⊸/⍟noerr c +•Out 1↓∾' '⊸∾¨∾⟨ + ⟨"Running",•Repr≠c,"tests:"⟩ + noerr/⟨"(error cases excluded)"⟩ + ¯4↓¨files +⟩ + +Trim ← ((∨`∧∨`⌾⌽)' '⊸≠)⊸/ +M ← {e‿b←𝕩 + Msg ← {∾⟨ + """",b,""": expected " + "to fail"⍟("!"⊸≡)e + " but " + 0⊸≡◶⟨"received "∾·•Repr⎊"{…}"⊑,"evaluation failed"⟩𝕩 + ⟩} + ("!"⊸≡◶⟨<Native,0˙⟩ e) ≢◶⟨0,1∘•Out∘Msg⟩ <∘Exec⎊0 b +} +r ← (M '%'⊸= (∨´⊣)◶⟨"1"≍○<⊢, Trim¨(+`-2⊸×)⊸⊔⟩ ⊢)¨ c +•Out 0⊸<◶⟨"All passed!",•Repr∾" failed!"˙⟩ +´r |
