diff options
Diffstat (limited to 'stdlib/source/lux/test.lux')
-rw-r--r-- | stdlib/source/lux/test.lux | 112 |
1 files changed, 56 insertions, 56 deletions
diff --git a/stdlib/source/lux/test.lux b/stdlib/source/lux/test.lux index 9a43645e5..69cfbb647 100644 --- a/stdlib/source/lux/test.lux +++ b/stdlib/source/lux/test.lux @@ -1,4 +1,4 @@ -(;module: {#;doc "Tools for unit & property-based/generative testing."} +(.module: {#.doc "Tools for unit & property-based/generative testing."} lux (lux [macro #+ with-gensyms] (macro ["s" syntax #+ syntax: Syntax] @@ -30,16 +30,16 @@ (type: #export Counters [Nat Nat]) (type: #export Seed - {#;doc "The seed value used for random testing (if that feature is used)."} + {#.doc "The seed value used for random testing (if that feature is used)."} Nat) (type: #export Test - (r;Random (Promise [Counters Text]))) + (r.Random (Promise [Counters Text]))) (def: pcg-32-magic-inc Nat +12345) ## [Values] -(def: #hidden Monad<Random> (Monad r;Random) r;Monad<Random>) +(def: #hidden Monad<Random> (Monad r.Random) r.Monad<Random>) (def: success Counters [+1 +0]) (def: failure Counters [+0 +1]) @@ -53,19 +53,19 @@ (All [a] (-> Text Test)) (|> [failure (format " [Error] " message)] (:: Monad<Promise> wrap) - (:: r;Monad<Random> wrap))) + (:: r.Monad<Random> wrap))) (def: #export (assert message condition) - {#;doc "Check that a condition is true, and fail with the given message otherwise."} + {#.doc "Check that a condition is true, and fail with the given message otherwise."} (-> Text Bool (Promise [Counters Text])) (if condition (:: Monad<Promise> wrap [success (format "[Success] " message)]) (:: Monad<Promise> wrap [failure (format " [Error] " message)]))) (def: #export (test message condition) - {#;doc "Check that a condition is true, and fail with the given message otherwise."} + {#.doc "Check that a condition is true, and fail with the given message otherwise."} (-> Text Bool Test) - (:: r;Monad<Random> wrap (assert message condition))) + (:: r.Monad<Random> wrap (assert message condition))) (def: #hidden (run' tests) (-> (List [Text (IO Test) Text]) (Promise Counters)) @@ -74,29 +74,29 @@ (list/map (: (-> [Text (IO Test) Text] (Promise Counters)) (function [[module test description]] (do @ - [#let [pre (io;run instant;now) - seed (int-to-nat (instant;to-millis pre))] - [counters documentation] (|> (io;run test) - (r;run (r;pcg-32 [pcg-32-magic-inc seed])) - product;right) - #let [post (io;run instant;now) + [#let [pre (io.run instant.now) + seed (int-to-nat (instant.to-millis pre))] + [counters documentation] (|> (io.run test) + (r.run (r.pcg-32 [pcg-32-magic-inc seed])) + product.right) + #let [post (io.run instant.now) _ (log! (format "@ " module " " - "(" (%i (duration;to-millis (instant;span pre post))) "ms" ")" + "(" (%i (duration.to-millis (instant.span pre post))) "ms" ")" "\n" description "\n" "\n" documentation "\n"))]] (wrap counters))))) - (monad;seq @))] + (monad.seq @))] (wrap (list/fold add-counters start test-runs)))) (def: failed? (-> Counters Bool) - (|>> product;right (n/> +0))) + (|>> product.right (n/> +0))) (def: #export (seed value test) (-> Seed Test Test) (function [prng] - (let [[_ result] (r;run (r;pcg-32 [pcg-32-magic-inc value]) + (let [[_ result] (r.run (r.pcg-32 [pcg-32-magic-inc value]) test)] [prng result]))) @@ -109,21 +109,21 @@ test ## else - (do r;Monad<Random> - [seed r;nat] + (do r.Monad<Random> + [seed r.nat] (function [prng] - (let [[prng' instance] (r;run (r;pcg-32 [pcg-32-magic-inc seed]) test)] + (let [[prng' instance] (r.run (r.pcg-32 [pcg-32-magic-inc seed]) test)] [prng' (do Monad<Promise> [[counters documentation] instance] (if (failed? counters) (wrap [counters (format "Failed with this seed: " (%n seed) "\n" documentation)]) - (product;right (r;run prng' (times (n/dec amount) test)))))]))))) + (product.right (r.run prng' (times (n/dec amount) test)))))]))))) ## [Syntax] -(def: #hidden _code/text_ code;text) +(def: #hidden _code/text_ code.text) (syntax: #export (context: description test) - {#;doc (doc "Macro for definint tests." + {#.doc (doc "Macro for definint tests." (context: "Simple macros and constructs" ($_ seq (test "Can write easy loops for iterative programming." @@ -136,25 +136,25 @@ (test "Can create lists easily through macros." (and (case (list 1 2 3) - (#;Cons 1 (#;Cons 2 (#;Cons 3 #;Nil))) + (#.Cons 1 (#.Cons 2 (#.Cons 3 #.Nil))) true _ false) (case (list& 1 2 3 (list 4 5 6)) - (#;Cons 1 (#;Cons 2 (#;Cons 3 (#;Cons 4 (#;Cons 5 (#;Cons 6 #;Nil)))))) + (#.Cons 1 (#.Cons 2 (#.Cons 3 (#.Cons 4 (#.Cons 5 (#.Cons 6 #.Nil)))))) true _ false))) (test "Can have defaults for Maybe values." - (and (is "yolo" (maybe;default "yolo" - #;None)) + (and (is "yolo" (maybe.default "yolo" + #.None)) - (is "lol" (maybe;default "yolo" - (#;Some "lol"))))) + (is "lol" (maybe.default "yolo" + (#.Some "lol"))))) )) "Also works with random generation of values for property-based testing." @@ -188,50 +188,50 @@ )} (with-gensyms [g!context g!test g!error] (wrap (list (` (def: #export (~ g!context) - {#;;test (;;_code/text_ (~ description))} + {#..test (.._code/text_ (~ description))} (IO Test) - (io (case ("lux try" [(io (do ;;Monad<Random> [] (~ test)))]) - (#;Right (~ g!test)) + (io (case ("lux try" [(io (do ..Monad<Random> [] (~ test)))]) + (#.Right (~ g!test)) (~ g!test) - (#;Left (~ g!error)) - (;;fail (~ g!error)))))))))) + (#.Left (~ g!error)) + (..fail (~ g!error)))))))))) (def: (exported-tests module-name) (-> Text (Meta (List [Text Text Text]))) - (do macro;Monad<Meta> - [defs (macro;exports module-name)] + (do macro.Monad<Meta> + [defs (macro.exports module-name)] (wrap (|> defs (list/map (function [[def-name [_ def-anns _]]] - (case (macro;get-text-ann (ident-for #;;test) def-anns) - (#;Some description) + (case (macro.get-text-ann (ident-for #..test) def-anns) + (#.Some description) [true module-name def-name description] _ [false module-name def-name ""]))) - (list;filter product;left) - (list/map product;right))))) + (list.filter product.left) + (list/map product.right))))) -(def: #hidden _composeT_ (-> Text Text Text) (:: text;Monoid<Text> compose)) +(def: #hidden _composeT_ (-> Text Text Text) (:: text.Monoid<Text> compose)) (def: #hidden _%i_ (-> Int Text) %i) (syntax: #export (run) - {#;doc (doc "Runs all the tests defined on the current module, and in all imported modules." + {#.doc (doc "Runs all the tests defined on the current module, and in all imported modules." (run))} (with-gensyms [g!successes g!failures g!total-successes g!total-failures] (do @ - [current-module macro;current-module-name - modules (macro;imported-modules current-module) + [current-module macro.current-module-name + modules (macro.imported-modules current-module) tests (: (Meta (List [Text Text Text])) - (|> (#;Cons current-module modules) - list;reverse - (monad;map @ exported-tests) + (|> (#.Cons current-module modules) + list.reverse + (monad.map @ exported-tests) (:: @ map list/join))) #let [tests+ (list/map (function [[module-name test desc]] - (` [(~ (code;text module-name)) (~ (code;symbol [module-name test])) (~ (code;text desc))])) + (` [(~ (code.text module-name)) (~ (code.symbol [module-name test])) (~ (code.text desc))])) tests) - num-tests (list;size tests+) - groups (list;split-all promise;concurrency-level tests+)]] + num-tests (list.size tests+) + groups (list.split-all promise.concurrency-level tests+)]] (wrap (list (` (: (IO Unit) (io (exec (do Monad<Promise> [(~' #let) [(~ g!total-successes) +0 @@ -251,15 +251,15 @@ " tests passed." "\n" (_%i_ (nat-to-int (~ g!total-failures))) " tests failed.")) - (promise;future (if (n/> +0 (~ g!total-failures)) - ;;die - ;;exit)))) + (promise.future (if (n/> +0 (~ g!total-failures)) + ..die + ..exit)))) []))))))))) (def: #export (seq left right) - {#;doc "Sequencing combinator."} + {#.doc "Sequencing combinator."} (-> Test Test Test) - (do r;Monad<Random> + (do r.Monad<Random> [left left right right] (wrap (do Monad<Promise> |