uCBQN/test/run.bqn

272 lines
9.8 KiB
BQN
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

NextIdx {i/𝕩 (i𝕩)˜i𝕨} # for each index 𝕨, find the index of the next 1 in mask 𝕩
UM {(𝕨)/𝕩}
Fail {•Out 𝕩 •Exit 1}
Trim {((``)𝕩' ')/𝕩}
{ 𝕊:
•Out "Usage: test/run.bqn [options | files]"
•Out "Options:"
•Out " lint Check that every test either is expected to return a specific value, error, or contains a '!'"
•Out " slow Enable slow tests"
•Out " noerr Disable erroring tests (ones expected to, or which contain ⎊)"
•Out " heapverify Disable tests that aren't runnable in heapverify"
•Out " debug Disable tests that aren't runnable in debug"
•Out " no-catch Disable catching errors in tests not expected to error"
•Out " update-messages Auto-update error messages in tests"
•Out " ignore-messages Don't warn about incorrect error messages"
•Out " bin-search Binary search for some property. Next argument should be /[01]*/, with a 1 appended every time the property is matched, and a 0 otherwise"
•Out " seed=123 Random seed for tests that care (default=1; seed=u will choose a random seed)"
•Exit 0
} (0=•args) ´ "help""h""?"'-'/¨•args
o {
args •args
search @
{
n»𝕩
search '0'-˜(n/args)<""
! ´search01
search search1
args (¬n𝕩)/args
}(´) "bin-search"¨ args
named "run""lint""update-messages""slow""ignore-messages""noerr""heapverify""debug""no-catch""seed"
i named{𝕩˜𝕩'='}¨ args
run ´i=0
lint ´i=1
update ´i=2
slow ´i=3
errm ¬´i=4
noerr ´i=5
heapverify ´i=6
debug ´i=7
noCatch ´i=8
seed {
: 1;
"u": s•rand.Range 231 •Out "seed="•Repr s s;
s: •ParseFloat 5s
} (i=9)/args
usz
properFills
eachFills
randomizeHeuristics
knownHeapverify
knownDebug
hasTestUtils
32000000 {(𝕨) 𝕩 (𝕩)𝕨} {PProperties: @P@; } •internal
noerr heapverify
update ¬heapverify
files (i=named)/args
run update ¬´lintupdate
}
_catch_ {o.noCatch? 𝔽; 𝔽𝔾}
searchRefine {
searchI 0
{
o.search@? 𝕩;
searchIo.search? 𝕩;
1𝕩? 𝕩;
SearchRefine (2÷˜𝕩) ((searchI+1) searchIo.search) 𝕩
}
}
exitCode 0
Run { 𝕊 testname:
lns •FLines fullfile "cases"•file.At filename ".bqn" ˜(-) testname
defkdefv "IS_HEAPVERIFY""heapverify←"•Repr o.heapverify
i 0
Pos {filename, ":", •Repr 1+𝕩}
Next {𝕊: (i+1) ilns}
Process {
"%DEF "5𝕩?
defkdefv¨<¨ {(Process 1𝕩).str}(1) ' '() 5𝕩
@
;
"":@
;
'#'𝕩? @
;
"("𝕩?
Process (@+10)¨ ¯1 <Next•_while_{")"¯1𝕩} Next@
;
# insert defs
si /(𝕩)"%USE"𝕩
mi si+5
ei mi NextIdx ¬𝕩'_'"0aA"+¨102626
g (+`+´ 𝕩UM¨ simiei) 𝕩
pre g
[·,uk,post] 31g
{Fail (Pos i)": Unknown def "𝕩uk} /¬ukdefk
str pre ((defkuk)defv) ¨ post
Flag {
m (str) 𝕩str
str /˜ ¬ »(¯1+𝕩) m
´m
}
{
enabled ¬ (¬o.slow) Flag "%SLOW"
enabled ¬ o.debug Flag "%!DEBUG"
enabled ¬ o.heapverify Flag "%!HEAPVERIFY"
enabled {00: 1; 10: o.properFills; 01: ¬o.properFills} Flag¨ "%PROPER_FILLS""%!PROPER_FILLS"
enabled {00: 1; 10: o.eachFills ; 01: ¬o.eachFills } Flag¨ "%EACH_FILLS""%!EACH_FILLS"
enabled {00: 1; 10: o.usz=32; 01: o.usz=64} Flag¨ "%USZ32""%USZ64"
enabled {00: 1; 10: o.usz=32; 01: o.usz=64} Flag¨ "%USZ32""%EACHFILLS"
ln i-1
str str # at end to let Flag have updated it
}
}
tests SearchRefine @¨/ <(ProcessNext)•_while_{𝕊: ilns}
{𝕊: •Out "Narrowed down to test "Pos (tests).ln} (o.search@)1=tests
tests { 𝕊ns: ln,strns
idx str'%'
{
idx str? ns, "eval", str;
(i2idx+1)<str? '%'i2str? ns, "equal", idxstr, (2+idx)str;
{𝕊: Fail (Pos ln)": Unknown test format"} '!'str
ns, "error", (idx+1)str, 1idxstr
}
}¨
{ 𝕊 d:
ln(d).ln
ty1d
Lint {𝕊: •Out "Lint: ", Pos ln, ": ", 𝕨}(¬)
{
"eval"ty? "No check or assert" Lint ´'!'=2d;
@
}
}¨o.lint tests
{ 𝕊:
badCount 0
badMessage 0
currLn 0
skipped 0
dir •file.At "testDir"
•file.CreateDir(¬•file.Exists) dir
Bad {
""𝕊𝕩;
•Out Pos currLn, ": ", 𝕩
•Out¨ " "¨ 𝕨
badCount+ 1
}
ErrMsg {𝕊: m•CurrentError@ {1==m? ´2=•Type¨m? m; •Repr"(unrepresentable)" m}}
PreEval
_addPreEval {𝕩? PreEvalPreEval 𝔽; @}
{𝕊: 1 •internal.Temp o.seed}_addPreEval o.randomizeHeuristics
Eval {
PreEval@
dir, testname,"_line_",•Repr currLn+1,".bqn", helpers,"arg0",1 •BQN 𝕩
}
EvalS •BQN{𝕊: Bad "Computing expected value errored" "(could not compute expected value)"}
toRun tests
toRun {{𝕩.enabled}¨/𝕩}
skipped+ (tests)-toRun
results {
"eval"str: {
o.noerr? '⎊'str? skipped+1;
Eval _catch_ {𝕊: Bad "Expected success, got error: "ErrMsg@} str
@
};
"error"strexp: {
o.noerr? skipped+1;
okgot (1Eval)(0ErrMsg) str
exp EvalS{×Trim𝕩} exp
{
(gotexp) ¬ok? @;
ok? Bad "Expected error, but didn't get one" @;
"Expected: "exp "Got: "got Bado.errm "Wrong error message"
badMessage+ 1
got
}
};
"equal"strexp: {
o.noerr? '⎊'str? skipped+1;
okgot (1Eval)_catch_(0ErrMsg) str
exp EvalS exp
{
¬ok? Bad "Expected value, but got error: "got;
got •internal.EEqual exp? @;
"Expected: "•Repr exp "Got: "•Repr•Show got Bad "Wrong value"
@
}
@
}
}{currLn(𝕩).ln 1𝕩}¨ toRun
{𝕊:
resdesc ({@𝕩? 0; (¬(@+10)𝕩) ¬´"TEST FAIL"𝕩}¨ results)/¨ resultstoRun
0res?
•Out "Update ", •Reprres, " entr", (1<res)"y""ies", " in ", filename, "?"
{
¬"yY"˜'n'˜•GetLine@? •Out "Not updating.";
[idxs, upd] >res {new𝕊ln, "error", str, ·: ln "!", •Repr new, " ", '%' lnlns}¨ desc
"Refusing to write over changed file" ! lns •FLines fullfile
fullfile •FLines lns {×𝕩? 𝕩; 𝕨}¨ (lns)idxsupd
•Out "Updated."
}
;@
} o.update
skipm (×skipped)/" (", •Repr skipped, " skipped)"
ran (tests)-skipped
{
0=badCount? •Out filename": "(•Repr ran)" passed!"skipm;
•Out •Repr ran-badCount, '/', •Repr ran, skipm ((¬o.errm)×badMessage)/"; ", •Repr badMessage, " mismatched error message", (1badMessage)/"s"skipm
exitCode 1
}
}o.run @
}
helpers {
TVVariation, CLRClearRefs, HasFill, EEqual, ListVariations •internal
indistinguishable {IIndistinguishable: I; EEqual} •internal
_tvar0_ {
F _𝕣_ LV x: (CLR@) { F 𝕩 TV x}¨ LV 𝕩;
w F _𝕣_ LV x: (CLR@) (LV 𝕨) {(𝕨 TV w) F 𝕩 TV x} LV 𝕩
}
{o.heapverify? IndistinguishableEEqual; @}
Classify {(𝕩) Indistinguishable˜ 𝕩}
_eqvar0_ { LV 𝔾
r 𝕨 𝔽 _tvar0_ 𝔾 𝕩
class {·𝕊·: 𝕨+2×𝕩; 𝕊·: 𝕩} c0(r) {HasFill 𝕩? 'h' = 1¨ LV 𝕩; 𝕨0}¨ args𝕨𝕩
(r)("failed eqvar eequal" ! EEqual)¨ 1r
{
r0 𝕩
{
r0 Indistinguishable 𝕩?
1;
classes {
a: (@+10) •Fmt "type""class" ˘ a Classify r;
wcxc:
wvxv LV¨ args
wcxc+'A'
"row=type of 𝕨, col=type of 𝕩:" @+10,' ',' '¨ "\|",xc," ==",' '¨xv (wc¨wv) {cv𝕊𝕩: c '|' 𝕩 ' ' v}¨ <˘ '0'+Classify r
} c0
! "TEST FAIL: _eqvar0_ failed: "classes
}¨ 𝕩
}¨ class r
r
}
_eqvar {𝔽 _eqvar0_ ListVariations}
_eqvarv_ {𝔽 _eqvar0_ (𝕘ListVariations)}
}
Run¨ SearchRefine o.files
•Exit(0)(¬o.heapverify) exitCode