Add proper tests

This commit is contained in:
madmaurice 2021-04-02 16:06:26 +02:00
parent 31bab456b0
commit d35611b813
5 changed files with 47 additions and 19 deletions

3
Makefile Normal file
View file

@ -0,0 +1,3 @@
.PHONY: test
test:
@prove -e $(PWD)/tool/test-runner.pl -v $(PWD)/t/

1
t/bool.t Normal file
View file

@ -0,0 +1 @@
(expect "True is true" t)

2
t/comments.t Normal file
View file

@ -0,0 +1,2 @@
;; This is a comment
(expect "Comment does not influence code" t)

19
test.pl
View file

@ -1,19 +0,0 @@
use lib "./lib";
use Minilisp;
use Data::Dumper;
my $term = <<EOF;
(defun fact (n) (if (> n 1) (* n (fact (- n 1))) 1))
(write-line (fact 5))
EOF
my $parsed = Minilisp::compile($term);
my $ctx = {
'a' => "bar",
};
print "$term\n";
print ":= " . $parsed->($ctx) . "\n";

41
tool/test-runner.pl Executable file
View file

@ -0,0 +1,41 @@
#!/usr/bin/env perl
use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/../lib";
use Minilisp;
my $scriptfile = shift;
die "No script file provided." unless defined $scriptfile && -f $scriptfile;
open(my $fh, "<", $scriptfile) or die "Could not open $scriptfile: $!";
my $script = do { local $/; <$fh> };
close($fh);
# Remove shebang
$script =~ s/^#!.*\n//;
my $parsed = Minilisp::compile($script);
my $plan = 0;
my $ctx = {
'expect' => sub {
my ($desc, $success) = @_;
print "not " unless $success;
print "ok - $desc\n";
$plan++;
}
};
print "TAP Version 13\n";
$parsed->($ctx);
print "1..$plan\n";
exit 0;