Skip to content

Commit

Permalink
Make test suite handle /r in templates.
Browse files Browse the repository at this point in the history
Also make test output much less verbose.
  • Loading branch information
bakpakin committed May 6, 2022
1 parent 52ec1a0 commit 101b836
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 20 deletions.
22 changes: 6 additions & 16 deletions spork/test.janet
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
(var num-tests-passed 0)
(var num-tests-run 0)
(var suite-num 0)
(var numchecks 0)
(var start-time 0)

(defn assert
Expand All @@ -12,17 +11,9 @@
(default e "assert error")
(++ num-tests-run)
(if x (++ num-tests-passed))
(if x
(do
(when (= numchecks 25)
(set numchecks 0)
(print))
(++ numchecks)
(prin "\e[32m✔\e[0m"))
(do
(prin "\n\e[31m✘\e[0m ")
(set numchecks 0)
(print e)))
(unless x
(prin "\e[31m✘\e[0m ")
(print e))
x)

(defn assert-not
Expand All @@ -45,14 +36,13 @@
(defn start-suite [x]
"Starts test suite."
(set suite-num x)
(set start-time (os/clock))
(print "\nRunning test suite " x " tests...\n"))
(set start-time (os/clock)))

(defn end-suite []
"Ends test suite."
(def delta (- (os/clock) start-time))
(printf "\n\nTest suite %d finished in %.3f seconds" suite-num delta)
(print num-tests-passed " of " num-tests-run " tests passed.\n")
(prinf "test suite %d finished in %.3f seconds - " suite-num delta)
(print num-tests-passed " of " num-tests-run " tests passed.")
(if (not= num-tests-passed num-tests-run) (os/exit 1)))

(defmacro timeit
Expand Down
7 changes: 5 additions & 2 deletions test/suite0008.janet
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@

(test/start-suite 8)

(defn- remove-r [x] (string/replace-all "\r" "" x))

(defn check-template
[template args expected]
(def expected (string/trim (remove-r expected)))
(def buf @"")
(with-dyns [:out buf]
(template args))
(def sbuf (string/trim (string buf)))
(test/assert (= sbuf expected) (string "Render of " template)))
(def sbuf (string/trim (remove-r (string buf))))
(test/assert (= sbuf expected) (string/format "template %v - expected %v, got %v" template expected sbuf)))

(import ./templates/hi :as hi)
(import ./templates/hop :as hop)
Expand Down
2 changes: 0 additions & 2 deletions test/suite0010.janet
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,4 @@
(eu/pcall (fn workerf [i] (+= x i)) 10)
(assert (= x 45) "pcall 2")



(end-suite)

0 comments on commit 101b836

Please sign in to comment.