From 442d1557b879a8a4bd76f441f72a17bfb71cf05f Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sat, 17 Jul 2021 22:48:54 -0400 Subject: Now allowing compilers to generate custom-named outputs. --- stdlib/source/test/aedifex/command/build.lux | 68 ++++++++++++++++++++++ stdlib/source/test/aedifex/dependency.lux | 8 ++- stdlib/source/test/aedifex/dependency/status.lux | 14 +++++ stdlib/source/test/aedifex/profile.lux | 25 +++++--- stdlib/source/test/aedifex/repository/identity.lux | 2 +- stdlib/source/test/aedifex/runtime.lux | 7 ++- stdlib/source/test/lux.lux | 37 +++++++++++- 7 files changed, 150 insertions(+), 11 deletions(-) (limited to 'stdlib/source/test') diff --git a/stdlib/source/test/aedifex/command/build.lux b/stdlib/source/test/aedifex/command/build.lux index 1292c232f..4b0960d32 100644 --- a/stdlib/source/test/aedifex/command/build.lux +++ b/stdlib/source/test/aedifex/command/build.lux @@ -5,6 +5,7 @@ [abstract [monad (#+ do)]] [control + [pipe (#+ case>)] [io (#+ IO)] ["." try] ["." exception] @@ -72,6 +73,38 @@ (def: (on_await state) (#try.Success [state shell.error])))))))) +(def: #export (reader_shell error?) + (-> Bit (-> (List Text) (Shell IO))) + (shell.mock + (function (_ [actual_environment actual_working_directory actual_command actual_arguments]) + (#try.Success + (: (shell.Mock (List Text)) + (implementation + (def: (on_read state) + (if error? + (exception.throw shell.no_more_output []) + (case state + (#.Cons head tail) + (#try.Success [tail head]) + + #.Nil + (exception.throw shell.no_more_output [])))) + (def: (on_error state) + (if error? + (case state + (#.Cons head tail) + (#try.Success [tail head]) + + #.Nil + (exception.throw shell.no_more_output [])) + (exception.throw shell.no_more_output []))) + (def: (on_write input state) + (#try.Failure "on_write")) + (def: (on_destroy state) + (#try.Failure "on_destroy")) + (def: (on_await state) + (#try.Success [state shell.error])))))))) + (def: compiler (Random Dependency) (do random.monad @@ -181,4 +214,39 @@ (text\= /.failure end))))] (_.cover' [/.failure] (try.default false verdict))))) + (do ! + [expected/0 (random.ascii/alpha 5) + expected/1 (random.ascii/alpha 5) + expected/2 (random.ascii/alpha 5)] + (`` ($_ _.and + (~~ (template [ ] + [(let [console (@version.echo "") + shell (|> (list expected/0 expected/1 expected/2) + (..reader_shell ) + shell.async)] + (wrap (do {! promise.monad} + [verdict (do ///action.monad + [process (shell [environment.empty working_directory "" (list "")]) + _ ( console process) + actual/0 (\ console read_line []) + actual/1 (\ console read_line []) + actual/2 (\ console read_line []) + end! (|> (\ console read_line []) + (\ ! map (|>> (case> (#try.Failure error) + true + + (#try.Success _) + false) + #try.Success)))] + (wrap (and (text\= expected/0 actual/0) + (text\= expected/1 actual/1) + (text\= expected/2 actual/2) + end!)))] + (_.cover' [] + (try.default false verdict)))))] + + [#0 /.log_output!] + [#1 /.log_error!] + )) + ))) )))) diff --git a/stdlib/source/test/aedifex/dependency.lux b/stdlib/source/test/aedifex/dependency.lux index 7ce95f716..733e15710 100644 --- a/stdlib/source/test/aedifex/dependency.lux +++ b/stdlib/source/test/aedifex/dependency.lux @@ -5,7 +5,9 @@ [abstract [monad (#+ do)] [\\specification - ["$." equivalence]]] + ["$." equivalence] + ["$." order] + ["$." hash]]] [math ["." random (#+ Random)]]]] [// @@ -26,4 +28,8 @@ ($_ _.and (_.for [/.equivalence] ($equivalence.spec /.equivalence ..random)) + (_.for [/.order] + ($order.spec /.order ..random)) + (_.for [/.hash] + ($hash.spec /.hash ..random)) )))) diff --git a/stdlib/source/test/aedifex/dependency/status.lux b/stdlib/source/test/aedifex/dependency/status.lux index f886c031f..64bb2f642 100644 --- a/stdlib/source/test/aedifex/dependency/status.lux +++ b/stdlib/source/test/aedifex/dependency/status.lux @@ -3,8 +3,12 @@ [lux #* ["_" test (#+ Test)] [abstract + [monad (#+ do)] [\\specification ["$." equivalence]]] + [data + ["." binary #_ + ["#T" \\test]]] [math ["." random (#+ Random) ("#\." monad)]]]] ["$." /// #_ @@ -31,4 +35,14 @@ ($_ _.and (_.for [/.equivalence] ($equivalence.spec /.equivalence ..random)) + + (do random.monad + [payload (binaryT.random 1)] + (_.cover [/.verified] + (case (/.verified payload) + (#/.Verified sha1 md5) + true + + _ + false))) )))) diff --git a/stdlib/source/test/aedifex/profile.lux b/stdlib/source/test/aedifex/profile.lux index c593f1706..7163ac780 100644 --- a/stdlib/source/test/aedifex/profile.lux +++ b/stdlib/source/test/aedifex/profile.lux @@ -14,7 +14,7 @@ [parser ["." cli]]] [data - ["." text] + ["." text ("#\." equivalence)] [collection ["." set (#+ Set)] ["." dictionary (#+ Dictionary)]]] @@ -144,9 +144,20 @@ (_.for [/.Distribution /.License /.SCM /.Organization /.Email /.Developer /.Contributor /.Info /.Source /.Target /.Name /.Profile] - ($_ _.and - (_.for [/.equivalence] - ($equivalence.spec /.equivalence ..random)) - (_.for [/.monoid] - ($monoid.spec /.equivalence /.monoid ..random)) - )))) + (`` ($_ _.and + (_.for [/.equivalence] + ($equivalence.spec /.equivalence ..random)) + (_.for [/.monoid] + ($monoid.spec /.equivalence /.monoid ..random)) + + (_.cover [/.default] + (text\= "" /.default)) + (_.cover [/.default_compiler] + (|> (\ /.monoid identity) + (get@ #/.compiler) + (is? /.default_compiler))) + (_.cover [/.default_target] + (|> (\ /.monoid identity) + (get@ #/.target) + (is? /.default_target))) + ))))) diff --git a/stdlib/source/test/aedifex/repository/identity.lux b/stdlib/source/test/aedifex/repository/identity.lux index 74daecb4d..e19acde36 100644 --- a/stdlib/source/test/aedifex/repository/identity.lux +++ b/stdlib/source/test/aedifex/repository/identity.lux @@ -20,7 +20,7 @@ (def: #export test Test (<| (_.covering /._) - (_.for [/.Identity] + (_.for [/.User /.Password /.Identity] ($_ _.and (_.for [/.equivalence] ($equivalence.spec /.equivalence ..random)) diff --git a/stdlib/source/test/aedifex/runtime.lux b/stdlib/source/test/aedifex/runtime.lux index 24745da4a..7d6d3f98b 100644 --- a/stdlib/source/test/aedifex/runtime.lux +++ b/stdlib/source/test/aedifex/runtime.lux @@ -3,7 +3,9 @@ [lux #* ["_" test (#+ Test)] [abstract - [monad (#+ do)]] + [monad (#+ do)] + [\\specification + ["$." equivalence]]] [data ["." maybe ("#\." functor)] ["." text ("#\." equivalence)] @@ -35,6 +37,9 @@ [path (random.ascii/alpha 5) runtime ..random] (`` ($_ _.and + (_.for [/.equivalence] + ($equivalence.spec /.equivalence ..random)) + (~~ (template [] [(_.cover [/.default_java /.default_js /.default_python /.default_lua /.default_ruby] (let [listing (|> (list /.default_java /.default_js /.default_python /.default_lua /.default_ruby) diff --git a/stdlib/source/test/lux.lux b/stdlib/source/test/lux.lux index 26924ef8e..1e9976f4e 100644 --- a/stdlib/source/test/lux.lux +++ b/stdlib/source/test/lux.lux @@ -19,7 +19,9 @@ [data ["." bit ("#\." equivalence)] ["." text ("#\." equivalence) - ["%" format (#+ format)]]] + ["%" format (#+ format)]] + [collection + ["." list]]] [macro ["." code ("#\." equivalence)]] ["." math @@ -553,6 +555,38 @@ (n.= (n.* (inc expected_left) (dec expected_right)) (actual expected_left expected_right)))))) +(/.template: (!n/+ ) + (n.+ )) + +(def: for_template + Test + (`` ($_ _.and + (_.cover [/.template] + (let [bits (list (~~ (/.template [_] + [true] + + [0] [1] [2] + )))] + (and (n.= 3 (list.size bits)) + (list.every? (bit\= true) bits)))) + (do random.monad + [left random.nat + right random.nat] + (_.cover [/.template:] + (n.= (n.+ left right) + (!n/+ left right)))) + (do {! random.monad} + [sample (\ ! map (n.% 5) random.nat)] + (_.cover [/.^template] + (case sample + (/.^template [] + [ true]) + ([0] [1] [2] [3] [4]) + + _ + false))) + ))) + (def: test Test (<| (_.covering /._) @@ -577,6 +611,7 @@ ..for_type ..for_i64 ..for_function + ..for_template ..sub_tests ))) -- cgit v1.2.3