Skip to content

Commit

Permalink
Can now test for parser/validator/runtime errors
Browse files Browse the repository at this point in the history
  • Loading branch information
pragma- committed Dec 31, 2021
1 parent 521c18b commit 5216d27
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
26 changes: 23 additions & 3 deletions bin/runtests
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,31 @@ foreach my $test (@selected_tests) {
$output = '';
$test_file = $test;

my $expected_error;

if ($test_file =~ /_err/) {
if ($code =~ /^\s*#\s*(.*error.*)$/ism) {
$expected_error = $1;
} else {
$expected_error = "Unspecified error";
}
}

eval { $plang->interpret_string($code) };

if ($@) {
push @failed, [$test_file, 'EXCEPTION', '', $@];
print 'X';
if (my $exception = $@) {
if (defined $expected_error) {
if ($exception eq $expected_error) {
push @passed, [$test_file, 'EXCEPTION', $expected_error, $exception];
print '.';
} else {
push @failed, [$test_file, 'EXCEPTION', $expected_error, $exception];
print 'X';
}
} else {
push @failed, [$test_file, 'EXCEPTION', 'No exception', $exception];
print 'X';
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions test/curry_err.pt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fn curriedAdd(x) fn add(y) x + y

curriedAdd(3)(4)(5)

# Validator error: cannot invoke `7` as a function (have type Integer)

0 comments on commit 5216d27

Please sign in to comment.