From ba0915f384b0ba2d5f92e2c812f951167874c02c Mon Sep 17 00:00:00 2001 From: MadMaurice Date: Fri, 9 Apr 2021 00:01:27 +0200 Subject: [PATCH] Add plan to each test --- t/and_or.t | 2 ++ t/block.t | 2 ++ t/bool.t | 2 ++ t/comments.t | 1 + t/cond.t | 2 ++ t/context.t | 2 ++ t/do.t | 2 ++ t/euler1.t | 2 ++ t/euler2.t | 2 ++ t/function.t | 2 ++ t/keyword.t | 2 ++ t/let.t | 2 ++ t/lists.t | 2 ++ t/loop.t | 2 ++ t/math.t | 2 ++ t/recursion.t | 2 ++ t/strings.t | 2 ++ t/throw_catch.t | 2 ++ t/unless.t | 2 ++ t/when.t | 2 ++ tool/test-runner.pl | 12 ++++++++---- 21 files changed, 47 insertions(+), 4 deletions(-) diff --git a/t/and_or.t b/t/and_or.t index 6b13400..c1349a8 100644 --- a/t/and_or.t +++ b/t/and_or.t @@ -1,3 +1,5 @@ +(plan 7) + (let ((a 'ok)) (and nil (set a 'fail)) (expect "and - Short circuit" (equal a 'ok))) diff --git a/t/block.t b/t/block.t index df6eb5c..b9ed159 100644 --- a/t/block.t +++ b/t/block.t @@ -1,3 +1,5 @@ +(plan 5) + (expect "block - return last value" (equal 'top (block nil 'top))) diff --git a/t/bool.t b/t/bool.t index d81b662..7b92627 100644 --- a/t/bool.t +++ b/t/bool.t @@ -1,3 +1,5 @@ +(plan 12) + ;; Constants (expect "True is true" (eq 1 (if t 1 0))) diff --git a/t/comments.t b/t/comments.t index 804cc3b..08d8803 100644 --- a/t/comments.t +++ b/t/comments.t @@ -1,3 +1,4 @@ +(plan 3) ;; This is a comment (expect "Comment does not influence code" t) ;; Another comment diff --git a/t/cond.t b/t/cond.t index 107dac1..58d67f9 100644 --- a/t/cond.t +++ b/t/cond.t @@ -1,3 +1,5 @@ +(plan 1) + (expect "cond" (equal 'ok (cond ((> 1 2) 'fail) diff --git a/t/context.t b/t/context.t index e563538..d5f0816 100644 --- a/t/context.t +++ b/t/context.t @@ -1,3 +1,5 @@ +(plan 3) + (let ((a 2)) (let ((a 10)) (expect "Inner variable shadows outer" (= a 10))) diff --git a/t/do.t b/t/do.t index 58d2093..c09bd9f 100644 --- a/t/do.t +++ b/t/do.t @@ -1,3 +1,5 @@ +(plan 3) + (expect "do - simple example" (equal (do ((n 1)) (t n)) 1)) diff --git a/t/euler1.t b/t/euler1.t index cefd969..d1aa872 100644 --- a/t/euler1.t +++ b/t/euler1.t @@ -1,3 +1,5 @@ +(plan 1) + (defun range (start end) (do ((lst (list) (cons i lst)) (i start (+ 1 i))) ((= i end) lst))) diff --git a/t/euler2.t b/t/euler2.t index 67d4bd2..47496a3 100644 --- a/t/euler2.t +++ b/t/euler2.t @@ -1,3 +1,5 @@ +(plan 1) + (let ((result (do ((a 1 b) (b 2 (+ a b)) (sum 0)) ((> b 4000000) sum) (when (evenp b) diff --git a/t/function.t b/t/function.t index 9786328..6676659 100644 --- a/t/function.t +++ b/t/function.t @@ -1,3 +1,5 @@ +(plan 5) + (defun inc (a) (+ a 1)) (expect "inc 5 == 6" (eq (inc 5) 6)) diff --git a/t/keyword.t b/t/keyword.t index 7fdb35c..00774dc 100644 --- a/t/keyword.t +++ b/t/keyword.t @@ -1,3 +1,5 @@ +(plan 3) + (let ((a 'a) (b 'b)) (expect "equal to itself" (equal a a)) diff --git a/t/let.t b/t/let.t index 26d8486..dfe32e5 100644 --- a/t/let.t +++ b/t/let.t @@ -1,3 +1,5 @@ +(plan 4) + (let ((a 5) (b 6)) (expect "a is 5" (= a 5)) (expect "b is 6" (= b 6)) diff --git a/t/lists.t b/t/lists.t index 3c5fb6d..a643ff6 100644 --- a/t/lists.t +++ b/t/lists.t @@ -1,3 +1,5 @@ +(plan 18) + (let ((lst (list 1 2 3))) (write "# lst = ") (write-line lst) (expect "Length of list is 3" (= (length lst) 3)) diff --git a/t/loop.t b/t/loop.t index 76149bd..52ad66d 100644 --- a/t/loop.t +++ b/t/loop.t @@ -1,3 +1,5 @@ +(plan 1) + (expect "loop" (equal (let ((i 0)) (loop (set i (+ i 1)) diff --git a/t/math.t b/t/math.t index 0f73f3d..e7eef52 100644 --- a/t/math.t +++ b/t/math.t @@ -1,3 +1,5 @@ +(plan 16) + (expect "+ - 3 parameters" (= (+ 2 4 2) 8)) (expect "- - 3 parameters" (= (- 8 2 3) 3)) (expect "* - 2 parameters" (= (* 5 6) 30)) diff --git a/t/recursion.t b/t/recursion.t index 0c5838c..071837e 100644 --- a/t/recursion.t +++ b/t/recursion.t @@ -1,3 +1,5 @@ +(plan 2) + ;; Factorial (defun factorial (n) diff --git a/t/strings.t b/t/strings.t index 9dbfdb7..9533044 100644 --- a/t/strings.t +++ b/t/strings.t @@ -1,3 +1,5 @@ +(plan 4) + (expect "length of string" (= (length "hello") 5)) (expect "string-upcase" (string= (string-upcase "helLo") "HELLO")) diff --git a/t/throw_catch.t b/t/throw_catch.t index 84de627..7cbec93 100644 --- a/t/throw_catch.t +++ b/t/throw_catch.t @@ -1,3 +1,5 @@ +(plan 5) + (expect "catch - without throw" (equal 'ok (catch 'exc1 diff --git a/t/unless.t b/t/unless.t index c06d5b5..9107afd 100644 --- a/t/unless.t +++ b/t/unless.t @@ -1,3 +1,5 @@ +(plan 5) + (expect "unless - true condition" (null (unless t 'fail))) diff --git a/t/when.t b/t/when.t index 036dc7c..7b902c8 100644 --- a/t/when.t +++ b/t/when.t @@ -1,3 +1,5 @@ +(plan 5) + (expect "when - true condition" (equal 'ok (when t 'ok))) diff --git a/tool/test-runner.pl b/tool/test-runner.pl index 7ccd801..4744f32 100755 --- a/tool/test-runner.pl +++ b/tool/test-runner.pl @@ -15,25 +15,29 @@ die "No script file provided." unless defined $scriptfile && -f $scriptfile; my $parsed = Minilisp::compile_file($scriptfile); -my $plan = 0; +my $expected_plan; my $ctx = { 'expect' => sub { my ($desc, $success) = @_; print "not " unless $success; print "ok - $desc\n"; - $plan++; }, comment => sub { my ($v) = @_; print "# " . Minilisp::lisp_format($v) . "\n"; }, + plan => sub { + die "Multiple plans" if defined $expected_plan; + $expected_plan = shift; + } }; print "TAP Version 13\n"; $parsed->($ctx); -die "No tests" unless $plan > 0; -print "1..$plan\n"; +die "No plan" unless defined $expected_plan; + +print "1..$expected_plan\n"; exit 0;