Created
May 25, 2020 19:28
-
-
Save roobie/b47b997bd1178ff4a50509efa174622e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(import ./testament/src/testament :as t) | |
(comment ``` | |
this code is a crude implementation of a TAP style renderer. | |
I've tried a couple of formatters found here https://www.npmjs.com/package/tape#pretty-reporters, | |
Some of which work pretty good, whereas others are a bit weird.```) | |
(def space " ") | |
(def indent " ") | |
(var counter 0) | |
(var failcounter 0) | |
# Here, we're simply printing to stdout, but we could theoretically write to a websocket or do other crazy stuff. | |
(t/set-on-result-hook | |
(fn [{:passed? passed? | |
:kind kind | |
:expect expect | |
:actual actual | |
:note note}] | |
(let [stack-frames (debug/stack (fiber/current)) | |
stack-frame (in stack-frames 3)] # crude guess, really. Perhaps we should walk the stack until the first non-library source file name? | |
(if passed? | |
(print (string "ok" space (inc counter) space note)) | |
(do | |
(++ failcounter) | |
(printf "not ok %d %s\n%s" | |
(inc counter) | |
(string "in" | |
space (stack-frame :source) | |
space "col" space (stack-frame :source-column) | |
space "line" space (stack-frame :source-line) | |
) | |
(string | |
indent "---\n" | |
indent "Expected:" space expect "\n" | |
indent "Actual:" space actual "\n" | |
indent "..." "\n" | |
"\n")))) | |
(++ counter)))) | |
(defn rand-no [] | |
(if (< (math/random) 0.1) 0 1)) | |
(t/deftest test-name (t/is (= 1 1) "hello there")) | |
(t/deftest test-name (t/is (= (rand-no) (rand-no)))) | |
(t/deftest test-name (t/is (= (rand-no) (rand-no)))) | |
(t/deftest test-name (t/is (= (rand-no) (rand-no)))) | |
(t/deftest test-name (t/is (= (rand-no) (rand-no)))) | |
(t/deftest test-name (t/is (= (rand-no) (rand-no)))) | |
(t/deftest test-name (t/is (= (rand-no) (rand-no)) "My note")) | |
(t/deftest test-name (t/is (= (rand-no) (rand-no)))) | |
(t/deftest test-name (t/is (= (rand-no) (rand-no)))) | |
(t/deftest test-name (t/is (= (rand-no) (rand-no)))) | |
(t/deftest test-name (t/is (= (rand-no) (rand-no)))) | |
(t/deftest test-name (t/is (= (rand-no) (rand-no)))) | |
(t/deftest test-name (t/is (= (rand-no) (rand-no)))) | |
# Start by printing the header | |
(print "TAP version 13") | |
# Each test prints results when they're available | |
(t/run-tests! :silent true :exit-on-fail false) | |
(print) # make some space for the outro | |
# Lastly, we print the summary | |
(print (string "1.." counter)) | |
(print (string "# tests" space counter)) | |
(print (string "# passed" space (- counter failcounter))) | |
(print (string "# fail" space failcounter)) | |
(print) | |
(when (= 0 failcounter) | |
(print "# ok")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment