This is possible if one uses testament:
With testament the tests are written as:
(import testament :prefix "" :exit true)
(deftest one-plus-one
(is (= 2 (+ 1 1)) "1 + 1 = 2"))
(deftest two-plus-two
(is (= 5 (+ 2 2)) "2 + 2 = 5"))
(deftest test-should-fail
(is (= "hello" "holla") "should fail"))
Each test case is defined as:
(deftest <testname> (is <assertion>) <note>)
Testament allows defining a function which will be called after each test:
(set-on-result-hook reporter)
(run-tests!)
In this case, reporter can be defined as:
(defn reporter
"pretty report"
[result]
(var symbol "\e[31m✕\e[0m")
(if (result :passed?) (set symbol "\e[32m✓\e[0m"))
(print symbol " " (result :note))
)
The result will be:
$ jpm test
running test/test.janet ...
✓ 1 + 1 = 2
✕ should fail
✕ 2 + 2 = 5
> Failed: two-plus-two
Assertion: 2 + 2 = 5
Expect: 5
Actual: 4
> Failed: test-should-fail
Assertion: should fail
Expect: "hello"
Actual: "holla"
-----------------------------------
3 tests run containing 3 assertions
1 tests passed, 2 tests failed
-----------------------------------
In a Linux terminal the x
will be red, and ✓
will be green.
The complete test code:
$ cat test/testam.janet
(import testament :prefix "" :exit true)
(deftest one-plus-one
(is (= 2 (+ 1 1)) "1 + 1 = 2"))
(deftest two-plus-two
(is (= 5 (+ 2 2)) "2 + 2 = 5"))
(deftest test-should-fail
(is (= "hello" "holla") "should fail"))
(defn reporter
"pretty report"
[result]
(var symbol "\e[31m✕\e[0m")
(if (result :passed?) (set symbol "\e[32m✓\e[0m"))
(print symbol " " (result :note))
)
(set-on-result-hook reporter)
(run-tests!)