mirror of
https://github.com/janet-lang/janet
synced 2024-12-29 09:50:27 +00:00
Clean up testing code a little bit.
This commit is contained in:
parent
6ace978ab8
commit
db046fa8bb
23
test/helper.dst
Normal file
23
test/helper.dst
Normal file
@ -0,0 +1,23 @@
|
||||
# Helper code for running tests
|
||||
|
||||
(var num-tests-passed 0)
|
||||
(var num-tests-run 0)
|
||||
(var suite-num 0)
|
||||
|
||||
(defn assert [x e]
|
||||
(++ num-tests-run)
|
||||
(when x (++ num-tests-passed))
|
||||
(print (if x
|
||||
" \e[32m✔\e[0m "
|
||||
" \e[31m✘\e[0m ") e)
|
||||
x)
|
||||
|
||||
(defn start-suite [x]
|
||||
(:= suite-num x)
|
||||
(print "\nRunning test suite " x " tests...\n"))
|
||||
|
||||
(defn end-suite []
|
||||
(print "\nTest suite " suite-num " finished.")
|
||||
(print num-tests-passed " of " num-tests-run " tests passed.\n")
|
||||
(if (not= num-tests-passed num-tests-run) (exit 1)))
|
||||
|
@ -18,20 +18,8 @@
|
||||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
# IN THE SOFTWARE.
|
||||
|
||||
(print "\nRunning Suite 0 tests...\n")
|
||||
|
||||
(var num-tests-passed 0)
|
||||
(var num-tests-run 0)
|
||||
(def assert (fn [x e]
|
||||
(:= num-tests-run (+ 1 num-tests-run))
|
||||
(if x
|
||||
(do
|
||||
(print " \e[32m✔\e[0m " e)
|
||||
(:= num-tests-passed (+ 1 num-tests-passed))
|
||||
x)
|
||||
(do
|
||||
(print " \e[31m✘\e[0m " e)
|
||||
x))))
|
||||
(import "test/helper.dst")
|
||||
(start-suite 0)
|
||||
|
||||
(assert (= 10 (+ 1 2 3 4)) "addition")
|
||||
(assert (= -8 (- 1 2 3 4)) "subtraction")
|
||||
@ -283,8 +271,5 @@
|
||||
(++ i))
|
||||
(assert (= i 6) "when macro"))
|
||||
|
||||
(end-suite)
|
||||
|
||||
# report
|
||||
|
||||
(print "\n" num-tests-passed " of " num-tests-run " tests passed\n")
|
||||
(if (not= num-tests-passed num-tests-run) (exit 1))
|
||||
|
@ -18,20 +18,8 @@
|
||||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
# IN THE SOFTWARE.
|
||||
|
||||
(print "\nRunning Suite 1 Tests...\n")
|
||||
|
||||
(var num-tests-passed 0)
|
||||
(var num-tests-run 0)
|
||||
(def assert (fn [x e]
|
||||
(:= num-tests-run (+ 1 num-tests-run))
|
||||
(if x
|
||||
(do
|
||||
(print " \e[32m✔\e[0m " e)
|
||||
(:= num-tests-passed (+ 1 num-tests-passed))
|
||||
x)
|
||||
(do
|
||||
(print " \e[31m✘\e[0m " e)
|
||||
x))))
|
||||
(import "test/helper.dst")
|
||||
(start-suite 1)
|
||||
|
||||
(assert (= 400.0 (sqrt 160000)) "sqrt(160000)=400")
|
||||
(assert (= (real 400) (sqrt 160000)) "sqrt(160000)=400")
|
||||
@ -52,5 +40,4 @@
|
||||
(assert (= (myfun true) 8) "check do form regression")
|
||||
(assert (= (myfun false) 9) "check do form regression")
|
||||
|
||||
(print "\n" num-tests-passed " of " num-tests-run " tests passed\n")
|
||||
(if (not= num-tests-passed num-tests-run) (exit 1))
|
||||
(end-suite)
|
||||
|
Loading…
Reference in New Issue
Block a user