diff options
author | Eduardo Julian | 2021-07-10 03:10:43 -0400 |
---|---|---|
committer | Eduardo Julian | 2021-07-10 03:10:43 -0400 |
commit | 4610968193df10af12c91f699fec39aeb3ef703a (patch) | |
tree | 27d1578548ad49f5aefe76fb696a7af10361c9cf /stdlib/source/test | |
parent | f3e869d0246e956399ec31a074c6c6299ff73602 (diff) |
Made the "try" macro into a common one, instead of a host-specific one.
Diffstat (limited to 'stdlib/source/test')
-rw-r--r-- | stdlib/source/test/aedifex/command/deps.lux | 7 | ||||
-rw-r--r-- | stdlib/source/test/aedifex/dependency/resolution.lux | 12 | ||||
-rw-r--r-- | stdlib/source/test/lux.lux | 5 | ||||
-rw-r--r-- | stdlib/source/test/lux/control/function/contract.lux | 9 | ||||
-rw-r--r-- | stdlib/source/test/lux/control/parser.lux | 76 | ||||
-rw-r--r-- | stdlib/source/test/lux/control/remember.lux | 10 | ||||
-rw-r--r-- | stdlib/source/test/lux/control/try.lux | 4 | ||||
-rw-r--r-- | stdlib/source/test/lux/ffi.js.lux | 7 | ||||
-rw-r--r-- | stdlib/source/test/lux/program.lux | 7 | ||||
-rw-r--r-- | stdlib/source/test/lux/target/jvm.lux | 8 | ||||
-rw-r--r-- | stdlib/source/test/lux/test.lux | 249 | ||||
-rw-r--r-- | stdlib/source/test/lux/time/instant.lux | 6 |
12 files changed, 329 insertions, 71 deletions
diff --git a/stdlib/source/test/aedifex/command/deps.lux b/stdlib/source/test/aedifex/command/deps.lux index ecb34437a..819495c02 100644 --- a/stdlib/source/test/aedifex/command/deps.lux +++ b/stdlib/source/test/aedifex/command/deps.lux @@ -103,8 +103,11 @@ (///dependency/deployment.all local)) post (|> (\ ///.monoid identity) (set@ #///.dependencies (set.from_list ///dependency.hash (list dependee depender))) - (/.do! console local (list (///repository.mock ($///dependency/resolution.single depender_artifact depender_package) - [])))) + (/.do! console local + (list (///repository.mock ($///dependency/resolution.single depender_artifact depender_package) + [])) + (function (_ url) + (///repository.mock $///dependency/resolution.nope [])))) #let [had_dependee_before! (set.member? pre dependee_artifact) diff --git a/stdlib/source/test/aedifex/dependency/resolution.lux b/stdlib/source/test/aedifex/dependency/resolution.lux index 42116844f..6d25ffd4b 100644 --- a/stdlib/source/test/aedifex/dependency/resolution.lux +++ b/stdlib/source/test/aedifex/dependency/resolution.lux @@ -86,6 +86,16 @@ (\ ///hash.md5_codec encode) (\ utf8.codec encode))) +(def: #export nope + (Mock Any) + (implementation + (def: the_description + "[0]") + (def: (on_download uri state) + (#try.Failure "NOPE")) + (def: (on_upload uri binary state) + (#try.Failure "NOPE")))) + (def: #export (single artifact package) (-> Artifact Package (Mock Any)) (let [expected (///artifact.uri (get@ #///artifact.version artifact) artifact)] @@ -407,6 +417,8 @@ (list (///repository.mock (..single dependee_artifact dependee_package) []) (///repository.mock (..single depender_artifact depender_package) []) (///repository.mock (..single ignored_artifact ignored_package) [])) + (function (_ url) + (///repository.mock ..nope [])) (list depender) /.empty)] (_.cover' [/.all] diff --git a/stdlib/source/test/lux.lux b/stdlib/source/test/lux.lux index beebb2844..b320841c5 100644 --- a/stdlib/source/test/lux.lux +++ b/stdlib/source/test/lux.lux @@ -38,6 +38,7 @@ ["#." meta] ["#." program] ["#." target] + ["#." test] ["#." time] ## ["#." tool] ## TODO: Update & expand tests for this ["#." type] @@ -209,7 +210,8 @@ (def: sub_tests Test - (with_expansions [<target> (for {@.jvm (~~ (as_is /target/jvm.test)) + (with_expansions [## TODO: Update & expand tests for this + <target> (for {@.jvm (~~ (as_is /target/jvm.test)) @.old (~~ (as_is /target/jvm.test))} (~~ (as_is))) <extension> (for {@.old (~~ (as_is))} @@ -224,6 +226,7 @@ /meta.test /program.test /target.test + /test.test /time.test ## /tool.test /type.test diff --git a/stdlib/source/test/lux/control/function/contract.lux b/stdlib/source/test/lux/control/function/contract.lux index 76eb07104..0e31427ee 100644 --- a/stdlib/source/test/lux/control/function/contract.lux +++ b/stdlib/source/test/lux/control/function/contract.lux @@ -1,7 +1,6 @@ (.module: [lux #* ["_" test (#+ Test)] - ["." ffi] [abstract [monad (#+ do)]] [control @@ -20,16 +19,16 @@ [expected random.nat]) ($_ _.and (_.cover [/.pre] - (case (ffi.try (/.pre (n.even? expected) - true)) + (case (try (/.pre (n.even? expected) + true)) (#try.Success output) output (#try.Failure error) (not (n.even? expected)))) (_.cover [/.post] - (case (ffi.try (/.post n.odd? - expected)) + (case (try (/.post n.odd? + expected)) (#try.Success actual) (is? expected actual) diff --git a/stdlib/source/test/lux/control/parser.lux b/stdlib/source/test/lux/control/parser.lux index bf69c8330..82ce4e6a4 100644 --- a/stdlib/source/test/lux/control/parser.lux +++ b/stdlib/source/test/lux/control/parser.lux @@ -12,7 +12,7 @@ [control ["." try (#+ Try)] [parser - ["s" code]]] + ["<.>" code]]] [data ["." text ("#\." equivalence) ["%" format (#+ format)]] @@ -96,44 +96,44 @@ ($_ _.and (_.cover [/.maybe] (and (|> (list (code.nat expected0)) - (/.run (/.maybe s.nat)) + (/.run (/.maybe <code>.nat)) (match (#.Some actual) (n.= expected0 actual))) (|> (list (code.int (.int expected0))) - (/.run (/.maybe s.nat)) + (/.run (/.maybe <code>.nat)) (match #.None #1)))) (_.cover [/.some] (and (|> (list\map code.nat expected+) - (/.run (/.some s.nat)) + (/.run (/.some <code>.nat)) (match actual (\ (list.equivalence n.equivalence) = expected+ actual))) (|> (list\map (|>> .int code.int) expected+) - (/.run (/.some s.nat)) + (/.run (/.some <code>.nat)) (match #.Nil #1)))) (_.cover [/.many] (and (|> (list\map code.nat expected+) - (/.run (/.many s.nat)) + (/.run (/.many <code>.nat)) (match actual (\ (list.equivalence n.equivalence) = expected+ actual))) (|> (list (code.nat expected0)) - (/.run (/.many s.nat)) + (/.run (/.many <code>.nat)) (match (list actual) (n.= expected0 actual))) (|> (list\map (|>> .int code.int) expected+) - (/.run (/.many s.nat)) + (/.run (/.many <code>.nat)) fails?))) (_.cover [/.filter] (and (|> (list (code.nat even0)) - (/.run (/.filter n.even? s.nat)) + (/.run (/.filter n.even? <code>.nat)) (match actual (n.= even0 actual))) (|> (list (code.nat odd0)) - (/.run (/.filter n.even? s.nat)) + (/.run (/.filter n.even? <code>.nat)) fails?))) (_.cover [/.and] - (let [even (/.filter n.even? s.nat) - odd (/.filter n.odd? s.nat)] + (let [even (/.filter n.even? <code>.nat) + odd (/.filter n.odd? <code>.nat)] (and (|> (list (code.nat even0) (code.nat odd0)) (/.run (/.and even odd)) (match [left right] @@ -143,8 +143,8 @@ (/.run (/.and even odd)) fails?)))) (_.cover [/.or] - (let [even (/.filter n.even? s.nat) - odd (/.filter n.odd? s.nat)] + (let [even (/.filter n.even? <code>.nat) + odd (/.filter n.odd? <code>.nat)] (and (|> (list (code.nat even0)) (/.run (/.or even odd)) (match (#.Left actual) (n.= even0 actual))) @@ -155,8 +155,8 @@ (/.run (/.or even odd)) fails?)))) (_.cover [/.either] - (let [even (/.filter n.even? s.nat) - odd (/.filter n.odd? s.nat)] + (let [even (/.filter n.even? <code>.nat) + odd (/.filter n.odd? <code>.nat)] (and (|> (list (code.nat even0)) (/.run (/.either even odd)) (match actual (n.= even0 actual))) @@ -168,10 +168,10 @@ fails?)))) (_.cover [/.not] (and (|> (list (code.nat expected0)) - (/.run (/.not s.nat)) + (/.run (/.not <code>.nat)) fails?) (|> (list (code.bit not0)) - (/.run (/.not s.nat)) + (/.run (/.not <code>.nat)) (match [] #1)))) ))) @@ -187,53 +187,53 @@ ($_ _.and (_.cover [/.exactly] (and (|> (list\map code.nat expected+) - (/.run (/.exactly times s.nat)) + (/.run (/.exactly times <code>.nat)) (match actual (\ (list.equivalence n.equivalence) = (list.take times expected+) actual))) (|> (list\map code.nat expected+) - (/.run (/.exactly (inc variadic) s.nat)) + (/.run (/.exactly (inc variadic) <code>.nat)) fails?))) (_.cover [/.at_least] (and (|> (list\map code.nat expected+) - (/.run (/.at_least times s.nat)) + (/.run (/.at_least times <code>.nat)) (match actual (\ (list.equivalence n.equivalence) = expected+ actual))) (|> (list\map code.nat expected+) - (/.run (/.at_least (inc variadic) s.nat)) + (/.run (/.at_least (inc variadic) <code>.nat)) fails?))) (_.cover [/.at_most] (and (|> (list\map code.nat expected+) - (/.run (/.at_most times s.nat)) + (/.run (/.at_most times <code>.nat)) (match actual (\ (list.equivalence n.equivalence) = (list.take times expected+) actual))) (|> (list\map code.nat expected+) - (/.run (/.at_most (inc variadic) s.nat)) + (/.run (/.at_most (inc variadic) <code>.nat)) (match actual (\ (list.equivalence n.equivalence) = expected+ actual))))) (_.cover [/.between] (and (|> (list\map code.nat expected+) - (/.run (/.between times variadic s.nat)) + (/.run (/.between times variadic <code>.nat)) (match actual (\ (list.equivalence n.equivalence) = expected+ actual))) (|> (list\map code.nat (list.take times expected+)) - (/.run (/.between times variadic s.nat)) + (/.run (/.between times variadic <code>.nat)) (match actual (\ (list.equivalence n.equivalence) = (list.take times expected+) actual))))) - (_.cover [/.sep_by] + (_.cover [/.separated_by] (|> (list.interpose (code.text separator) (list\map code.nat expected+)) - (/.run (/.sep_by (s.this! (code.text separator)) s.nat)) + (/.run (/.separated_by (<code>.this! (code.text separator)) <code>.nat)) (match actual (\ (list.equivalence n.equivalence) = expected+ @@ -261,14 +261,14 @@ [expected random.nat even (random.filter n.even? random.nat) odd (random.filter n.odd? random.nat) - #let [nat^ s.nat - even^ (/.filter n.even? s.nat) - odd^ (/.filter n.odd? s.nat)]] + #let [nat^ <code>.nat + even^ (/.filter n.even? <code>.nat) + odd^ (/.filter n.odd? <code>.nat)]] ($_ _.and (_.cover [/.rec] (let [parser (/.rec (function (_ self) - (/.either s.nat - (s.tuple self)))) + (/.either <code>.nat + (<code>.tuple self)))) level_0 (code.nat expected) level_up (: (-> Code Code) (|>> list code.tuple))] @@ -282,17 +282,17 @@ (/.run parser) (match actual (n.= expected actual)))))) (_.cover [/.after] - (and (|> (/.run (/.after even^ s.nat) + (and (|> (/.run (/.after even^ <code>.nat) (list (code.nat even) (code.nat expected))) (match actual (n.= expected actual))) - (|> (/.run (/.after even^ s.nat) + (|> (/.run (/.after even^ <code>.nat) (list (code.nat odd) (code.nat expected))) fails?))) (_.cover [/.before] - (and (|> (/.run (/.before even^ s.nat) + (and (|> (/.run (/.before even^ <code>.nat) (list (code.nat expected) (code.nat even))) (match actual (n.= expected actual))) - (|> (/.run (/.before even^ s.nat) + (|> (/.run (/.before even^ <code>.nat) (list (code.nat expected) (code.nat odd))) fails?))) (_.cover [/.parses?] @@ -324,7 +324,7 @@ (and happy_path! sad_path!))) (_.cover [/.codec] - (|> (/.run (/.codec n.decimal s.text) + (|> (/.run (/.codec n.decimal <code>.text) (list (code.text (%.nat expected)))) (match actual (n.= expected actual)))) ))) diff --git a/stdlib/source/test/lux/control/remember.lux b/stdlib/source/test/lux/control/remember.lux index 168f29f12..6e8c96118 100644 --- a/stdlib/source/test/lux/control/remember.lux +++ b/stdlib/source/test/lux/control/remember.lux @@ -40,7 +40,7 @@ #.None (list) (#.Some focus) (list focus)))))) -(def: (try computation) +(def: (attempt computation) (All [a] (-> (Meta a) (Meta (Try a)))) (function (_ compiler) (case (computation compiler) @@ -71,10 +71,10 @@ message (product.right (random.run prng ..message)) expected (product.right (random.run prng ..focus))] (do meta.monad - [should_fail0 (..try (macro.expand (to_remember macro yesterday message #.None))) - should_fail1 (..try (macro.expand (to_remember macro yesterday message (#.Some expected)))) - should_succeed0 (..try (macro.expand (to_remember macro tomorrow message #.None))) - should_succeed1 (..try (macro.expand (to_remember macro tomorrow message (#.Some expected))))] + [should_fail0 (..attempt (macro.expand (to_remember macro yesterday message #.None))) + should_fail1 (..attempt (macro.expand (to_remember macro yesterday message (#.Some expected)))) + should_succeed0 (..attempt (macro.expand (to_remember macro tomorrow message #.None))) + should_succeed1 (..attempt (macro.expand (to_remember macro tomorrow message (#.Some expected))))] (wrap (list (code.bit (and (case should_fail0 (#try.Failure error) (and (test_failure yesterday message #.None error) diff --git a/stdlib/source/test/lux/control/try.lux b/stdlib/source/test/lux/control/try.lux index b89246b26..6f1e22a7c 100644 --- a/stdlib/source/test/lux/control/try.lux +++ b/stdlib/source/test/lux/control/try.lux @@ -30,7 +30,7 @@ (function (_ ==) (\ (/.equivalence ==) =))) -(def: #export (try element) +(def: #export (attempt element) (All [a] (-> (Random a) (Random (Try a)))) ($_ random.or (random.unicode 1) @@ -47,7 +47,7 @@ #let [(^open "io\.") io.monad]]) ($_ _.and (_.for [/.equivalence] - ($equivalence.spec (/.equivalence n.equivalence) (..try random.nat))) + ($equivalence.spec (/.equivalence n.equivalence) (..attempt random.nat))) (_.for [/.functor] ($functor.spec ..injection ..comparison /.functor)) (_.for [/.apply] diff --git a/stdlib/source/test/lux/ffi.js.lux b/stdlib/source/test/lux/ffi.js.lux index ded33ed08..9835e52e4 100644 --- a/stdlib/source/test/lux/ffi.js.lux +++ b/stdlib/source/test/lux/ffi.js.lux @@ -64,13 +64,6 @@ (text\= "string" (/.type_of string)) (text\= "function" (/.type_of function)) (text\= "object" (/.type_of object)))) - (_.cover [/.try] - (case (/.try (error! string)) - (#try.Success _) - false - - (#try.Failure error) - (text\= string error))) (_.cover [/.import:] (let [encoding "utf8"] (text\= string diff --git a/stdlib/source/test/lux/program.lux b/stdlib/source/test/lux/program.lux index fe969cd3c..973216d84 100644 --- a/stdlib/source/test/lux/program.lux +++ b/stdlib/source/test/lux/program.lux @@ -1,7 +1,6 @@ (.module: [lux #* ["_" test (#+ Test)] - ["." ffi] [abstract [monad (#+ do)]] [control @@ -55,9 +54,9 @@ (:coerce (List Text) (io.run outcome))))) (with_expansions [<program> (/.program: [arg/0 arg/1 arg/2 arg/3] (io.io []))] - (case (ffi.try ((: (-> (List Text) (io.IO Any)) - (..actual_program <program>)) - inputs)) + (case (try ((: (-> (List Text) (io.IO Any)) + (..actual_program <program>)) + inputs)) (#try.Success _) false diff --git a/stdlib/source/test/lux/target/jvm.lux b/stdlib/source/test/lux/target/jvm.lux index 6e22d611f..acdeaf653 100644 --- a/stdlib/source/test/lux/target/jvm.lux +++ b/stdlib/source/test/lux/target/jvm.lux @@ -124,7 +124,7 @@ loader (/loader.memory (/loader.new_library []))] _ (/loader.define class_name bytecode loader) class (io.run (/loader.load class_name loader)) - method (ffi.try (get_method method_name class))] + method (try (get_method method_name class))] (java/lang/reflect/Method::invoke (ffi.null) (ffi.array java/lang/Object 0) method)) (#try.Success actual) (test actual) @@ -892,7 +892,7 @@ (case (do try.monad [_ (/loader.define class_name bytecode loader) class (io.run (/loader.load class_name loader)) - method (ffi.try (get_method static_method class)) + method (try (get_method static_method class)) output (java/lang/reflect/Method::invoke (ffi.null) (ffi.array java/lang/Object 0) method)] (wrap (:coerce Int output))) (#try.Success actual) @@ -1357,7 +1357,7 @@ loader (/loader.memory (/loader.new_library []))] _ (/loader.define class_name bytecode loader) class (io.run (/loader.load class_name loader)) - method (ffi.try (get_method object_method_name class))] + method (try (get_method object_method_name class))] (java/lang/reflect/Method::invoke (ffi.null) (ffi.array java/lang/Object 0) method)) (#try.Success actual) (test expected actual) @@ -1709,7 +1709,7 @@ _ (/loader.define interface_class interface_bytecode loader) _ (/loader.define concrete_class concrete_bytecode loader) class (io.run (/loader.load concrete_class loader)) - method (ffi.try (get_method static_method class)) + method (try (get_method static_method class)) output (java/lang/reflect/Method::invoke (ffi.null) (ffi.array java/lang/Object 0) method)] (wrap (:coerce Int output))) (#try.Success actual) diff --git a/stdlib/source/test/lux/test.lux b/stdlib/source/test/lux/test.lux new file mode 100644 index 000000000..d321f88f5 --- /dev/null +++ b/stdlib/source/test/lux/test.lux @@ -0,0 +1,249 @@ +(.module: + [lux #* + [abstract + [monad (#+ do)]] + [control + ["." io] + ["." exception] + [concurrency + ["." promise] + ["." atom (#+ Atom)]]] + [data + ["." text ("#\." equivalence)] + [collection + ["." list]]] + [math + ["." random] + [number + ["n" nat]]]] + {1 + ["." /]}) + +(def: (verify expected_message/0 expected_message/1 successes failures [tally message]) + (-> Text Text Nat Nat [/.Tally Text] Bit) + (and (text.contains? expected_message/0 message) + (text.contains? expected_message/1 message) + (n.= successes (get@ #/.successes tally)) + (n.= failures (get@ #/.failures tally)))) + +(def: assertion + /.Test + (do {! random.monad} + [expected_message/0 (random.ascii/lower 5) + expected_message/1 (random.filter (|>> (text\= expected_message/0) not) + (random.ascii/lower 5))] + ($_ /.and + (wrap (do promise.monad + [[success_tally success_message] (/.assert expected_message/0 true) + [failure_tally failure_message] (/.assert expected_message/0 false)] + (/.cover' [/.assert /.Tally] + (and (text.ends_with? expected_message/0 success_message) + (text.ends_with? expected_message/0 failure_message) + (and (n.= 1 (get@ #/.successes success_tally)) + (n.= 0 (get@ #/.failures success_tally))) + (and (n.= 0 (get@ #/.successes failure_tally)) + (n.= 1 (get@ #/.failures failure_tally))))))) + (wrap (do promise.monad + [tt (/.and' (/.assert expected_message/0 true) + (/.assert expected_message/1 true)) + ff (/.and' (/.assert expected_message/0 false) + (/.assert expected_message/1 false)) + tf (/.and' (/.assert expected_message/0 true) + (/.assert expected_message/1 false)) + ft (/.and' (/.assert expected_message/0 false) + (/.assert expected_message/1 true))] + (/.cover' [/.and'] + (and (..verify expected_message/0 expected_message/1 2 0 tt) + (..verify expected_message/0 expected_message/1 0 2 ff) + (..verify expected_message/0 expected_message/1 1 1 tf) + (..verify expected_message/0 expected_message/1 1 1 ft))))) + ))) + +(def: seed + /.Test + (do {! random.monad} + [seed random.nat + #let [[read write] (: [(promise.Promise Nat) (promise.Resolver Nat)] + (promise.promise []))] + pre (<| (/.seed seed) + (do ! + [sample random.nat + #let [wrote? (io.run (write sample))]] + (/.test "" wrote?))) + post (<| (/.seed seed) + (do ! + [actual random.nat] + (wrap (do promise.monad + [expected read] + (/.assert "" (n.= expected actual))))))] + (wrap (do promise.monad + [[pre_tally pre_message] pre + [post_tally post_message] post] + (/.cover' [/.seed] + (and (and (n.= 1 (get@ #/.successes pre_tally)) + (n.= 0 (get@ #/.failures pre_tally))) + (and (n.= 1 (get@ #/.successes post_tally)) + (n.= 0 (get@ #/.failures post_tally))))))))) + +(def: times + /.Test + ($_ /.and + (do {! random.monad} + [times_assertion (/.times 0 (/.test "" true))] + (wrap (do promise.monad + [[tally error] times_assertion] + (/.cover' [/.must_try_test_at_least_once] + (and (text.contains? (get@ #exception.label /.must_try_test_at_least_once) error) + (n.= 0 (get@ #/.successes tally)) + (n.= 1 (get@ #/.failures tally))))))) + (do {! random.monad} + [expected (\ ! map (|>> (n.% 10) inc) random.nat) + #let [counter (: (Atom Nat) + (atom.atom 0))] + times_assertion (<| (/.times expected) + (do ! + [_ (wrap []) + #let [_ (io.run (atom.update inc counter))]] + (/.test "" true)))] + (wrap (do promise.monad + [[tally error] times_assertion + actual (promise.future (atom.read counter))] + (/.cover' [/.times] + (and (n.= expected actual) + (n.= 1 (get@ #/.successes tally)) + (n.= 0 (get@ #/.failures tally))))))) + )) + +(def: in_parallel + /.Test + ($_ /.and + (do {! random.monad} + [expected (\ ! map (|>> (n.% 10) inc) random.nat) + #let [counter (: (Atom Nat) + (atom.atom 0))] + assertion (<| /.in_parallel + (list.repeat expected) + (: /.Test) + (do ! + [_ (wrap []) + #let [_ (io.run (atom.update inc counter))]] + (/.test "" true)))] + (wrap (do promise.monad + [[tally error] assertion + actual (promise.future (atom.read counter))] + (/.cover' [/.in_parallel] + (and (n.= expected actual) + (n.= expected (get@ #/.successes tally)) + (n.= 0 (get@ #/.failures tally))))))) + (do {! random.monad} + [expected (\ ! map (|>> (n.% 10) inc) random.nat) + #let [counter (: (Atom Nat) + (atom.atom 0))] + assertion (<| /.in_parallel + (list.repeat expected) + (: /.Test) + (do ! + [_ (wrap []) + #let [_ (undefined) + _ (io.run (atom.update inc counter))]] + (/.test "" true)))] + (wrap (do promise.monad + [[tally error] assertion + actual (promise.future (atom.read counter))] + (/.cover' [/.error_during_execution] + (let [correct_error! (text.contains? (get@ #exception.label /.error_during_execution) error) + no_complete_run! (n.= 0 actual) + no_successes! (n.= 0 (get@ #/.successes tally)) + ran_all_tests! (n.= expected (get@ #/.failures tally))] + (and correct_error! + no_complete_run! + no_successes! + ran_all_tests!)))))) + )) + +(def: #export test + /.Test + (<| (/.covering /._) + (/.for [/.Test]) + (do {! random.monad} + [expected_context (random.ascii/lower 5) + expected_message/0 (random.filter (|>> (text\= expected_context) not) + (random.ascii/lower 5)) + expected_message/1 (random.filter (|>> (text\= expected_message/0) not) + (random.ascii/lower 5))] + ($_ /.and + (/.for [/.Assertion] + ..assertion) + (/.for [/.Seed] + seed) + (do ! + [success_assertion (/.test expected_message/0 true) + failure_assertion (/.test expected_message/0 false)] + (wrap (do promise.monad + [[success_tally success_message] success_assertion + [failure_tally failure_message] failure_assertion] + (/.cover' [/.test] + (and (text.ends_with? expected_message/0 success_message) + (text.ends_with? expected_message/0 failure_message) + (and (n.= 1 (get@ #/.successes success_tally)) + (n.= 0 (get@ #/.failures success_tally))) + (and (n.= 0 (get@ #/.successes failure_tally)) + (n.= 1 (get@ #/.failures failure_tally)))))))) + (do ! + [tt (/.and (/.test expected_message/0 true) + (/.test expected_message/1 true)) + ff (/.and (/.test expected_message/0 false) + (/.test expected_message/1 false)) + tf (/.and (/.test expected_message/0 true) + (/.test expected_message/1 false)) + ft (/.and (/.test expected_message/0 false) + (/.test expected_message/1 true))] + (wrap (do promise.monad + [tt tt + ff ff + tf tf + ft ft] + (/.cover' [/.and] + (and (..verify expected_message/0 expected_message/1 2 0 tt) + (..verify expected_message/0 expected_message/1 0 2 ff) + (..verify expected_message/0 expected_message/1 1 1 tf) + (..verify expected_message/0 expected_message/1 1 1 ft)))))) + (do ! + [success_assertion (/.context expected_context (/.test expected_message/0 true)) + failure_assertion (/.context expected_context (/.test expected_message/0 false))] + (wrap (do promise.monad + [[success_tally success_message] success_assertion + [failure_tally failure_message] failure_assertion] + (/.cover' [/.context] + (and (and (text.contains? expected_context success_message) + (text.contains? expected_message/0 success_message)) + (and (text.contains? expected_context failure_message) + (text.contains? expected_message/0 failure_message)) + (and (n.= 1 (get@ #/.successes success_tally)) + (n.= 0 (get@ #/.failures success_tally))) + (and (n.= 0 (get@ #/.successes failure_tally)) + (n.= 1 (get@ #/.failures failure_tally)))))))) + (do ! + [failure_assertion (/.fail expected_message/0)] + (wrap (do promise.monad + [[failure_tally failure_message] failure_assertion] + (/.cover' [/.fail] + (and (text.contains? expected_message/0 failure_message) + (and (n.= 0 (get@ #/.successes failure_tally)) + (n.= 1 (get@ #/.failures failure_tally)))))))) + (do ! + [success_assertion (/.lift expected_message/0 (wrap true)) + failure_assertion (/.lift expected_message/0 (wrap false))] + (wrap (do promise.monad + [[success_tally success_message] success_assertion + [failure_tally failure_message] failure_assertion] + (/.cover' [/.lift] + (and (text.contains? expected_message/0 success_message) + (text.contains? expected_message/0 failure_message) + (and (n.= 1 (get@ #/.successes success_tally)) + (n.= 0 (get@ #/.failures success_tally))) + (and (n.= 0 (get@ #/.successes failure_tally)) + (n.= 1 (get@ #/.failures failure_tally)))))))) + ..times + ..in_parallel + )))) diff --git a/stdlib/source/test/lux/time/instant.lux b/stdlib/source/test/lux/time/instant.lux index 316ef8783..551144a6b 100644 --- a/stdlib/source/test/lux/time/instant.lux +++ b/stdlib/source/test/lux/time/instant.lux @@ -1,7 +1,6 @@ (.module: [lux #* ["_" test (#+ Test)] - ["." ffi] [abstract [monad (#+ do)] {[0 #spec] @@ -12,7 +11,8 @@ ["$." codec]]}] [control ["." function] - ["." try]] + ["." try] + ["." io]] [data [collection ["." list ("#\." fold)]]] @@ -97,7 +97,7 @@ (apply duration.inverse day\pred 6) (apply duration.inverse day\pred 7))))) (_.cover [/.now] - (case (ffi.try /.now) + (case (try (io.run /.now)) (#try.Success _) true |