Permalink
Browse files

&eval does not catch exceptions.

This has far reaching consequences for roast, and this
patch only catches a subset of them.
It also removes a few evals that were only there for error
catching, and are now useless.
Some fudging has also changed.
  • Loading branch information...
1 parent 0c8e9c6 commit 001e798bcbc2015f3af232b8a900a5dd32877c42 @moritz moritz committed Oct 9, 2011
Showing with 154 additions and 176 deletions.
  1. +8 −9 S02-lexical-conventions/unspace.t
  2. +2 −2 S02-literals/radix.t
  3. +3 −6 S02-literals/sub-calls.t
  4. +1 −1 S02-literals/subscript.t
  5. +9 −12 S02-magicals/dollar_bang.t
  6. +2 −2 S02-magicals/env.t
  7. +1 −0 S02-names-vars/list_array_perl.t
  8. +4 −3 S02-names-vars/names.t
  9. +2 −3 S02-types/hash.t
  10. +1 −1 S02-types/lists.t
  11. +2 −2 S02-types/subset.t
  12. +5 −4 S03-metaops/hyper.t
  13. +3 −3 S03-operators/binding-scalars.t
  14. +3 −3 S03-operators/brainos.t
  15. +3 −5 S03-operators/precedence.t
  16. +4 −2 S04-declarations/constant.t
  17. +1 −2 S04-declarations/my.t
  18. +2 −3 S04-exception-handlers/catch.t
  19. +3 −3 S04-statements/for.t
  20. +1 −1 S05-metasyntax/regex.t
  21. +1 −2 S05-metasyntax/unknown.t
  22. +4 −7 S06-multi/lexical-multis.t
  23. +5 −5 S06-operator-overloading/imported-subs.t
  24. +2 −2 S06-other/main-eval.t
  25. +1 −2 S06-other/misc.t
  26. +2 −2 S06-routine-modifiers/scoped-named-subs.t
  27. +1 −2 S06-signature/arity.t
  28. +2 −2 S06-signature/errors.t
  29. +19 −20 S06-signature/named-parameters.t
  30. +1 −1 S06-signature/optional.t
  31. +2 −4 S06-signature/passing-arrays.t
  32. +1 −1 S06-signature/slurpy-params.t
  33. +2 −2 S06-signature/unspecified.t
  34. +1 −1 S06-traits/as.t
  35. +1 −0 S06-traits/is-readonly.t
  36. +1 −1 S06-traits/is-rw.t
  37. +10 −10 S10-packages/basic.t
  38. +2 −3 S10-packages/use-with-class.t
  39. +1 −1 S11-modules/lexical.t
  40. +1 −4 S12-class/attributes.t
  41. +2 −1 S12-class/augment-supersede.t
  42. +2 −2 S12-class/instantiate.t
  43. +2 −2 S12-class/self-inheritance.t
  44. +2 −2 S12-methods/multi.t
  45. +1 −1 S12-methods/private.t
  46. +2 −2 S12-subset/subtypes.t
  47. +11 −15 S13-overloading/operators.t
  48. +1 −1 S14-roles/composition.t
  49. +4 −4 S29-context/eval.t
  50. +2 −2 S32-array/pop.t
  51. +2 −2 S32-array/shift.t
  52. +1 −1 S32-temporal/DateTime-Instant-Duration.t
  53. +1 −1 integration/advent2009-day04.t
  54. +1 −1 integration/error-reporting.t
