lux/test

Tools for unit & property-based/generative testing.

Types

Seed

The seed value used for random testing (if that feature is used).

(type: Seed
  lux;Nat)

Test

Tests are asynchronous process which may fail.

(type: Test
  (lux/concurrency/promise;Promise (lux/data/error;Error lux;Unit)))

Macros

run

## Runs all the tests defined on the current module, and in all imported modules.
(run)

test:

## Macro for definint tests.
(test: "Simple macros and constructs"
  ($_ seq
      (assert "Can write easy loops for iterative programming."
              (i.= 1000
                   (loop [counter 0
                          value 1]
                     (if (i.< 3 counter)
                       (recur (i.inc counter) (i.* 10 value))
                       value))))

      (assert "Can create lists easily through macros."
              (and (case (list 1 2 3)
                     (#lux;Cons1 (#lux;Cons2 (#lux;Cons3 #lux;Nil)))
                     true

                     _
                     false)

                   (case (list& 1 2 3 (list 4 5 6))
                     (#lux;Cons1 (#lux;Cons2 (#lux;Cons3 (#lux;Cons4 (#lux;Cons5 (#lux;Cons6 #lux;Nil))))))
                     true

                     _
                     false)))

      (assert "Can have defaults for Maybe values."
              (and (is "yolo" (default "yolo"
                                #lux;None))

                   (is "lol" (default "yolo"
                               (#lux;Some"lol")))))))

## Also works with random generation of values for property-based testing.
(test: "Addition & Substraction"
  [x (:: @ map <prep> rand-gen)
   y (:: @ map <prep> rand-gen)]
  (assert ""
          (and (|> x (- y) (+ y) (= x))
               (|> x (+ y) (- y) (= x)))))

## By default, random tests will be tried 100 times, you can specify the amount you want:
(test: "Addition & Substraction"
  #times +1234
  [x (:: @ map <prep> rand-gen)
   y (:: @ map <prep> rand-gen)]
  (assert ""
          (and (|> x (- y) (+ y) (= x))
               (|> x (+ y) (- y) (= x)))))

## If a test fails, you'll be shown a seed that you can then use to reproduce a failing scenario.
(test: "Addition & Substraction"
  #seed +987654321
  [x (:: @ map <prep> rand-gen)
   y (:: @ map <prep> rand-gen)]
  (assert ""
          (and (|> x (- y) (+ y) (= x))
               (|> x (+ y) (- y) (= x)))))

Values

(alt left right)

Alternative combinator.

(-> Test Test Test)

(assert message condition)

Check that a condition is true, and fail with the given message otherwise.

(-> lux;Text lux;Bool Test)

(fail message)

(All [a] (-> lux;Text Test))

(seq left right)

Sequencing combinator.

(-> Test Test Test)