Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Replace more eval-dies-ok with throws-like (S04)
  • Loading branch information
usev6 committed Sep 28, 2015
1 parent 202bbe6 commit 1753a2b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
14 changes: 7 additions & 7 deletions S04-statements/do.t
Expand Up @@ -6,16 +6,16 @@ plan 29;

# L<S04/The do-once loop/"can't" put "statement modifier">
# Note in accordance with STD, conditionals are OK, loops are not.
eval-dies-ok 'my $i = 1; do { $i++ } while $i < 5;',
throws-like 'my $i = 1; do { $i++ } while $i < 5;', X::Obsolete,
"'do' can't take the 'while' modifier";

eval-dies-ok 'my $i = 1; do { $i++ } until $i > 4;',
throws-like 'my $i = 1; do { $i++ } until $i > 4;', X::Obsolete,
"'do' can't take the 'until' modifier";

eval-dies-ok 'my $i; do { $i++ } for 1..3;',
throws-like 'my $i; do { $i++ } for 1..3;', X::Obsolete,
"'do' can't take the 'for' modifier";

eval-dies-ok 'my $i; do { $i++ } given $i;',
throws-like 'my $i; do { $i++ } given $i;', X::Obsolete,
"'do' can't take the 'given' modifier";

eval-lives-ok 'my $i; do { $i++ } unless $i;',
Expand Down Expand Up @@ -135,13 +135,13 @@ is EVAL('my $i; A: do { $i++; redo A until $i == 5; $i-- }; $i'), 4,

# L<S04/The do-once loop/"bare block is not a do-once">
{
eval-dies-ok 'my $i; { $i++; next; $i--; }',
throws-like 'my $i; { $i++; next; $i--; }', X::ControlFlow,
"bare block can't take 'next'";

eval-dies-ok 'my $i; { $i++; last; $i--; }',
throws-like 'my $i; { $i++; last; $i--; }', X::ControlFlow,
"bare block can't take 'last'";

eval-dies-ok 'my $i; { $i++; redo; $i--; }',
throws-like 'my $i; { $i++; redo; $i--; }', X::ControlFlow,
"bare block can't take 'last'";
}

Expand Down
21 changes: 11 additions & 10 deletions S04-statements/for.t
Expand Up @@ -4,7 +4,7 @@ use MONKEY-TYPING;

use Test;

plan 93;
plan 94;

=begin description
Expand All @@ -19,8 +19,8 @@ for statement as possible
# L<S04/The C<for> statement/"no foreach statement any more">
{
my $times_run = 0;
eval-dies-ok 'foreach 1..10 { $times_run++ }; 1', "foreach is gone";
eval-dies-ok 'foreach (1..10) { $times_run++}; 1',
throws-like 'foreach 1..10 { $times_run++ }; 1', X::Obsolete, "foreach is gone";
throws-like 'foreach (1..10) { $times_run++}; 1', X::Obsolete,
"foreach is gone, even with parens";
is $times_run, 0, "foreach doesn't work";
}
Expand Down Expand Up @@ -364,7 +364,7 @@ class TestClass{ has $.key is rw };
}

# L<S04/Statement parsing/keywords require whitespace>
eval-dies-ok('for(0..5) { }','keyword needs at least one whitespace after it');
throws-like 'for(0..5) { }', X::Comp::Group, 'keyword needs at least one whitespace after it';

# looping with more than one loop variables
{
Expand All @@ -377,9 +377,10 @@ eval-dies-ok('for(0..5) { }','keyword needs at least one whitespace after it');
}

{
#my $str = '';
eval-dies-ok('for 1..5 -> $x, $y { $str ~= "$x$y" }', 'Should throw exception, no value for parameter $y');
#is $str, "1234", "loop ran before throwing exception";
my $str = '';
throws-like 'for 1..5 -> $x, $y { $str ~= "$x$y" }', X::AdHoc,
'Should throw exception, no value for parameter $y';
is $str, "1234", "loop ran before throwing exception";
#diag ">$str<";
}

Expand Down Expand Up @@ -422,8 +423,8 @@ eval-dies-ok('for(0..5) { }','keyword needs at least one whitespace after it');
}

{
eval-dies-ok 'for 1.. { };', "Please use ..* for indefinite range";
eval-dies-ok 'for 1... { };', "1... does not exist";
throws-like 'for 1.. { };', X::Comp::Group, "Please use ..* for indefinite range";
throws-like 'for 1... { };', X::Comp::Group, "1... does not exist";
}

{
Expand Down Expand Up @@ -505,7 +506,7 @@ eval-dies-ok('for(0..5) { }','keyword needs at least one whitespace after it');

# RT #62478
{
eval-dies-ok 'for (my $i; $i <=3; $i++) { $i; }', 'Unsupported use of C-style "for (;;)" loop; in Perl 6 please use "loop (;;)"';
throws-like 'for (my $i; $i <=3; $i++) { $i; }', X::Obsolete, 'Unsupported use of C-style "for (;;)" loop; in Perl 6 please use "loop (;;)"';
}

{
Expand Down

0 comments on commit 1753a2b

Please sign in to comment.