diff options
-rw-r--r-- | stdlib/source/lux/test.lux | 2 | ||||
-rw-r--r-- | stdlib/test/test/lux.lux | 13 | ||||
-rw-r--r-- | stdlib/test/test/lux/cli.lux | 109 | ||||
-rw-r--r-- | stdlib/test/test/lux/host.jvm.lux | 133 | ||||
-rw-r--r-- | stdlib/test/test/lux/host/jvm.jvm.lux | 51 | ||||
-rw-r--r-- | stdlib/test/tests.lux | 9 |
6 files changed, 164 insertions, 153 deletions
diff --git a/stdlib/source/lux/test.lux b/stdlib/source/lux/test.lux index f0ab87249..a96af556b 100644 --- a/stdlib/source/lux/test.lux +++ b/stdlib/source/lux/test.lux @@ -67,7 +67,7 @@ (text.join-with ..separator) (format description ..separator))])))) -(def: failure-prefix " [Error] ") +(def: failure-prefix "[Failure] ") (def: success-prefix "[Success] ") (def: #export fail diff --git a/stdlib/test/test/lux.lux b/stdlib/test/test/lux.lux index 0ed5cbc2a..4be4b753b 100644 --- a/stdlib/test/test/lux.lux +++ b/stdlib/test/test/lux.lux @@ -9,7 +9,11 @@ ["." i64]]] ["." math ["r" random (#+ Random) ("r/." Functor<Random>)]] - ["_" test (#+ Test)]]) + ["_" test (#+ Test)]] + [/ + ["/." cli] + ["/." host + ["/." jvm]]]) (def: identity Test @@ -237,4 +241,11 @@ ..template) (<| (_.context "Cross-platform support.") ..cross-platform-support) + (<| (_.context "/cli") + /cli.test) + (<| (_.context "/host") + ($_ _.and + /host.test + (<| (_.context "/jvm") + /jvm.test))) )) diff --git a/stdlib/test/test/lux/cli.lux b/stdlib/test/test/lux/cli.lux index 12e0b7361..bf7bc72a7 100644 --- a/stdlib/test/test/lux/cli.lux +++ b/stdlib/test/test/lux/cli.lux @@ -13,61 +13,62 @@ ["." list]]] [math ["r" random]] - ["/" cli]] - lux/test) + ["/" cli] + ["_" test (#+ Test)]]) -(context: "CLI" - (<| (times 100) - (do @ - [num-args (|> r.nat (:: @ map (n/% 10))) - #let [(^open "Nat/.") number.Codec<Text,Nat> - gen-arg (:: @ map Nat/encode r.nat)] - yes gen-arg - #let [gen-ignore (|> (r.unicode 5) (r.filter (|>> (text/= yes) not)))] - no gen-ignore - pre-ignore (r.list 5 gen-ignore) - post-ignore (r.list 5 gen-ignore)] - ($_ seq - (test "Can read any argument." - (|> (/.run (list yes) /.any) - (case> (#error.Failure _) - #0 - - (#error.Success arg) - (text/= arg yes)))) - (test "Can test tokens." - (and (|> (/.run (list yes) (/.this yes)) - (case> (#error.Failure _) - #0 +(def: #export test + Test + (do r.Monad<Random> + [num-args (|> r.nat (:: @ map (n/% 10))) + #let [(^open "Nat/.") number.Codec<Text,Nat> + gen-arg (:: @ map Nat/encode r.nat)] + yes gen-arg + #let [gen-ignore (r.filter (|>> (text/= yes) not) + (r.unicode 5))] + no gen-ignore + pre-ignore (r.list 5 gen-ignore) + post-ignore (r.list 5 gen-ignore)] + ($_ _.and + (_.test "Can read any argument." + (|> (/.run (list yes) /.any) + (case> (#error.Failure _) + #0 + + (#error.Success arg) + (text/= arg yes)))) + (_.test "Can test tokens." + (and (|> (/.run (list yes) (/.this yes)) + (case> (#error.Failure _) + #0 - (#error.Success _) - #1)) - (|> (/.run (list no) (/.this yes)) - (case> (#error.Failure _) - #1 + (#error.Success _) + #1)) + (|> (/.run (list no) (/.this yes)) + (case> (#error.Failure _) + #1 - (#error.Success _) - #0)))) - (test "Can use custom token parsers." - (|> (/.run (list yes) (/.parse Nat/decode)) - (case> (#error.Failure _) - #0 - - (#error.Success parsed) - (text/= (Nat/encode parsed) - yes)))) - (test "Can query if there are any more inputs." - (and (|> (/.run (list) /.end) - (case> (#error.Success []) #1 _ #0)) - (|> (/.run (list yes) (p.not /.end)) - (case> (#error.Success []) #0 _ #1)))) - (test "Can parse CLI input anywhere." - (|> (/.run (list.concat (list pre-ignore (list yes) post-ignore)) - (|> (/.somewhere (/.this yes)) - (p.before (p.some /.any)))) - (case> (#error.Failure _) - #0 + (#error.Success _) + #0)))) + (_.test "Can use custom token parsers." + (|> (/.run (list yes) (/.parse Nat/decode)) + (case> (#error.Failure _) + #0 + + (#error.Success parsed) + (text/= (Nat/encode parsed) + yes)))) + (_.test "Can query if there are any more inputs." + (and (|> (/.run (list) /.end) + (case> (#error.Success []) #1 _ #0)) + (|> (/.run (list yes) (p.not /.end)) + (case> (#error.Success []) #0 _ #1)))) + (_.test "Can parse CLI input anywhere." + (|> (/.run (list.concat (list pre-ignore (list yes) post-ignore)) + (|> (/.somewhere (/.this yes)) + (p.before (p.some /.any)))) + (case> (#error.Failure _) + #0 - (#error.Success _) - #1))) - )))) + (#error.Success _) + #1))) + ))) diff --git a/stdlib/test/test/lux/host.jvm.lux b/stdlib/test/test/lux/host.jvm.lux index caa943771..c3dcf6791 100644 --- a/stdlib/test/test/lux/host.jvm.lux +++ b/stdlib/test/test/lux/host.jvm.lux @@ -1,14 +1,14 @@ (.module: [lux #* [control - [monad (#+ do Monad)] + [monad (#+ Monad do)] pipe] [data [text ("text/." Equivalence<Text>)]] ["&" host (#+ import: class: interface: object)] [math - ["r" random]]] - lux/test) + ["r" random]] + ["_" test (#+ Test)]]) (import: (java/util/concurrent/Callable a)) @@ -58,66 +58,71 @@ (interface: TestInterface ([] foo [boolean String] void #throws [Exception])) -(context: "Conversions" - (<| (times 100) - (do @ - [sample r.int] - (with-expansions - [<int-convs> (do-template [<to> <from> <message>] - [(test <message> - (or (|> sample <to> <from> (i/= sample)) - (let [capped-sample (|> sample <to> <from>)] - (|> capped-sample <to> <from> (i/= capped-sample)))))] - - [&.long-to-byte &.byte-to-long "Can succesfully convert to/from byte."] - [&.long-to-short &.short-to-long "Can succesfully convert to/from short."] - [&.long-to-int &.int-to-long "Can succesfully convert to/from int."] - [&.long-to-float &.float-to-long "Can succesfully convert to/from float."] - [&.long-to-double &.double-to-long "Can succesfully convert to/from double."] - [(<| &.int-to-char &.long-to-int) (<| &.int-to-long &.char-to-int) "Can succesfully convert to/from char."] - )] - ($_ seq - <int-convs> - ))))) - -(context: "Miscellaneous" - ($_ seq - (test "Can check if an object is of a certain class." - (and (case (&.check String "") (#.Some _) true #.None false) - (case (&.check Long "") (#.Some _) false #.None true) - (case (&.check Object "") (#.Some _) true #.None false) - (case (&.check Object (&.null)) (#.Some _) false #.None true))) - - (test "Can run code in a 'synchronized' block." - (&.synchronized "" #1)) - - (test "Can access Class instances." - (text/= "java.lang.Class" (Class::getName (&.class-for java/lang/Class)))) - - (test "Can check if a value is null." - (and (&.null? (&.null)) - (not (&.null? "")))) - - (test "Can safely convert nullable references into Maybe values." - (and (|> (: (Maybe Object) (&.??? (&.null))) - (case> #.None #1 - _ #0)) - (|> (: (Maybe Object) (&.??? "")) - (case> (#.Some _) #1 - _ #0)))) +(def: conversions Test + (do r.Monad<Random> + [sample r.int] + (`` ($_ _.and + (~~ (do-template [<to> <from> <message>] + [(_.test <message> + (or (|> sample <to> <from> (i/= sample)) + (let [capped-sample (|> sample <to> <from>)] + (|> capped-sample <to> <from> (i/= capped-sample)))))] + + [&.long-to-byte &.byte-to-long "Can succesfully convert to/from byte."] + [&.long-to-short &.short-to-long "Can succesfully convert to/from short."] + [&.long-to-int &.int-to-long "Can succesfully convert to/from int."] + [&.long-to-float &.float-to-long "Can succesfully convert to/from float."] + [&.long-to-double &.double-to-long "Can succesfully convert to/from double."] + [(<| &.int-to-char &.long-to-int) (<| &.int-to-long &.char-to-int) "Can succesfully convert to/from char."] + )) + )))) + +(def: miscellaneous Test + ($_ _.and + (_.test "Can check if an object is of a certain class." + (and (case (&.check String "") (#.Some _) true #.None false) + (case (&.check Long "") (#.Some _) false #.None true) + (case (&.check Object "") (#.Some _) true #.None false) + (case (&.check Object (&.null)) (#.Some _) false #.None true))) + + (_.test "Can run code in a 'synchronized' block." + (&.synchronized "" #1)) + + (_.test "Can access Class instances." + (text/= "java.lang.Class" (Class::getName (&.class-for java/lang/Class)))) + + (_.test "Can check if a value is null." + (and (&.null? (&.null)) + (not (&.null? "")))) + + (_.test "Can safely convert nullable references into Maybe values." + (and (|> (: (Maybe Object) (&.??? (&.null))) + (case> #.None #1 + _ #0)) + (|> (: (Maybe Object) (&.??? "")) + (case> (#.Some _) #1 + _ #0)))) )) -(context: "Arrays" - (<| (times 100) - (do @ - [size (|> r.nat (:: @ map (|>> (n/% 100) (n/max 1)))) - idx (|> r.nat (:: @ map (n/% size))) - value r.int] - ($_ seq - (test "Can create arrays of some length." - (n/= size (&.array-length (&.array Long size)))) - - (test "Can set and get array values." - (let [arr (&.array Long size)] - (exec (&.array-write idx value arr) - (i/= value (&.array-read idx arr))))))))) +(def: arrays Test + (do r.Monad<Random> + [size (|> r.nat (:: @ map (|>> (n/% 100) (n/max 1)))) + idx (|> r.nat (:: @ map (n/% size))) + value r.int] + ($_ _.and + (_.test "Can create arrays of some length." + (n/= size (&.array-length (&.array Long size)))) + + (_.test "Can set and get array values." + (let [arr (&.array Long size)] + (exec (&.array-write idx value arr) + (i/= value (&.array-read idx arr)))))))) + +(def: #export test + ($_ _.and + (<| (_.context "Conversions.") + ..conversions) + (<| (_.context "Miscellaneous.") + ..miscellaneous) + (<| (_.context "Arrays.") + ..arrays))) diff --git a/stdlib/test/test/lux/host/jvm.jvm.lux b/stdlib/test/test/lux/host/jvm.jvm.lux index b293c811f..caa3efd1f 100644 --- a/stdlib/test/test/lux/host/jvm.jvm.lux +++ b/stdlib/test/test/lux/host/jvm.jvm.lux @@ -28,10 +28,10 @@ [modifier ["/.M" inner]]]] [math - ["r" random]]] - lux/test) + ["r" random]] + ["_" test (#+ Test)]]) -(def: (write-class name bytecode) +(def: (write-class! name bytecode) (-> Text Binary (IO Text)) (let [file-path (format name ".class")] (do io.Monad<IO> @@ -44,11 +44,9 @@ (format "Wrote: " (%t file-path)) (#error.Failure error) - ## TODO: Remove 'log!' call. - (exec (log! error) - error)))))) + error))))) -(context: "Class" +(def: class Test (let [package "my.package" name "MyClass" full-name (format package "." name) @@ -63,23 +61,24 @@ (row.row)) bytecode (binary.write /class.format input) loader (/loader.memory (/loader.new-library []))] - ($_ seq - (test "Can read a generated class." - (case (binary.read /class.format bytecode) - (#error.Success output) - (:: /class.Equivalence<Class> = input output) - - (#error.Failure error) - ## TODO: Remove 'log!' call. - (exec (log! error) - false))) - (test "Can generate a class." - (case (/loader.define full-name bytecode loader) - (#error.Success definition) - true - - (#error.Failure error) - ## TODO: Remove 'log!' call. - (exec (log! error) - false))) + ($_ _.and + (_.test "Can read a generated class." + (case (binary.read /class.format bytecode) + (#error.Success output) + (:: /class.Equivalence<Class> = input output) + + (#error.Failure error) + false)) + (_.test "Can generate a class." + (case (/loader.define full-name bytecode loader) + (#error.Success definition) + true + + (#error.Failure error) + false)) ))) + +(def: #export test + Test + (<| (_.context "Class") + ..class)) diff --git a/stdlib/test/tests.lux b/stdlib/test/tests.lux index 738ef182b..5c7838634 100644 --- a/stdlib/test/tests.lux +++ b/stdlib/test/tests.lux @@ -83,10 +83,6 @@ ## TODO: Must have 100% coverage on tests. [test ["/." lux - ## [cli (#+)] - ## [host (#+)] - ## [host - ## [jvm (#+)]] ## [io (#+)] ## [time ## [instant (#+)] @@ -196,6 +192,5 @@ ) (program: args - (exec (_.run! (<| (_.times 100) - /lux.test)) - (io []))) + (io (_.run! (<| (_.times 100) + /lux.test)))) |