diff options
Diffstat (limited to 'stdlib/source/library')
-rw-r--r-- | stdlib/source/library/lux/test.lux | 35 | ||||
-rw-r--r-- | stdlib/source/library/lux/test/tally.lux | 45 | ||||
-rw-r--r-- | stdlib/source/library/lux/test/unit.lux | 57 |
3 files changed, 74 insertions, 63 deletions
diff --git a/stdlib/source/library/lux/test.lux b/stdlib/source/library/lux/test.lux index 411c6c1c7..16df02a68 100644 --- a/stdlib/source/library/lux/test.lux +++ b/stdlib/source/library/lux/test.lux @@ -42,7 +42,8 @@ ["[0]" instant]]]]] [/ ["//" unit] - ["[0]" coverage (.only Coverage)]]) + ["[0]" coverage (.only Coverage)] + ["[0]" tally (.only Tally)]]) (type .public Test (Random //.Test)) @@ -94,8 +95,8 @@ [prng result]))) (def failed? - (-> //.Tally Bit) - (|>> (the //.#failures) (n.> 0))) + (-> Tally Bit) + (|>> (the tally.#failures) (n.> 0))) (def separator text.new_line) @@ -127,21 +128,21 @@ product.right))))]))))) (def (description duration tally) - (-> Duration //.Tally Text) - (let [successes (the //.#successes tally) - failures (the //.#failures tally) - missing (set.difference (the //.#actual tally) - (the //.#expected tally)) - unexpected (set.difference (the //.#expected tally) - (the //.#actual tally)) + (-> Duration Tally Text) + (let [successes (the tally.#successes tally) + failures (the tally.#failures tally) + missing (set.difference (the tally.#actual tally) + (the tally.#expected tally)) + unexpected (set.difference (the tally.#expected tally) + (the tally.#actual tally)) report (is (-> Coverage Text) (|>> set.list (list.sorted (at symbol.order <)) (exception.listing %.symbol))) - expected_coverage (set.size (the //.#expected tally)) + expected_coverage (set.size (the tally.#expected tally)) unexpected_coverage (set.size unexpected) actual_coverage (n.- unexpected_coverage - (set.size (the //.#actual tally))) + (set.size (the tally.#actual tally))) coverage (case expected_coverage 0 "N/A" expected (let [missing_ratio (f./ (n.frac expected) @@ -204,7 +205,7 @@ (console.write_line report console)) <else>))] (async.future (at environment.default exit - (case (the //.#failures tally) + (case (the tally.#failures tally) 0 ..success_exit_code _ ..failure_exit_code))))) @@ -237,7 +238,7 @@ (-> (List Test) Test) (case (list.size tests) 0 - (random#in (async#in [//.start ""])) + (random#in (async#in [tally.empty ""])) expected_tests (do random.monad @@ -254,10 +255,10 @@ {try.#Failure error} (//.test (exception.error ..error_during_execution [error]) false)))) - state (is (Atom (Dictionary Nat [//.Tally Text])) + state (is (Atom (Dictionary Nat [Tally Text])) (atom.atom (dictionary.empty n.order))) [read! write!] (is [//.Test - (async.Resolver [//.Tally Text])] + (async.Resolver [Tally Text])] (async.async [])) _ (list#mix (function (_ test index) (exec @@ -271,7 +272,7 @@ (list#each product.right))] (write! [(|> assertions (list#each product.left) - (list#mix //.total //.start)) + (list#mix tally.and tally.empty)) (|> assertions (list#each product.right) (text.interposed ..separator))])) diff --git a/stdlib/source/library/lux/test/tally.lux b/stdlib/source/library/lux/test/tally.lux new file mode 100644 index 000000000..afbab607a --- /dev/null +++ b/stdlib/source/library/lux/test/tally.lux @@ -0,0 +1,45 @@ +(.require + [library + [lux (.except and) + [data + [collection + ["[0]" set (.only Set)]]] + [math + [number + ["n" nat]]] + [meta + ["[0]" symbol]]]] + [// + ["[0]" coverage (.only Coverage)]]) + +(type .public Tally + (Record + [#successes Nat + #failures Nat + #expected Coverage + #actual Coverage])) + +(def .public (and parameter subject) + (-> Tally Tally Tally) + [#successes (n.+ (the #successes parameter) (the #successes subject)) + #failures (n.+ (the #failures parameter) (the #failures subject)) + #expected (set.union (the #expected parameter) + (the #expected subject)) + #actual (set.union (the #actual parameter) + (the #actual subject))]) + +(def .public empty + Tally + [#successes 0 + #failures 0 + #expected (set.empty symbol.hash) + #actual (set.empty symbol.hash)]) + +(with_template [<name> <category>] + [(def .public <name> + Tally + (revised <category> .++ ..empty))] + + [success #successes] + [failure #failures] + ) diff --git a/stdlib/source/library/lux/test/unit.lux b/stdlib/source/library/lux/test/unit.lux index 0e90bb46c..02e063447 100644 --- a/stdlib/source/library/lux/test/unit.lux +++ b/stdlib/source/library/lux/test/unit.lux @@ -15,8 +15,7 @@ ["[0]" list (.use "[1]#[0]" functor mix)] ["[0]" set (.only Set)]]] [math - [number (.only hex) - ["n" nat]]] + [number (.only hex)]] ["[0]" meta (.only) ["[0]" symbol] ["[0]" code (.only) @@ -24,39 +23,8 @@ [macro [syntax (.only syntax)]]]]] [// - ["[0]" coverage (.only Coverage)]]) - -(type .public Tally - (Record - [#successes Nat - #failures Nat - #expected Coverage - #actual Coverage])) - -(def .public (total parameter subject) - (-> Tally Tally Tally) - [#successes (n.+ (the #successes parameter) (the #successes subject)) - #failures (n.+ (the #failures parameter) (the #failures subject)) - #expected (set.union (the #expected parameter) - (the #expected subject)) - #actual (set.union (the #actual parameter) - (the #actual subject))]) - -(def .public start - Tally - [#successes 0 - #failures 0 - #expected (set.empty symbol.hash) - #actual (set.empty symbol.hash)]) - -(with_template [<name> <category>] - [(def <name> - Tally - (revised <category> .++ ..start))] - - [success_tally #successes] - [failure_tally #failures] - ) + ["[0]" coverage (.only Coverage)] + ["[0]" tally (.only Tally)]]) (type .public Test (Async [Tally Text])) @@ -72,7 +40,7 @@ _ (|> left (async.upon! (function (_ [l_tally l_documentation]) (async.upon! (function (_ [r_tally r_documentation]) - (write! [(..total l_tally r_tally) + (write! [(tally.and l_tally r_tally) (format l_documentation ..separator r_documentation)])) right))) io.run!)] @@ -91,19 +59,16 @@ (-> Text Test Test) (|>> %.text context')) -(def failure_prefix "[Failure] ") -(def success_prefix "[Success] ") - (def .public failure (-> Text Test) - (|>> (format ..failure_prefix) - [..failure_tally] + (|>> (format "[Failure] ") + [tally.failure] async#in)) (def .public success (-> Text Test) - (|>> (format ..success_prefix) - [..success_tally] + (|>> (format "[Success] ") + [tally.success] async#in)) (def .public (test message condition) @@ -128,7 +93,7 @@ coverage (set.of_list symbol.hash coverage)] (|> (..test message condition) (async#each (function (_ [tally documentation]) - [(revised #actual (set.union coverage) tally) + [(revised tally.#actual (set.union coverage) tally) documentation]))))) (def .public coverage @@ -148,7 +113,7 @@ (text.interposed ..definition_separator)) coverage (set.of_list symbol.hash coverage)] (async#each (function (_ [tally documentation]) - [(revised #actual (set.union coverage) tally) + [(revised tally.#actual (set.union coverage) tally) documentation]) (..context' context test)))) @@ -167,7 +132,7 @@ (let [coverage (coverage.decoded module coverage)] (|> (..context' module test) (async#each (function (_ [tally documentation]) - [(revised #expected (set.union coverage) tally) + [(revised tally.#expected (set.union coverage) tally) (|> documentation (text.replaced (format ..clean_up_marker module symbol.separator) "") (text.replaced ..clean_up_marker ""))]))))) |