+test now deals with recursive directory structures.

+test now offloads creation of the test tree into a renderer. this should help
with caching. using a renderer also lets us deal with hierarchical directory
structures, leading to better organization.
This commit is contained in:
Elliot Glaysher 2018-01-06 22:51:52 -08:00
parent 625959a004
commit 48585d2b2f
7 changed files with 87 additions and 59 deletions

View File

@ -1,67 +1,35 @@
:: todo: think about using horns to import all tests in %/tests?
::
:: i should be able to use /: ?
/+ new-hoon, tester /+ new-hoon, tester
/= all-tests
:: ok, doing this as a list first. then do it automated. is there an equivalent /^ (map @ta tests:tester)
:: to /_ which works on an arbitrary directory? /: /===/tests
/= test-thr /: /===/tests/thr /!noun/ /_ /test-tree/
/= test-myb /: /===/tests/myb /!noun/ ::
/= test-ls /: /===/tests/ls /!noun/
/= test-mp /: /===/tests/mp /!noun/
=, new-hoon =, new-hoon
|% |%
:> # %models
+|
+= tests
:> a hierarchical structure of tests
:>
:> an alphabetically sorted recursive association list
:> mapping a part of a path to either a test trap or a
:> sublist of the same type.
(list (pair term (either (trap (list tape)) tests)))
::
:> # %test
+|
++ gen-tests
:> creates a {tests} list out of a vase of a test suite
|= [v=vase eny=@uvJ]
^- tests
=+ arms=(sort (sloe p.v) aor)
=+ context=(slop (init-test-vase:tester eny) v)
%+ map:ls arms
|= arm/term
:- arm
:- %&
|.
=/ r (slap context [%cnsg [arm ~] [%$ 3] [[%$ 2] ~]])
((hard (list tape)) q:(slap r [%limb %results]))
:: ::
++ test-runner ++ test-runner
:> run all tests in {a} with a filter. :> run all tests in {a} with a filter.
=| pax=path =| pax=path
|= [filter=path a=tests] |= [filter=path eny=@uvJ a=tests:tester]
^- tang ^- tang
%- concat:ls %- concat:ls
%+ map:ls a %+ turn a
|= b=(pair term (either (trap (list tape)) tests)) |= b=instance:tester
^- tang ^- tang
=^ matches filter (match-filter filter p.b) =^ matches filter (match-filter filter p.b)
?. matches ?. matches
~ ~
?- -.q.b ?- -.q.b
%& (run-test [p.b pax] p.q.b) %& (run-test [p.b pax] eny p.q.b)
%| ^$(pax [p.b pax], a p.q.b) %| ^$(pax [p.b pax], a p.q.b)
== ==
:: ::
++ run-test ++ run-test
:> executes an individual test. :> executes an individual test.
|= [pax=path test=(trap (list tape))] |= [pax=path eny=@uvJ test=$-(@uvJ (list tape))]
^- tang ^- tang
=+ name=(spud (reverse:ls pax)) =+ name=(spud (flop pax))
=+ run=(mule test) =+ run=(mule |.((test eny)))
~! run
?- -.run ?- -.run
$| :: the stack is already flopped for output? $| :: the stack is already flopped for output?
;: weld ;: weld
@ -74,7 +42,6 @@
%- flop %- flop
;: weld ;: weld
`tang`[[%leaf (weld name " FAILED")] ~] `tang`[[%leaf (weld name " FAILED")] ~]
~! p:run
%+ turn p:run %+ turn p:run
|= {i/tape} |= {i/tape}
^- tank ^- tank
@ -98,16 +65,7 @@
$~ $~
== ==
:- %tang :- %tang
%+ test-runner %^ test-runner
?~ filter ~ pax.filter ?~ filter ~ pax.filter
^- tests eny
:~ (test-map-to-test-list:tester all-tests)
:: todo: for now, this is manually constructed. later, this should
:: be generated from the contents of %/tests, without addressing the
:: files individually. if possible, lift the call to ++gen-tests into
:: the build steps for caching.
['ls' [%| (gen-tests !>(test-ls) eny)]]
['mp' [%| (gen-tests !>(test-mp) eny)]]
['myb' [%| (gen-tests !>(test-myb) eny)]]
['thr' [%| (gen-tests !>(test-thr) eny)]]
==

View File

@ -1,5 +1,65 @@
/+ new-hoon
:: common testing library. :: common testing library.
|% |%
:> # %models
+|
+= tests
:> a hierarchical structure of tests
:>
:> an alphabetically sorted recursive association list
:> mapping a part of a path to either a test trap or a
:> sublist of the same type.
(list instance)
::
+= instance
:> a mapping between a term and part of a test tree.
:>
(pair term (each $-(@uvJ (list tape)) tests))
::
:> # %generate
:> utilities for generating models.
+|
++ merge-base-and-recur
:> combine the current file and subdirectory.
:>
:> this merges the file {base} with its child files {recur}.
|= [base=vase recur=(map @ta tests:tester)]
^- tests
=+ a=(gen-tests base)
=+ b=(test-map-to-test-list recur)
:: todo: why does ++weld not work here? {a} and {b} are cast and have the
:: correct faces.
(welp a b)
::
++ test-map-to-test-list
:> translates ford output to something we can work with.
:>
:> ford gives us a `(map @ta tests:tester)`, but we actually
:> want something like ++tests.
|= a=(map @ta tests:tester)
:: todo: i'd like to sort this, but ++sort has -find.a problems much like
:: ++weld does above!?
^- tests
%+ turn
(to-list:dct:new-hoon a)
|= {key/@ta value/tests:tester}
[key [%| value]]
::
++ gen-tests
:> creates a {tests} list out of a vase of a test suite
|= v=vase :: eny=@uvJ]
^- tests
=+ arms=(sort (sloe p.v) aor)
%+ turn arms
|= arm/term
:- arm
:- %&
|= eny=@uvJ
=+ context=(slop (init-test-vase:tester eny) v)
=/ r (slap context [%cnsg [arm ~] [%$ 3] [[%$ 2] ~]])
((hard (list tape)) q:(slap r [%limb %results]))
::
++ init-test-vase ++ init-test-vase
|= {cookie/@uvJ} |= {cookie/@uvJ}
^- vase ^- vase
@ -79,7 +139,7 @@
:> # :> #
:> # %test :> # %test
:> # :> #
:> assertions on state :> test expectation functions
+| +|
:: todo: unit testing libraries have a lot more to them than just eq. :: todo: unit testing libraries have a lot more to them than just eq.
++ expect-eq ++ expect-eq
@ -99,7 +159,7 @@
:> # :> #
:> # %output :> # %output
:> # :> #
:> called by the test harness after test completion :> called by the test harness
:: ::
++ results ++ results
:> returns results. :> returns results.

10
ren/test-tree.hoon Normal file
View File

@ -0,0 +1,10 @@
/+ tester
/= base /| /!noun/
/~ ~
==
/= recur /^ (map @ta tests:tester)
/| /_ /test-tree/
/~ ~
==
::
(merge-base-and-recur:tester !>(base) recur)