Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Replace some eval-dies-ok in S06-* with throws-like
  • Loading branch information
usev6 committed Sep 24, 2015
1 parent f8f05e7 commit f6f656b
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 17 deletions.
3 changes: 2 additions & 1 deletion S06-multi/lexical-multis.t
Expand Up @@ -10,7 +10,8 @@ plan 15;
my multi foo() { 42 }
is(foo(), 42, 'can call lexically scoped multi');
}
eval-dies-ok(q{ foo() }, 'lexical multi not callable outside of lexical scope');
throws-like q{ foo() }, X::Undeclared::Symbols,
'lexical multi not callable outside of lexical scope';
}

# test that lexical multis in inner scopes add to those in outer scopes
Expand Down
4 changes: 2 additions & 2 deletions S06-multi/subsignature.t
Expand Up @@ -187,7 +187,7 @@ is(foo(42), 1, 'dispatch with no possible candidates fell back to proto');
is (elk 3), 4, "multi definition of prefix:<elk> works";
}

eval-dies-ok 'proto rt68242(|c($a)){};proto rt68242(|c($c,$d)){};',
throws-like 'proto rt68242(|c($a)){};proto rt68242(|c($c,$d)){};', X::Redeclaration,
'attempt to define two proto subs with the same name dies';

# RT #65322
Expand All @@ -196,7 +196,7 @@ eval-dies-ok 'proto rt68242(|c($a)){};proto rt68242(|c($c,$d)){};',
multi sub rt65322(|c( Int $n where 1 )) { 1 }
sub rt65322(|c( Int $n )) { 2 }
];
eval-dies-ok $rt65322, "Can't define sub and multi sub without proto";
throws-like 'EVAL $rt65322', X::Redeclaration, "Can't define sub and multi sub without proto";
}

# RT #111454
Expand Down
4 changes: 3 additions & 1 deletion S06-operator-overloading/sub.t
Expand Up @@ -270,7 +270,9 @@ Testing operator overloading subroutines
}
is (2 our_non_assoc_infix 3), (2 ** 3), "Non-associative works for just tow operands.";
is ((2 our_non_assoc_infix 2) our_non_assoc_infix 3), (2 ** 2) ** 3, "Non-associative works when used with parens.";
eval-dies-ok '2 our_non_assoc_infix 3 our_non_assoc_infix 4', "Non-associative should not parsed when used chainly.";
throws-like '2 our_non_assoc_infix 3 our_non_assoc_infix 4',
X::Syntax::NonAssociative,
"Non-associative should not parsed when used chainly.";
}

#?niecza skip "roles NYI"
Expand Down
2 changes: 1 addition & 1 deletion S06-other/pairs-as-lvalues.t
Expand Up @@ -5,7 +5,7 @@ plan 5;

# L<S06/Pairs as lvalues/>

eval-dies-ok 'my $var; (key => $var) = "value"';
throws-like 'my $var; (key => $var) = "value"', X::Assignment::RO;

#?rakudo.moar todo "NYI RT #124660"
#?rakudo.jvm skip "Flattening named argument must have VMHash REPR RT #124661"
Expand Down
6 changes: 3 additions & 3 deletions S06-signature/named-parameters.t
Expand Up @@ -222,9 +222,9 @@ nok(%fellowship<dwarf>.defined, "dwarf arg was not given");
# L<S06/Parameters and arguments/"A signature containing a name collision">

#?niecza 2 todo "sub params with the same name"
eval-dies-ok 'sub rt68086( $a, $a ) { }', 'two sub params with the same name';
throws-like 'sub rt68086( $a, $a ) { }', X::Redeclaration, 'two sub params with the same name';

eval-dies-ok 'sub svn28865( :$a, :@a ) {}',
throws-like 'sub svn28865( :$a, :@a ) {}', X::Signature::NameClash,
'sub params with the same name and different types';

