Add plan to each test

This commit is contained in:
madmaurice 2021-04-09 00:01:27 +02:00
parent 0cbc43927d
commit ba0915f384
21 changed files with 47 additions and 4 deletions

View file

@ -1,3 +1,5 @@
(plan 7)
(let ((a 'ok))
(and nil (set a 'fail))
(expect "and - Short circuit" (equal a 'ok)))

View file

@ -1,3 +1,5 @@
(plan 5)
(expect "block - return last value"
(equal 'top (block nil 'top)))

View file

@ -1,3 +1,5 @@
(plan 12)
;; Constants
(expect "True is true" (eq 1 (if t 1 0)))

View file

@ -1,3 +1,4 @@
(plan 3)
;; This is a comment
(expect "Comment does not influence code" t)
;; Another comment

View file

@ -1,3 +1,5 @@
(plan 1)
(expect "cond"
(equal 'ok
(cond ((> 1 2) 'fail)

View file

@ -1,3 +1,5 @@
(plan 3)
(let ((a 2))
(let ((a 10))
(expect "Inner variable shadows outer" (= a 10)))

2
t/do.t
View file

@ -1,3 +1,5 @@
(plan 3)
(expect "do - simple example"
(equal (do ((n 1)) (t n)) 1))

View file

@ -1,3 +1,5 @@
(plan 1)
(defun range (start end)
(do ((lst (list) (cons i lst)) (i start (+ 1 i))) ((= i end) lst)))

View file

@ -1,3 +1,5 @@
(plan 1)
(let ((result
(do ((a 1 b) (b 2 (+ a b)) (sum 0)) ((> b 4000000) sum)
(when (evenp b)

View file

@ -1,3 +1,5 @@
(plan 5)
(defun inc (a) (+ a 1))
(expect "inc 5 == 6" (eq (inc 5) 6))

View file

@ -1,3 +1,5 @@
(plan 3)
(let ((a 'a)
(b 'b))
(expect "equal to itself" (equal a a))

View file

@ -1,3 +1,5 @@
(plan 4)
(let ((a 5) (b 6))
(expect "a is 5" (= a 5))
(expect "b is 6" (= b 6))

View file

@ -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))

View file

@ -1,3 +1,5 @@
(plan 1)
(expect "loop"
(equal (let ((i 0))
(loop (set i (+ i 1))

View file

@ -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))

View file

@ -1,3 +1,5 @@
(plan 2)
;; Factorial
(defun factorial (n)

View file

@ -1,3 +1,5 @@
(plan 4)
(expect "length of string" (= (length "hello") 5))
(expect "string-upcase" (string= (string-upcase "helLo") "HELLO"))

View file

@ -1,3 +1,5 @@
(plan 5)
(expect "catch - without throw"
(equal 'ok
(catch 'exc1

View file

@ -1,3 +1,5 @@
(plan 5)
(expect "unless - true condition"
(null (unless t 'fail)))

View file

@ -1,3 +1,5 @@
(plan 5)
(expect "when - true condition"
(equal 'ok (when t 'ok)))

View file

@ -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;