diff options
Diffstat (limited to 'stdlib/source/test')
-rw-r--r-- | stdlib/source/test/lux/abstract.lux | 40 | ||||
-rw-r--r-- | stdlib/source/test/lux/abstract/interval.lux | 40 | ||||
-rw-r--r-- | stdlib/source/test/lux/target/python.lux | 53 | ||||
-rw-r--r-- | stdlib/source/test/lux/tool/compiler/meta/cache.lux | 2 | ||||
-rw-r--r-- | stdlib/source/test/lux/tool/compiler/meta/cache/artifact.lux | 53 |
5 files changed, 145 insertions, 43 deletions
diff --git a/stdlib/source/test/lux/abstract.lux b/stdlib/source/test/lux/abstract.lux index ae9d6c593..9d44f0e96 100644 --- a/stdlib/source/test/lux/abstract.lux +++ b/stdlib/source/test/lux/abstract.lux @@ -1,24 +1,24 @@ (.using - [library - [lux "*" - ["_" test {"+" Test}]]] - ["[0]" / "_" - ["[1][0]" apply] - ["[1][0]" codec] - ["[1][0]" comonad - ["[1]/[0]" cofree]] - ["[1][0]" enum] - ["[1][0]" equivalence] - ["[1][0]" hash] - ["[1][0]" mix] - ["[1][0]" functor - ["[1]/[0]" contravariant]] - ["[1][0]" interval] - ["[1][0]" monad - ["[1]/[0]" free]] - ["[1][0]" monoid] - ["[1][0]" order] - ["[1][0]" predicate]]) + [library + [lux "*" + ["_" test {"+" Test}]]] + ["[0]" / "_" + ["[1][0]" apply] + ["[1][0]" codec] + ["[1][0]" comonad + ["[1]/[0]" cofree]] + ["[1][0]" enum] + ["[1][0]" equivalence] + ["[1][0]" hash] + ["[1][0]" mix] + ["[1][0]" functor + ["[1]/[0]" contravariant]] + ["[1][0]" interval] + ["[1][0]" monad + ["[1]/[0]" free]] + ["[1][0]" monoid] + ["[1][0]" order] + ["[1][0]" predicate]]) (def: functor Test diff --git a/stdlib/source/test/lux/abstract/interval.lux b/stdlib/source/test/lux/abstract/interval.lux index bbb5cc045..e4cf534e0 100644 --- a/stdlib/source/test/lux/abstract/interval.lux +++ b/stdlib/source/test/lux/abstract/interval.lux @@ -1,24 +1,24 @@ (.using - [library - [lux "*" - ["_" test {"+" Test}] - [abstract - [monad {"+" do}] - ["[0]" order] - [\\specification - ["$[0]" equivalence]]] - [control - [pipe {"+" case>}]] - [data - [collection - ["[0]" set] - ["[0]" list]]] - [math - ["[0]" random {"+" Random}] - [number - ["n" nat]]]]] - [\\library - ["[0]" / {"+" Interval} ("#[0]" equivalence)]]) + [library + [lux "*" + ["_" test {"+" Test}] + [abstract + [monad {"+" do}] + ["[0]" order] + [\\specification + ["$[0]" equivalence]]] + [control + [pipe {"+" case>}]] + [data + [collection + ["[0]" set] + ["[0]" list]]] + [math + ["[0]" random {"+" Random}] + [number + ["n" nat]]]]] + [\\library + ["[0]" / {"+" Interval} ("#[0]" equivalence)]]) (template [<name> <cmp>] [(def: .public <name> diff --git a/stdlib/source/test/lux/target/python.lux b/stdlib/source/test/lux/target/python.lux index 0d9fb493a..b68adfedd 100644 --- a/stdlib/source/test/lux/target/python.lux +++ b/stdlib/source/test/lux/target/python.lux @@ -1,6 +1,6 @@ (.using [library - [lux {"-" exec} + [lux "*" ["_" test {"+" Test}] ["[0]" ffi] ["[0]" static] @@ -17,7 +17,7 @@ ["[0]" try {"+" Try} ("[1]#[0]" functor)]] [data ["[0]" bit ("[1]#[0]" equivalence)] - ["[0]" text {"+" \n} ("[1]#[0]" equivalence) + ["[0]" text ("[1]#[0]" equivalence) ["%" format {"+" format}]] [collection ["[0]" list ("[1]#[0]" functor)]]] @@ -412,7 +412,7 @@ (let [$output (static.random (|>> %.nat (format "output_") code.text) random.nat) environment (..dict [])] - (.exec + (exec ("python exec" (/.code (it (/.var $output))) (:expected environment)) (Dict::get [$output] environment)))) @@ -533,6 +533,52 @@ ..test|access) ))) +(def: test|exception + Test + (do [! random.monad] + [expected_error (random.ascii/upper 10) + expected random.safe_frac + dummy (random.only (|>> (f.= expected) not) + random.safe_frac) + $ex (# ! each (|>> %.nat (format "ex_") /.var) random.nat)] + ($_ _.and + (_.cover [/.raise /.Exception/1] + (case (try (..statement + (function (_ $output) + ($_ /.then + (/.raise (/.Exception/1 (/.string expected_error))) + (/.set (list $output) (/.float dummy)))))) + {try.#Failure actual_error} + (text#= expected_error actual_error) + + {try.#Success _} + false)) + (_.cover [/.try /.Except] + (and (|> (..statement + (function (_ $output) + (/.try ($_ /.then + (/.raise (/.Exception/1 (/.string expected_error))) + (/.set (list $output) (/.float dummy))) + (list [/.#classes (list "Exception") + /.#exception $ex + /.#handler (/.set (list $output) (/.float expected))])))) + (:as Frac) + (f.= expected)) + (case (try (..statement + (function (_ $output) + (/.try ($_ /.then + (/.raise (/.Exception/1 (/.string expected_error))) + (/.set (list $output) (/.float dummy))) + (list [/.#classes (list) + /.#exception $ex + /.#handler (/.set (list $output) (/.float expected))]))))) + {try.#Failure actual_error} + (text#= expected_error actual_error) + + {try.#Success actual} + false))) + ))) + (def: test|statement Test (do [! random.monad] @@ -587,6 +633,7 @@ (/.set (list $output) (/.apply/* (list) $def))))) (:as Frac) (f.= expected/0))) + ..test|exception (_.for [/.Location] ..test|location) ))) diff --git a/stdlib/source/test/lux/tool/compiler/meta/cache.lux b/stdlib/source/test/lux/tool/compiler/meta/cache.lux index d1c3c9249..a92a50ea7 100644 --- a/stdlib/source/test/lux/tool/compiler/meta/cache.lux +++ b/stdlib/source/test/lux/tool/compiler/meta/cache.lux @@ -16,6 +16,7 @@ ["[0]" /]] ["[0]" / "_" ["[1][0]" module] + ["[1][0]" artifact] ["$/[1]" // "_" ["[1][0]" context]]]) @@ -45,4 +46,5 @@ post/1)))) /module.test + /artifact.test )))) diff --git a/stdlib/source/test/lux/tool/compiler/meta/cache/artifact.lux b/stdlib/source/test/lux/tool/compiler/meta/cache/artifact.lux new file mode 100644 index 000000000..a9140b6a6 --- /dev/null +++ b/stdlib/source/test/lux/tool/compiler/meta/cache/artifact.lux @@ -0,0 +1,53 @@ +(.using + [library + [lux "*" + ["_" test {"+" Test}] + [abstract + [monad {"+" do}]] + [control + ["[0]" try] + [concurrency + ["[0]" async {"+" Async} ("[1]#[0]" monad)]]] + [data + ["[0]" binary ("[1]#[0]" equivalence) + ["$[1]" \\test]]] + [math + ["[0]" random {"+" Random}] + [number + ["n" nat]]] + [world + ["[0]" file]]]] + [\\library + ["[0]" / + ["/[1]" // "_" + ["[1][0]" module]]]] + ["$[0]" /// "_" + ["[1][0]" context]]) + +(def: .public test + Test + (<| (_.covering /._) + (do [! random.monad] + [.let [/ "/" + fs (file.mock /)] + context $///context.random + @module random.nat + @artifact random.nat + expected ($binary.random 1)] + ($_ _.and + (in (do async.monad + [pre (# fs file? (/.path fs context @module @artifact)) + _ (//module.enable! fs context @module) + write! (/.write! fs context @module @artifact expected) + post (# fs file? (/.path fs context @module @artifact)) + read! (/.read! fs context @module @artifact)] + (_.cover' [/.path /.write! /.read!] + (and (not pre) + (case write! + {try.#Success _} true + {try.#Failure _} false) + post + (case read! + {try.#Success actual} (binary#= expected actual) + {try.#Failure _} false))))) + )))) |