diff options
author | Eduardo Julian | 2022-11-07 02:48:02 -0400 |
---|---|---|
committer | Eduardo Julian | 2022-11-07 02:48:02 -0400 |
commit | 13c594758482bac0a7550bcb89cfeda8c5f0a1f3 (patch) | |
tree | 251236c17f3fe0fbd7b302d4f143e51a85539cf3 /stdlib/source/library/lux/test | |
parent | ae4c0a4746d59b552ebeba166a43ce756dd265af (diff) |
Added support for inline testing.
Diffstat (limited to 'stdlib/source/library/lux/test')
-rw-r--r-- | stdlib/source/library/lux/test/inline.lux | 73 | ||||
-rw-r--r-- | stdlib/source/library/lux/test/property.lux | 6 | ||||
-rw-r--r-- | stdlib/source/library/lux/test/tally.lux | 4 |
3 files changed, 78 insertions, 5 deletions
diff --git a/stdlib/source/library/lux/test/inline.lux b/stdlib/source/library/lux/test/inline.lux new file mode 100644 index 000000000..191a798cb --- /dev/null +++ b/stdlib/source/library/lux/test/inline.lux @@ -0,0 +1,73 @@ +(.require + [library + [lux (.except static) + [abstract + [monad (.only do)]] + [control + ["?" parser] + ["[0]" try] + ["[0]" exception (.only Exception)]] + [data + ["[0]" text (.only) + ["%" \\format]]] + [math + [number (.only hex)] + ["[0]" random (.only Random)]] + ["[0]" meta (.only) + ["[0]" code (.only) + ["?[1]" \\parser (.only Parser)]] + [macro + [syntax (.only syntax)]]]]]) + +(exception.def .public (failure test) + (Exception Code) + (exception.report + (list ["Test" (%.code test)]))) + +(type .public Test + (Random Bit)) + +(def pcg_32_magic_inc + Nat + (hex "FEDCBA9876543210")) + +(def ?static + (Parser [(Maybe Nat) + Code]) + (?.either (do ?.monad + [seed ?code.nat + term ?code.any] + (in [{.#Some seed} term])) + (do ?.monad + [term ?code.any] + (in [{.#None} term])))) + +(def .public static + (syntax (_ [[seed term] ?static]) + (do [! meta.monad] + [test (meta.eval Test term) + seed (when seed + {.#Some seed} + (in seed) + + _ + meta.seed) + .let [[_ success?] (random.result (random.pcg_32 [..pcg_32_magic_inc seed]) + (as Test test))]] + (if success? + (in (list)) + (meta.failure (exception.error ..failure [term])))))) + +(def .public dynamic + (syntax (_ [test ?code.any]) + (do [! meta.monad] + [error_message (meta.try (meta.failure (exception.error ..failure [test])))] + (in (list (` (is Any + (if (is Bit (, test)) + [] + (panic! (, (code.text (when error_message + {try.#Failure error} + error + + {try.#Success _} + "")))))))))))) diff --git a/stdlib/source/library/lux/test/property.lux b/stdlib/source/library/lux/test/property.lux index db3adfb11..3223d7c06 100644 --- a/stdlib/source/library/lux/test/property.lux +++ b/stdlib/source/library/lux/test/property.lux @@ -94,10 +94,6 @@ test)] [prng result]))) -(def failed? - (-> Tally Bit) - (|>> (the tally.#failures) (n.> 0))) - (def separator text.new_line) @@ -129,7 +125,7 @@ (let [[prng' instance] (random.result (random.pcg_32 [..pcg_32_magic_inc seed]) test)] [prng' (do [! async.monad] [[tally documentation] instance] - (if (..failed? tally) + (if (tally.failed? tally) (in [tally (times_failure seed documentation)]) (exec (if announce_success? diff --git a/stdlib/source/library/lux/test/tally.lux b/stdlib/source/library/lux/test/tally.lux index 7c587d688..1ee172fae 100644 --- a/stdlib/source/library/lux/test/tally.lux +++ b/stdlib/source/library/lux/test/tally.lux @@ -19,6 +19,10 @@ #expected Coverage #actual Coverage])) +(def .public failed? + (-> Tally Bit) + (|>> (the #failures) (n.> 0))) + (def .public (and parameter subject) (-> Tally Tally Tally) [#successes (n.+ (the #successes parameter) (the #successes subject)) |