Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[t/compiler.t] checked error message on failure
Just knowing that something fails isn't very informative. It turns out
we were sometimes failing for the wrong reasons. This commit is more
discerning about the actual failure.
  • Loading branch information
Carl Masak committed Feb 12, 2011
1 parent b62dada commit 97dea43
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions t/compiler.t
Expand Up @@ -52,34 +52,36 @@ for @programs-that-compile -> $program {
}

my @programs-that-don't-compile = # '
'$a',
'my',
'$a; my $a',
'my $a =',
'$a = 42',
'42 = my $a',
'42 := my $a',
'say $a',
'say $a; my $a',
'++42',
'{ my $a }; say $a',
'else { 42 }',
'if 42 say 42',
'if $a {}',
'if 42 { $a }',
'if 5 {} else { $a }',
'unless {}',
'unless a {}',
'my $a = 1; { say $a; my $a = 2 }', # use+declaration is outlawed
'$a' => 'used but not declared',
'my' => 'could not parse',
'$a; my $a' => 'used but not declared',
'my $a =' => 'could not parse',
'$a = 42' => 'used but not declared',
'42 = my $a' => 'could not parse',
'42 := my $a' => 'could not parse',
'say $a' => 'used but not declared',
'say $a; my $a' => 'used but not declared',
'++42' => 'could not parse',
'{ my $a }; say $a' => 'used but not declared',
'else { 42 }' => 'could not parse',
'if 42 say 42' => 'could not parse',
'if $a {}' => 'could not parse',
'if 42 { $a }' => 'used but not declared',
'if 5 {} else { $a }' => 'used but not declared',
'unless {}' => 'could not parse',
'unless a {}' => 'could not parse',
'my $a = 1; { say $a; my $a = 2 }' => 'reference to outer variable',
;

for @programs-that-don't-compile -> $program { # '
for @programs-that-don't-compile -> $pair { # '
my ($program, $expected-error) = .key, .value given $pair;
my $can-compile = False;
try {
$c.compile($program);
$can-compile = True;
}
ok !$can-compile, "will not compile '$program'";
ok !$can-compile && defined $!.substr($expected-error),
"'{escape $program}' gives error '$expected-error'";
}

done;

0 comments on commit 97dea43

Please sign in to comment.