uCBQN/test/run.bqn
dzaima cca858ceee test system improvements
- tolerate an existing ".bqn" in arguments
- actually assert test in fuzz/scan.bqn
2025-03-11 23:41:11 +02:00

212 lines
7.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"
•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"
i namedargs
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
pr 3200 {𝕩(𝕩)𝕨} {PProperties: 3@P@; } •internal
usz 0pr
properFills 1pr
eachFills 2pr
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}}
Eval {dir, testname,"_line_",•Repr currLn+1,".bqn", "arg0",1 •BQN 𝕩}
EvalS •BQN{𝕊: Bad "Bad comparison value" "(bad)"}
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 @
}
Run¨ SearchRefine o.files
•Exit(0)(¬o.heapverify) exitCode