aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/test.lux
diff options
context:
space:
mode:
authorEduardo Julian2022-07-28 17:39:01 -0400
committerEduardo Julian2022-07-28 17:39:01 -0400
commita4b64bf1cdf47160b6b615d2c6493039abfd7a94 (patch)
tree3fe8c149d9cad89bbf067c736d196260203d1a01 /stdlib/source/test/lux/test.lux
parenta4847190df926d35f7ece97da50a2a8b1462a24f (diff)
Extracted unit-testing machinery into its own module.
Diffstat (limited to '')
-rw-r--r--stdlib/source/test/lux/test.lux243
1 files changed, 122 insertions, 121 deletions
diff --git a/stdlib/source/test/lux/test.lux b/stdlib/source/test/lux/test.lux
index 3e47848dc..956969668 100644
--- a/stdlib/source/test/lux/test.lux
+++ b/stdlib/source/test/lux/test.lux
@@ -20,16 +20,17 @@
[number
["n" nat]]]]]
[\\library
- ["[0]" /]])
+ ["[0]" / (.only)
+ ["[0]" unit]]])
(def (verify expected_message/0 expected_message/1 successes failures [tally message])
- (-> Text Text Nat Nat [/.Tally Text] Bit)
+ (-> Text Text Nat Nat [unit.Tally Text] Bit)
(and (text.contains? expected_message/0 message)
(text.contains? expected_message/1 message)
- (n.= successes (the /.#successes tally))
- (n.= failures (the /.#failures tally))))
+ (n.= successes (the unit.#successes tally))
+ (n.= failures (the unit.#failures tally))))
-(def assertion
+(def unit_test
/.Test
(do [! random.monad]
[expected_message/0 (random.lower_case 5)
@@ -37,25 +38,25 @@
(random.lower_case 5))]
(all /.and
(in (do async.monad
- [[success_tally success_message] (/.assertion expected_message/0 true)
- [failure_tally failure_message] (/.assertion expected_message/0 false)]
- (/.coverage' [/.assertion /.Tally]
+ [[success_tally success_message] (unit.test expected_message/0 true)
+ [failure_tally failure_message] (unit.test expected_message/0 false)]
+ (unit.coverage [unit.test unit.Tally]
(and (text.ends_with? expected_message/0 success_message)
(text.ends_with? expected_message/0 failure_message)
- (and (n.= 1 (the /.#successes success_tally))
- (n.= 0 (the /.#failures success_tally)))
- (and (n.= 0 (the /.#successes failure_tally))
- (n.= 1 (the /.#failures failure_tally)))))))
+ (and (n.= 1 (the unit.#successes success_tally))
+ (n.= 0 (the unit.#failures success_tally)))
+ (and (n.= 0 (the unit.#successes failure_tally))
+ (n.= 1 (the unit.#failures failure_tally)))))))
(in (do async.monad
- [tt (/.and' (/.assertion expected_message/0 true)
- (/.assertion expected_message/1 true))
- ff (/.and' (/.assertion expected_message/0 false)
- (/.assertion expected_message/1 false))
- tf (/.and' (/.assertion expected_message/0 true)
- (/.assertion expected_message/1 false))
- ft (/.and' (/.assertion expected_message/0 false)
- (/.assertion expected_message/1 true))]
- (/.coverage' [/.and']
+ [tt (unit.and (unit.test expected_message/0 true)
+ (unit.test expected_message/1 true))
+ ff (unit.and (unit.test expected_message/0 false)
+ (unit.test expected_message/1 false))
+ tf (unit.and (unit.test expected_message/0 true)
+ (unit.test expected_message/1 false))
+ ft (unit.and (unit.test expected_message/0 false)
+ (unit.test expected_message/1 true))]
+ (unit.coverage [unit.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)
@@ -72,49 +73,49 @@
(do !
[sample random.nat
.let [wrote? (io.run! (write sample))]]
- (/.property "" wrote?)))
+ (/.test "" wrote?)))
post (<| (/.seed seed)
(do !
[actual random.nat]
(in (do async.monad
[expected read]
- (/.assertion "" (n.= expected actual))))))]
+ (unit.test "" (n.= expected actual))))))]
(in (do async.monad
[[pre_tally pre_message] pre
[post_tally post_message] post]
- (/.coverage' [/.seed]
- (and (and (n.= 1 (the /.#successes pre_tally))
- (n.= 0 (the /.#failures pre_tally)))
- (and (n.= 1 (the /.#successes post_tally))
- (n.= 0 (the /.#failures post_tally)))))))))
+ (unit.coverage [/.seed]
+ (and (and (n.= 1 (the unit.#successes pre_tally))
+ (n.= 0 (the unit.#failures pre_tally)))
+ (and (n.= 1 (the unit.#successes post_tally))
+ (n.= 0 (the unit.#failures post_tally)))))))))
(def times
/.Test
(all /.and
(do [! random.monad]
- [times_assertion (/.times 0 (/.property "" true))]
+ [times_unit_test (/.times 0 (/.test "" true))]
(in (do async.monad
- [[tally error] times_assertion]
- (/.coverage' [/.must_try_test_at_least_once]
+ [[tally error] times_unit_test]
+ (unit.coverage [/.must_try_test_at_least_once]
(and (text.contains? (the exception.#label /.must_try_test_at_least_once) error)
- (n.= 0 (the /.#successes tally))
- (n.= 1 (the /.#failures tally)))))))
+ (n.= 0 (the unit.#successes tally))
+ (n.= 1 (the unit.#failures tally)))))))
(do [! random.monad]
[expected (at ! each (|>> (n.% 10) ++) random.nat)
.let [counter (is (Atom Nat)
(atom.atom 0))]
- times_assertion (<| (/.times expected)
+ times_unit_test (<| (/.times expected)
(do !
[_ (in [])
.let [_ (io.run! (atom.update! ++ counter))]]
- (/.property "" true)))]
+ (/.test "" true)))]
(in (do async.monad
- [[tally error] times_assertion
+ [[tally error] times_unit_test
actual (async.future (atom.read! counter))]
- (/.coverage' [/.times]
+ (unit.coverage [/.times]
(and (n.= expected actual)
- (n.= 1 (the /.#successes tally))
- (n.= 0 (the /.#failures tally)))))))
+ (n.= 1 (the unit.#successes tally))
+ (n.= 0 (the unit.#failures tally)))))))
))
(def in_parallel
@@ -124,40 +125,40 @@
[expected (at ! each (|>> (n.% 10) ++) random.nat)
.let [counter (is (Atom Nat)
(atom.atom 0))]
- assertion (<| /.in_parallel
+ unit_test (<| /.in_parallel
(list.repeated expected)
(is /.Test)
(do !
[_ (in [])
.let [_ (io.run! (atom.update! ++ counter))]]
- (/.property "" true)))]
+ (/.test "" true)))]
(in (do async.monad
- [[tally error] assertion
+ [[tally error] unit_test
actual (async.future (atom.read! counter))]
- (/.coverage' [/.in_parallel]
+ (unit.coverage [/.in_parallel]
(and (n.= expected actual)
- (n.= expected (the /.#successes tally))
- (n.= 0 (the /.#failures tally)))))))
+ (n.= expected (the unit.#successes tally))
+ (n.= 0 (the unit.#failures tally)))))))
(do [! random.monad]
[expected (at ! each (|>> (n.% 10) ++) random.nat)
.let [counter (is (Atom Nat)
(atom.atom 0))]
- assertion (<| /.in_parallel
+ unit_test (<| /.in_parallel
(list.repeated expected)
(is /.Test)
(do !
[_ (in [])
.let [_ (undefined)
_ (io.run! (atom.update! ++ counter))]]
- (/.property "" true)))]
+ (/.test "" true)))]
(in (do async.monad
- [[tally error] assertion
+ [[tally error] unit_test
actual (async.future (atom.read! counter))]
- (/.coverage' [/.error_during_execution]
+ (unit.coverage [/.error_during_execution]
(let [correct_error! (text.contains? (the exception.#label /.error_during_execution) error)
no_complete_run! (n.= 0 actual)
- no_successes! (n.= 0 (the /.#successes tally))
- ran_all_tests! (n.= expected (the /.#failures tally))]
+ no_successes! (n.= 0 (the unit.#successes tally))
+ ran_all_tests! (n.= expected (the unit.#failures tally))]
(and correct_error!
no_complete_run!
no_successes!
@@ -171,49 +172,49 @@
/.Test
(all /.and
(do random.monad
- [not_covering (/.property "" true)
- covering (/.covering .._ (/.property "" true))]
+ [not_covering (/.test "" true)
+ covering (/.covering .._ (/.test "" true))]
(in (do async.monad
[[not_covering _] not_covering
[covering _] covering]
- (/.coverage' [/.covering]
- (and (and (set.empty? (the /.#expected not_covering))
- (set.empty? (the /.#actual not_covering)))
- (and (not (set.empty? (the /.#expected covering)))
- (set.empty? (the /.#actual covering))))))))
+ (unit.coverage [/.covering]
+ (and (and (set.empty? (the unit.#expected not_covering))
+ (set.empty? (the unit.#actual not_covering)))
+ (and (not (set.empty? (the unit.#expected covering)))
+ (set.empty? (the unit.#actual covering))))))))
(do random.monad
- [not_covering (/.covering .._ (/.property "" true))
+ [not_covering (/.covering .._ (/.test "" true))
covering (/.covering .._ (/.coverage [..dummy_target] true))]
(in (do async.monad
[[not_covering _] not_covering
[covering _] covering]
- (/.coverage' [/.coverage]
- (and (and (not (set.empty? (the /.#expected not_covering)))
- (not (set.member? (the /.#actual not_covering) (symbol ..dummy_target))))
- (and (not (set.empty? (the /.#expected covering)))
- (set.member? (the /.#actual covering) (symbol ..dummy_target))))))))
+ (unit.coverage [/.coverage]
+ (and (and (not (set.empty? (the unit.#expected not_covering)))
+ (not (set.member? (the unit.#actual not_covering) (symbol ..dummy_target))))
+ (and (not (set.empty? (the unit.#expected covering)))
+ (set.member? (the unit.#actual covering) (symbol ..dummy_target))))))))
(do random.monad
- [not_covering (/.covering .._ (/.property "" true))
- covering (/.covering .._ (in (/.coverage' [..dummy_target] true)))]
+ [not_covering (/.covering .._ (/.test "" true))
+ covering (/.covering .._ (in (unit.coverage [..dummy_target] true)))]
(in (do async.monad
[[not_covering _] not_covering
[covering _] covering]
- (/.coverage' [/.coverage']
- (and (and (not (set.empty? (the /.#expected not_covering)))
- (not (set.member? (the /.#actual not_covering) (symbol ..dummy_target))))
- (and (not (set.empty? (the /.#expected covering)))
- (set.member? (the /.#actual covering) (symbol ..dummy_target))))))))
+ (unit.coverage [unit.coverage]
+ (and (and (not (set.empty? (the unit.#expected not_covering)))
+ (not (set.member? (the unit.#actual not_covering) (symbol ..dummy_target))))
+ (and (not (set.empty? (the unit.#expected covering)))
+ (set.member? (the unit.#actual covering) (symbol ..dummy_target))))))))
(do random.monad
- [not_covering (/.covering .._ (/.property "" true))
- covering (/.covering .._ (/.for [..dummy_target] (/.property "" true)))]
+ [not_covering (/.covering .._ (/.test "" true))
+ covering (/.covering .._ (/.for [..dummy_target] (/.test "" true)))]
(in (do async.monad
[[not_covering _] not_covering
[covering _] covering]
- (/.coverage' [/.for]
- (and (and (not (set.empty? (the /.#expected not_covering)))
- (not (set.member? (the /.#actual not_covering) (symbol ..dummy_target))))
- (and (not (set.empty? (the /.#expected covering)))
- (set.member? (the /.#actual covering) (symbol ..dummy_target))))))))
+ (unit.coverage [/.for]
+ (and (and (not (set.empty? (the unit.#expected not_covering)))
+ (not (set.member? (the unit.#actual not_covering) (symbol ..dummy_target))))
+ (and (not (set.empty? (the unit.#expected covering)))
+ (set.member? (the unit.#actual covering) (symbol ..dummy_target))))))))
))
(def .public test
@@ -227,78 +228,78 @@
expected_message/1 (random.only (|>> (text#= expected_message/0) not)
(random.lower_case 5))]
(all /.and
- (/.for [/.Assertion]
- ..assertion)
+ (/.for [unit.Test]
+ ..unit_test)
(/.for [/.Seed]
seed)
(do !
- [success_assertion (/.property expected_message/0 true)
- failure_assertion (/.property expected_message/0 false)]
+ [success_unit_test (/.test expected_message/0 true)
+ failure_unit_test (/.test expected_message/0 false)]
(in (do async.monad
- [[success_tally success_message] success_assertion
- [failure_tally failure_message] failure_assertion]
- (/.coverage' [/.property]
+ [[success_tally success_message] success_unit_test
+ [failure_tally failure_message] failure_unit_test]
+ (unit.coverage [/.test]
(and (text.ends_with? (%.text expected_message/0) success_message)
(text.ends_with? (%.text expected_message/0) failure_message)
- (and (n.= 1 (the /.#successes success_tally))
- (n.= 0 (the /.#failures success_tally)))
- (and (n.= 0 (the /.#successes failure_tally))
- (n.= 1 (the /.#failures failure_tally))))))))
+ (and (n.= 1 (the unit.#successes success_tally))
+ (n.= 0 (the unit.#failures success_tally)))
+ (and (n.= 0 (the unit.#successes failure_tally))
+ (n.= 1 (the unit.#failures failure_tally))))))))
(do !
- [tt (/.and (/.property expected_message/0 true)
- (/.property expected_message/1 true))
- ff (/.and (/.property expected_message/0 false)
- (/.property expected_message/1 false))
- tf (/.and (/.property expected_message/0 true)
- (/.property expected_message/1 false))
- ft (/.and (/.property expected_message/0 false)
- (/.property expected_message/1 true))]
+ [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))]
(in (do async.monad
[tt tt
ff ff
tf tf
ft ft]
- (/.coverage' [/.and]
+ (unit.coverage [/.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 (/.property expected_message/0 true))
- failure_assertion (/.context expected_context (/.property expected_message/0 false))]
+ [success_unit_test (/.context expected_context (/.test expected_message/0 true))
+ failure_unit_test (/.context expected_context (/.test expected_message/0 false))]
(in (do async.monad
- [[success_tally success_message] success_assertion
- [failure_tally failure_message] failure_assertion]
- (/.coverage' [/.context]
+ [[success_tally success_message] success_unit_test
+ [failure_tally failure_message] failure_unit_test]
+ (unit.coverage [/.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 (the /.#successes success_tally))
- (n.= 0 (the /.#failures success_tally)))
- (and (n.= 0 (the /.#successes failure_tally))
- (n.= 1 (the /.#failures failure_tally))))))))
+ (and (n.= 1 (the unit.#successes success_tally))
+ (n.= 0 (the unit.#failures success_tally)))
+ (and (n.= 0 (the unit.#successes failure_tally))
+ (n.= 1 (the unit.#failures failure_tally))))))))
(do !
- [failure_assertion (/.failure expected_message/0)]
+ [failure_unit_test (/.failure expected_message/0)]
(in (do async.monad
- [[failure_tally failure_message] failure_assertion]
- (/.coverage' [/.failure]
+ [[failure_tally failure_message] failure_unit_test]
+ (unit.coverage [/.failure]
(and (text.contains? expected_message/0 failure_message)
- (and (n.= 0 (the /.#successes failure_tally))
- (n.= 1 (the /.#failures failure_tally))))))))
+ (and (n.= 0 (the unit.#successes failure_tally))
+ (n.= 1 (the unit.#failures failure_tally))))))))
(do !
- [success_assertion (/.lifted expected_message/0 (in true))
- failure_assertion (/.lifted expected_message/0 (in false))]
+ [success_unit_test (/.lifted expected_message/0 (in true))
+ failure_unit_test (/.lifted expected_message/0 (in false))]
(in (do async.monad
- [[success_tally success_message] success_assertion
- [failure_tally failure_message] failure_assertion]
- (/.coverage' [/.lifted]
+ [[success_tally success_message] success_unit_test
+ [failure_tally failure_message] failure_unit_test]
+ (unit.coverage [/.lifted]
(and (text.contains? expected_message/0 success_message)
(text.contains? expected_message/0 failure_message)
- (and (n.= 1 (the /.#successes success_tally))
- (n.= 0 (the /.#failures success_tally)))
- (and (n.= 0 (the /.#successes failure_tally))
- (n.= 1 (the /.#failures failure_tally))))))))
+ (and (n.= 1 (the unit.#successes success_tally))
+ (n.= 0 (the unit.#failures success_tally)))
+ (and (n.= 0 (the unit.#successes failure_tally))
+ (n.= 1 (the unit.#failures failure_tally))))))))
..times
..in_parallel
..coverage