aboutsummaryrefslogtreecommitdiff
path: root/test/unit.bqn
blob: df2bfcf1f0b0b572bfc14fb25df5853a1b820e7f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#! /usr/bin/env bqn

# Tests for components of BQN: compiler, runtime, primitive spec

filesopts  2  ('-'=⊑)¨ •args
files  (0<≠)1,´"all"¨".bqn"¨, •file.List"cases" files
ncrtrefnoerr  "-nocomp""-rt""-ref""-noerr"  opts
"Can't test runtime without the compiler!" ! ¬ncrtref

Native  •BQN
ReBQN  {𝕊 rt:
  compile  (•Import "../src/glyphs.bqn") •Import "../src/c.bqn"
  vm  •Import "../vm.bqn"
  BQN  rt,{𝕊"bqn":BQN}¨(VM Compile)
}
exec  ((rt2×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  {eb𝕩
  Msg  {
    """",b,""": expected "
    "to fail"("!")e
    " but "
    0"received "·•Repr"{…}","evaluation failed"𝕩
  }
  ("!"<Native,0˙ e) 0,1•OutMsg <Exec0 b
}
r  (M '%'= (´)"1"<⊢, Trim¨(+`-2×) )¨ c
•Out 0<"All passed!",•Repr∾" failed!"˙ +´r