aboutsummaryrefslogtreecommitdiff
path: root/test/unit.bqn
blob: 52a61556f289cb393da6610c035c2d0a82b41497 (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
43
44
#! /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
exec  {
  nc ? Native ;
  # Otherwise compiled
  gl  •Import "../src/glyphs.bqn"
  compile  gl •Import "../src/c.bqn"
  vm  •Import "../vm.bqn"
  r  {
    ref ? •Import "ref.bqn"   ;  # Reference implementations
    rt  ? •Import "../rt.bqn" ;  # Self-hosted
    •BQN¨ gl                  # Native runtime
  }
  BQN  r,{𝕊"bqn":BQN}¨(VM Compile)
}

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