diff options
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/library/lux/test.lux | 78 |
1 files changed, 39 insertions, 39 deletions
diff --git a/stdlib/source/library/lux/test.lux b/stdlib/source/library/lux/test.lux index d0a87c083..071798222 100644 --- a/stdlib/source/library/lux/test.lux +++ b/stdlib/source/library/lux/test.lux @@ -49,7 +49,7 @@ #expected_coverage (Set Symbol) #actual_coverage (Set Symbol)])) -(def: (total parameter subject) +(def (total parameter subject) (-> Tally Tally Tally) [#successes (n.+ (the #successes parameter) (the #successes subject)) #failures (n.+ (the #failures parameter) (the #failures subject)) @@ -58,7 +58,7 @@ #actual_coverage (set.union (the #actual_coverage parameter) (the #actual_coverage subject))]) -(def: start +(def start Tally [#successes 0 #failures 0 @@ -66,7 +66,7 @@ #actual_coverage (set.empty symbol.hash)]) (with_template [<name> <category>] - [(def: <name> + [(def <name> Tally (revised <category> .++ ..start))] @@ -80,10 +80,10 @@ (type: .public Test (Random Assertion)) -(def: separator +(def separator text.new_line) -(def: .public (and' left right) +(def .public (and' left right) (-> Assertion Assertion Assertion) (let [[read! write!] (is [(Async [Tally Text]) (async.Resolver [Tally Text])] @@ -97,13 +97,13 @@ io.run!)] read!)) -(def: .public (and left right) +(def .public (and left right) (-> Test Test Test) (do [! random.monad] [left left] (at ! each (..and' left) right))) -(def: (context' description) +(def (context' description) (-> Text Test Test) (random#each (async#each (function (_ [tally documentation]) [tally (|> documentation @@ -112,61 +112,61 @@ (text.interposed ..separator) (format description ..separator))])))) -(def: .public context +(def .public context (-> Text Test Test) (|>> %.text context')) -(def: failure_prefix "[Failure] ") -(def: success_prefix "[Success] ") +(def failure_prefix "[Failure] ") +(def success_prefix "[Success] ") -(def: .public failure +(def .public failure (-> Text Test) (|>> (format ..failure_prefix) [..failure_tally] async#in random#in)) -(def: .public (assertion message condition) +(def .public (assertion message condition) (-> Text Bit Assertion) (<| async#in (if condition [..success_tally (format ..success_prefix message)] [..failure_tally (format ..failure_prefix message)]))) -(def: .public (property message condition) +(def .public (property message condition) (-> Text Bit Test) (random#in (..assertion (%.text message) condition))) -(def: .public (lifted message random) +(def .public (lifted message random) (-> Text (Random Bit) Test) (random#each (..assertion (%.text message)) random)) -(def: pcg_32_magic_inc +(def pcg_32_magic_inc Nat (hex "FEDCBA9876543210")) (type: .public Seed Nat) -(def: .public (seed value test) +(def .public (seed value test) (-> Seed Test Test) (function (_ prng) (let [[_ result] (random.result (random.pcg_32 [..pcg_32_magic_inc value]) test)] [prng result]))) -(def: failed? +(def failed? (-> Tally Bit) (|>> (the #failures) (n.> 0))) -(def: (times_failure seed documentation) +(def (times_failure seed documentation) (-> Seed Text Text) (format documentation ..separator ..separator "Failed with this seed: " (%.nat seed))) (exception: .public must_try_test_at_least_once) -(def: .public (times amount test) +(def .public (times amount test) (-> Nat Test Test) (case amount 0 (..failure (exception.error ..must_try_test_at_least_once [])) @@ -185,7 +185,7 @@ (random.result prng') product.right))))]))))) -(def: (description duration tally) +(def (description duration tally) (-> Duration Tally Text) (let [successes (the #successes tally) failures (the #failures tally) @@ -235,10 +235,10 @@ "Pending definitions to cover" (report missing) "Unexpected definitions covered" (report unexpected)))) -(def: failure_exit_code +1) -(def: success_exit_code +0) +(def failure_exit_code +1) +(def success_exit_code +0) -(def: .public (run! test) +(def .public (run! test) (-> Test (Async Nothing)) (do async.monad [pre (async.future instant.now) @@ -264,15 +264,15 @@ 0 ..success_exit_code _ ..failure_exit_code))))) -(def: definition_separator " & ") +(def definition_separator " & ") -(def: clean_up_marker (text.of_char (hex "05"))) +(def clean_up_marker (text.of_char (hex "05"))) -(def: coverage_format +(def coverage_format (%.Format Symbol) (|>> %.symbol (format ..clean_up_marker))) -(def: (|coverage'| coverage condition) +(def (|coverage'| coverage condition) (-> (List Symbol) Bit Assertion) (let [message (|> coverage (list#each ..coverage_format) @@ -283,12 +283,12 @@ [(revised #actual_coverage (set.union coverage) tally) documentation]))))) -(def: (|coverage| coverage condition) +(def (|coverage| coverage condition) (-> (List Symbol) Bit Test) (|> (..|coverage'| coverage condition) random#in)) -(def: (|for| coverage test) +(def (|for| coverage test) (-> (List Symbol) Test Test) (let [context (|> coverage (list#each ..coverage_format) @@ -299,22 +299,22 @@ documentation])) (..context' context test)))) -(def: (symbol_code symbol) +(def (symbol_code symbol) (-> Symbol Code) (code.tuple (list (code.text (symbol.module symbol)) (code.text (symbol.short symbol))))) -(def: reference +(def reference (syntax (_ [name <code>.symbol]) (do meta.monad [_ (meta.export name)] (in (list (symbol_code name)))))) -(def: coverage_separator +(def coverage_separator Text (text.of_char 31)) -(def: encoded_coverage +(def encoded_coverage (-> (List Text) Text) (list#mix (function (_ short aggregate) (case aggregate @@ -322,7 +322,7 @@ _ (format aggregate ..coverage_separator short))) "")) -(def: (coverage_definitions module encoding) +(def (coverage_definitions module encoding) (-> Text Text (Set Symbol)) (loop (again [remaining encoding output (set.of_list symbol.hash (list))]) @@ -334,7 +334,7 @@ (set.has [module remaining] output)))) (with_template [<macro> <function>] - [(def: .public <macro> + [(def .public <macro> (syntax (_ [coverage (<code>.tuple (<>.many <code>.any)) condition <code>.any]) (let [coverage (list#each (function (_ definition) @@ -349,7 +349,7 @@ [coverage ..|coverage|] ) -(def: .public for +(def .public for (syntax (_ [coverage (<code>.tuple (<>.many <code>.any)) test <code>.any]) (let [coverage (list#each (function (_ definition) @@ -360,7 +360,7 @@ (.list (~+ coverage))) (~ test)))))))) -(def: (covering' module coverage test) +(def (covering' module coverage test) (-> Text Text Test Test) (let [coverage (..coverage_definitions module coverage)] (|> (..context' module test) @@ -370,7 +370,7 @@ (text.replaced (format ..clean_up_marker module symbol.separator) "") (text.replaced ..clean_up_marker ""))])))))) -(def: .public covering +(def .public covering (syntax (_ [module <code>.symbol test <code>.any]) (do meta.monad @@ -392,7 +392,7 @@ (exception.report "Error" (%.text error))) -(def: .public (in_parallel tests) +(def .public (in_parallel tests) (-> (List Test) Test) (case (list.size tests) 0 |