@@ -33,19 +33,18 @@ is((:foo\ ("bar")), ('foo' => "bar"), 'unspace with adverb');
is( ~([1,2,3]\ .[2,1,0]), "3 2 1", 'unspace on postfix subscript');
-my @array = 1,2,3;
+#?rakudo skip 'unimplemented postfix forms'
+{
+ my @array = 1,2,3;
-eval "
@array\ .>>++;
@array>>\ .++;
@array\ .>>\ .++;
@array\ .»++;
@array»\ .++;
@array\ .»\ .++;
-";
-#?pugs todo 'unimpl'
-#?rakudo todo 'unimpl'
-is( ~@array, "7 8 9", 'unspace with postfix hyperops');
+ is( ~@array, "7 8 9", 'unspace with postfix hyperops');
+}
#Test the "unspace" and unspace syntax
@@ -98,7 +97,7 @@ is(eval('foo\
#unspace is allowed after a pod = ... which means pod is
#syntactically recursive, i.e. you can put pod comments
#inside pod directives recursively!
-#?rakudo todo 'pod and unspace'
+#?rakudo skip 'pod and unspace'
is(eval('foo\
=\ begin comment
blah blah blah
@@ -114,11 +113,11 @@ blah
.lc'), 'a', 'unspace with pod =for comment w/ pod unspace');
}
-#?rakudo todo 'pod and unspace'
+#?rakudo skip 'pod and unspace'
is(eval('foo\
=\ comment blah blah blah
.lc'), 'a', 'unspace with pod =comment w/ pod unspace');
-#?rakudo todo 'pod and unspace'
+#?rakudo skip 'pod and unspace'
is(eval('foo\
=\
=begin nested_pod
View
@@ -181,8 +181,8 @@ is( :2<1.1> * :2<10> ** :2<10>, 6, 'multiplication and exponentiatio
#?pugs todo 'feature'
{
is( :2<1.1*2**10>, 1536, 'Power of two in <> works');
- #?rakudo todo "Really?!"
- is( eval('2«1.1*:2<10>**:2<10>»'), 6, 'Powers of two in <<>> works');
+ #?rakudo skip "Really?!"
+ is( 2«1.1*:2<10>**:2<10>», 6, 'Powers of two in <<>> works');
}
# Tests for the :x[ <list> ] notations
View
@@ -7,9 +7,6 @@ plan 20;
# TODO: *really* need a better smartlink
# L<S02/Bare identifiers/"If the unrecognized subroutine name">
-# Since these are all parsing tests, they should use eval to ensure all tests
-# can run even if something is broken. (Unless things are VERY broken.)
-
#?pugs emit if $?PUGS_BACKEND ne "BACKEND_PUGS" {
#?pugs emit skip_rest "PIL2JS and PIL-Run do not support eval() yet.";
#?pugs emit exit;
@@ -31,12 +28,12 @@ plan 20;
ok eval(q/&foo.(1); /), 'call with one arg, has dot and parens';
ok eval(q/&foo\ .(1);/), 'call with one arg, has long dot and parens';
#?pugs todo 'unspecced'
- nok eval(q/foo'bar'; /), 'call with one arg, has no space and no parens';
+ nok try { eval(q/foo'bar'; /) }, 'call with one arg, has no space and no parens';
ok eval(q/foo 1, 2; /), 'call with two args, no parens';
ok eval(q/foo(1, 2);/), 'call with two args, has parens';
- #?rakudo todo 'should parse as a routine foo:bar'
+ #?rakudo skip 'should parse as a routine foo:bar'
ok eval(q/foo:bar; /), 'call with adverb after no space';
ok eval(q/foo :bar; /), 'call with adverb after space';
@@ -51,7 +48,7 @@ plan 20;
sub succ($x) { $x + 1 }
is(eval(q/succ (1+2) * 30;/), 91, "parens after space aren't call-parens");
- ok(!eval(q/succ .(1+2) * 30;/), 'parsed as method call on $_');
+ nok(try {eval(q/succ .(1+2) * 30;/) }, 'parsed as method call on $_');
}
{
sub first() { "first" }
View
@@ -11,7 +11,7 @@ plan 3;
lives_ok({ all(@newval2) < any(@oldval); all(@newval1) > all(@oldval) }, "parses correctly, second statement is true");
my %hash = ("foo", "bar");
- ok(!(eval '%hash <foo>; 1'), '%hash \s+ <subscript> doesnt parse');
+ nok try { eval '%hash <foo>; 1'}, '%hash \s+ <subscript> doesnt parse';
isnt($!,"",'... and it sets $!');
};
View
@@ -2,7 +2,7 @@ use v6;
use Test;
-plan 18;
+plan 16;
=begin desc
@@ -12,31 +12,27 @@ This test tests the C<$!> builtin.
# L<S04/"Exceptions"/A bare die/fail takes $! as the default argument>
-eval 'nonexisting_subroutine()';
-ok defined($!), 'nonexisting sub in eval makes $! defined';
-eval 'nonexisting_subroutine()';
-ok $!, 'Calling a nonexisting subroutine sets $!';
+try { die "foo" };
+ok defined($!), 'error in try makes $! defined';
try { 1 };
nok $!.defined, 'successful try { } resets $!';
try { 1.nonexisting_method; };
ok $!.defined, 'Calling a nonexisting method defines $!';
-try { 1.nonexisting_method; };
-ok $!, 'Calling a nonexisting smethod sets $!';
my $called;
sub foo(Str $s) { return $called++ }; #OK not used
my @a;
-try { foo(@a,@a) };
-ok $!, 'Calling a subroutine with a nonmatching signature sets $!';
+try { eval 'foo(@a,@a)' };
+ok $!.defined, 'Calling a subroutine with a nonmatching signature sets $!';
ok !$called, 'The subroutine also was not called';
try { 1 div 0 };
-ok $!, 'Dividing one by zero sets $!';
+ok $!.defined, 'Dividing one by zero sets $!';
sub incr ( $a is rw ) { $a++ };
try { incr(19) };
-ok $!, 'Modifying a constant sets $!';
+ok $!.defined, 'Modifying a constant sets $!';
try {
try {
@@ -59,9 +55,10 @@ ok ~($!) ~~ /qwerty/, 'die without argument uses $! properly';
# - also tested more generically above.
# So no need to test the value of #! again here.
#is $!, 'goodbye', '$! has correct value after try';
+ #?rakudo skip 'spec change pending (?)'
ok ($!), '$! as boolean works (true)';
- eval q[ die('farewell'); ];
+ try { eval q[ die('farewell'); ] };
ok defined($!.perl), '$! has working Perl 6 object methods after eval';
ok ($!.WHAT ~~ Exception), '$! is Exception object after eval';
# Although S29-context/die.t tests $! being set after die, it's not
View
@@ -134,8 +134,8 @@ ok !%*ENV.exists("does_not_exist"), "exists() returns false on a not defined env
# Importation must be lexical
#?pugs todo 'bug'
{
- my $x = eval "%ENV";
- ok !$x.defined, '%ENV not visible by after lexical import scope';
+ try { eval "%ENV" };
+ ok $!.defined, '%ENV not visible by after lexical import scope';
1;
}
@@ -98,6 +98,7 @@ my @tests = (
}
# RT #65988
+#?rakudo skip 'RT 65988'
{
my $rt65988 = (\(1,2), \(3,4));
#?rakudo todo 'RT 65988 (bogus test?)'
View
@@ -2,7 +2,7 @@ use v6;
use Test;
-plan 139;
+plan 140;
# I'm using semi-random nouns for variable names since I'm tired of foo/bar/baz and alpha/beta/...
@@ -60,7 +60,8 @@ plan 139;
'dies when calling non-existent sub in existing package';
# RT #74520
class TestA { };
- eval 'TestA::b(3, :foo)';
+ nok try { eval 'TestA::b(3, :foo)'},
+ 'calling non-existing function in foreign class dies';;
#?rakudo todo 'nom regression'
ok "$!" ~~ / ' TestA::b' /, 'error message mentions function name';
}
@@ -97,7 +98,7 @@ plan 139;
# RT #69752
{
- eval 'Module.new';
+ try { eval 'Module.new' };
ok "$!" ~~ / 'Module' /,
'error message mentions name not recognized, no maximum recursion depth exceeded';
}
View
@@ -190,10 +190,9 @@ is %dupl<a>, 3, "hash creation with duplicate keys works correctly";
is $i, 4, "for %hash works";
}
-#?niecza skip 'Non-declarative sigil is missing its name'
{
- eval ' @%(a => <b>)<a> ';
- ok( $!, "doesn't really make sense, but shouldn't segfault, either ($!)");
+ nok try { eval ' @%(a => <b>)<a>' },
+ "doesn't really make sense, but shouldn't segfault, either ($!)";
}
# test for RT #62730
View
@@ -143,7 +143,7 @@ plan 29;
dies_ok { <1 2 3>.rt62836 },
'call to user-declared sub in List:: class dies';
- eval '<1 2 3>.rt62836';
+ try { eval '<1 2 3>.rt62836' };
ok "$!" ~~ /rt62836/, 'error message contains name of sub';
ok "$!" ~~ /not \s+ found/, 'error message says "not found"';
diag $!;
View
@@ -18,11 +18,11 @@ subset Even of Int where { $_ % 2 == 0 };
};
-nok eval('my Even $x = 3'),
+nok try { eval('my Even $x = 3') },
"Can't assign value that violates type constraint via subset";
# RT # 69518'
-nok eval('Even.new'), 'Cannot instantiate a subtype';
+nok try { eval('Even.new') }, 'Cannot instantiate a subtype';
{
ok 2 ~~ Even, 'Can smartmatch against subsets 1';
View
@@ -233,22 +233,23 @@ my @e;
};
#?niecza skip 'System.IndexOutOfRangeException: Array index is out of range.'
+#?rakudo skip 'postfix forms'
{ # unary postfix again, but with a twist
my @r;
- eval '@r = ("f", "oo", "bar")».chars';
+ @r = ("f", "oo", "bar".chars;
my @e = (1, 2, 3);
is(~@r, ~@e, "method call on list elements");
- eval '@r = ("f", "oo", "bar").».chars';
+ @r = ("f", "oo", "bar").».chars;
@e = (1, 2, 3);
is(~@r, ~@e, "method call on list elements (Same thing, dot form)");
- eval '@r = ("f", "oo", "bar")>>.chars';
+ @r = ("f", "oo", "bar")>>.chars;
@e = (1, 2, 3);
is(~@r, ~@e, "method call on list elements (ASCII)");
- eval '@r = ("f", "oo", "bar").>>.chars';
+ @r = ("f", "oo", "bar").>>.chars;
@e = (1, 2, 3);
is(~@r, ~@e, "method call on list elements (ASCII, Same thing, dot form)");
@@ -126,15 +126,15 @@ plan 29;
}
# := actually takes subroutine parameter list
-#?rakudo todo 'List binding'
+#?rakudo skip 'List binding'
#?niecza skip 'list binding'
{
my $a;
- eval '(:$a) := (:a<foo>)';
+ (:$a) := (:a<foo>);
#?pugs todo
is($a, "foo", "bound keyword");
my @tail;
- eval '($a, *@tail) := (1, 2, 3)';
+ ($a, *@tail) := (1, 2, 3);
#?pugs todo
ok($a == 1 && ~@tail eq '2 3', 'bound slurpy');
}
View
@@ -15,18 +15,18 @@ instead. Similar for C<!~>.
#L<S03/Chaining binary precedence/"To catch">
my $str = 'foo';
-eval '$str =~ m/bar/;';
+try { eval '$str =~ m/bar/;' };
ok $! ~~ Exception, 'caught "=~" braino';
ok "$!" ~~ /'~~'/, 'error for "=~" usage mentions "~~"';
-eval '$str !~ m/bar/;';
+try { eval '$str !~ m/bar/;' };
ok $! ~~ Exception, 'caught "!~" braino';
ok "$!" ~~ /'!~~'/, 'error for "!~" usage mentions "!~~"';
# RT #76878
+#?rakudo skip 'RT 76878'
{
my $x = 2;
- #?rakudo 4 todo 'RT 76878'
is eval('"$x =~ b"'), '2 =~ b', '=~ allowed in double quotes';
is eval('"$x !~ b"'), '2 !~ b', '!~ allowed in double quotes';
is eval('"$x << b"'), '2 << b', '<< allowed in double quotes';
@@ -146,24 +146,22 @@ is(((not 1,42)[1]), 42, "not is tighter than comma");
#?pugs todo 'list infix and assignment'
{
my @d;
- ok eval('@d = 1,3 Z 2,4'), "list infix tighter than list assignment, looser t than comma";
+ ok (@d = 1,3 Z 2,4), "list infix tighter than list assignment, looser t than comma";
is(@d, [1 .. 4], "to complicate things further, it dwims");
}
#?niecza skip 'Bogus term'
{
my @b;
- eval('@b = ((1, 3) Z (2, 4))');
+ @b = ((1, 3) Z (2, 4));
is(@b, [1 .. 4], "parens work around this");
};
# list prefix
#?niecza skip 'Undeclared name: "Z"'
{
- my $c;
- eval('$c = any 1, 2, Z 3, 4');
- #?rakudo skip 'unknown error'
+ my $c = any 1, 2 Z 3, 4;
ok($c == 3, "any is less tight than comma and Z");
}
@@ -162,7 +162,7 @@ use Test;
# Following tests test whether the constants are actually constant.
#?pugs todo 'feature'
{
- my $ok;
+ my $ok = 0;
constant grtz = 42;
$ok++ if grtz == 42;
@@ -171,6 +171,7 @@ use Test;
$ok++ if $!;
$ok++ if grtz == 42;
+ #?rakudo todo 'unknown'
is $ok, 3, "a constant declared using 'constant' is actually constant (1)";
}
@@ -191,7 +192,7 @@ use Test;
#?pugs todo 'feature'
{
- my $ok;
+ my $ok = 0;
constant wobble = 42;
$ok++ if wobble == 42;
@@ -200,6 +201,7 @@ use Test;
$ok++ if $!;
$ok++ if wobble == 42;
+ #?rakudo todo 'unknown'
is $ok, 3, "a constant declared using 'constant' is actually constant (3)";
}
View
@@ -203,7 +203,7 @@ my $z = 42; #OK not used
eval_lives_ok 'my $a;do { die "foo"; my $x; CATCH { default { $a = $x.defined } } }';
{
- #?rakudo 2 todo 'OUTER and SETTING'
+ #?rakudo 2 skip 'OUTER and SETTING'
ok eval('not OUTER::<$x>.defined'), 'OUTER::<$x>';
ok eval('not SETTING::<$x>.defined'), 'SETTING::<$x>';
my $x; #OK not used
@@ -220,7 +220,6 @@ my $z = 42; #OK not used
# XXX As I write this, this does not die right. more testing needed.
dies_ok { my Int $x = "abc" }, 'type error'; #OK
- #?rakudo todo 'type error not caught'
dies_ok { eval '$x = "abc"'; my Int $x; }, 'also a type error';
}
Oops, something went wrong.

0 comments on commit 001e798

Please sign in to comment.