From d35611b8135db257a1a7f40deead4c747a26dd59 Mon Sep 17 00:00:00 2001 From: MadMaurice Date: Fri, 2 Apr 2021 16:06:26 +0200 Subject: [PATCH] Add proper tests --- Makefile | 3 +++ t/bool.t | 1 + t/comments.t | 2 ++ test.pl | 19 ------------------- tool/test-runner.pl | 41 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 47 insertions(+), 19 deletions(-) create mode 100644 Makefile create mode 100644 t/bool.t create mode 100644 t/comments.t delete mode 100644 test.pl create mode 100755 tool/test-runner.pl diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..d5f2d1d --- /dev/null +++ b/Makefile @@ -0,0 +1,3 @@ +.PHONY: test +test: + @prove -e $(PWD)/tool/test-runner.pl -v $(PWD)/t/ diff --git a/t/bool.t b/t/bool.t new file mode 100644 index 0000000..4b0714c --- /dev/null +++ b/t/bool.t @@ -0,0 +1 @@ +(expect "True is true" t) diff --git a/t/comments.t b/t/comments.t new file mode 100644 index 0000000..77061f9 --- /dev/null +++ b/t/comments.t @@ -0,0 +1,2 @@ +;; This is a comment +(expect "Comment does not influence code" t) diff --git a/test.pl b/test.pl deleted file mode 100644 index 15b330a..0000000 --- a/test.pl +++ /dev/null @@ -1,19 +0,0 @@ -use lib "./lib"; - -use Minilisp; -use Data::Dumper; - -my $term = < 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"; diff --git a/tool/test-runner.pl b/tool/test-runner.pl new file mode 100755 index 0000000..1516ee0 --- /dev/null +++ b/tool/test-runner.pl @@ -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;