{
Expand Down Expand Up @@ -267,7 +267,7 @@ eval-dies-ok 'sub svn28865( :$a, :@a ) {}',
# RT #67558
{
#?niecza todo "Renaming a parameter to an existing positional should fail"
eval-dies-ok q[sub a(:$x, :foo($x) = $x) { $x }],
throws-like q[sub a(:$x, :foo($x) = $x) { $x }], X::Redeclaration,
'Cannot rename a parameter to an already existing positional';
sub a(:$x, :foo($y) = $x) { $y };
is a(x => 2), 2, 'Can fill named parameter with default from other named';
Expand Down
19 changes: 11 additions & 8 deletions S06-signature/optional.t
Expand Up @@ -37,11 +37,14 @@ is opt_typed() , 'undef', 'can leave out optional typed param';

# L<S06/Parameters and arguments/"required positional parameters must come
# before those bound to optional positional">
eval-dies-ok 'sub wrong1 ($a?, $b) {...}', 'optional params before required ones are forbidden';
throws-like 'sub wrong1 ($a?, $b) {...}', X::Parameter::WrongOrder,
'optional params before required ones are forbidden';
# RT #76022
{
eval-dies-ok 'sub wrong2 ($a = 1, $b) {...}', "...even if they're only optional by virtue of a default";
eval-dies-ok 'sub wrong3 ($a = 0, $b) {...}', '...and the default is 0';
throws-like 'sub wrong2 ($a = 1, $b) {...}', X::Parameter::WrongOrder,
"...even if they're only optional by virtue of a default";
throws-like 'sub wrong3 ($a = 0, $b) {...}', X::Parameter::WrongOrder,
'...and the default is 0';
}

sub foo_53814($w, $x?, :$y = 2) { $w~"|"~$x~"|"~$y };
Expand All @@ -54,7 +57,7 @@ dies-ok {foo_53814(1,Mu,'something_extra',:y(3))},
# old test is bogus, nullterm only allowed at the end of a list
# is rt54804( 1, , 3, ), '1|undef|3|undef',
# 'two commas parse as if undef is between them';
eval-dies-ok q/sub rt54804( $v, $w?, $x?, $y? ) {
throws-like q/sub rt54804( $v, $w?, $x?, $y? ) {
(defined( $v ) ?? $v !! 'undef')
~ '|' ~
(defined( $w ) ?? $w !! 'undef')
Expand All @@ -63,11 +66,11 @@ dies-ok {foo_53814(1,Mu,'something_extra',:y(3))},
~ '|' ~
(defined( $y ) ?? $y !! 'undef')
}
rt54804( 1, , 3, )/, "two commas in a row doesn't parse";
rt54804( 1, , 3, )/, X::Syntax::InfixInTermPosition, "two commas in a row doesn't parse";
}

eval-dies-ok( 'sub rt66822($opt?, $req) { "$opt, $req" }',
"Can't put required parameter after optional parameters" );
throws-like 'sub rt66822($opt?, $req) { "$opt, $req" }', X::Parameter::WrongOrder,
"Can't put required parameter after optional parameters";

# Niecza bug#49
sub opt_array1(@x?) { @x.elems }
Expand All @@ -80,7 +83,7 @@ is opt_hash1(), 0, "optional hash not passed is empty";
is opt_hash2(), 0, "optional hash not passed is empty (copy)";

# RT #71110
eval-dies-ok 'sub opt($a = 1, $b) { }',
throws-like 'sub opt($a = 1, $b) { }', X::Parameter::WrongOrder,
'Cannot put required parameter after optional parameters';

# RT #74758
Expand Down
2 changes: 1 addition & 1 deletion S06-signature/slurpy-params.t
Expand Up @@ -318,7 +318,7 @@ These tests are the testing for "List parameters" section of Synopsis 06
is-deeply @result, [1,2,3,1,2,3], "iteration succeeds on second pass";
}

eval-dies-ok 'sub rt65324(*@x, $oops) { say $oops }',
throws-like 'sub rt65324(*@x, $oops) { say $oops }', X::Parameter::WrongOrder,
"Can't put required parameter after variadic parameters";

# used to be RT #69424
Expand Down

0 comments on commit f6f656b

Please sign in to comment.