Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Another batch of (eval_|)dies_ok -> throws_like
  • Loading branch information
lizmat committed Aug 17, 2014
1 parent 8487e75 commit 89c2de2
Show file tree
Hide file tree
Showing 17 changed files with 217 additions and 109 deletions.
6 changes: 4 additions & 2 deletions S02-literals/misc-interpolation.t
Expand Up @@ -105,14 +105,16 @@ is("x \c[65,66,67]] x", "x ABC] x", "\\c[] should not eat following ]s");
'interpolation of indirect method calls (different quotes)';
is "|$x."f"()|", '|int|', #OK use of quotes
'interpolation of indirect method calls (same quotes)';
eval_dies_ok q["|$x."f "()"], '... but whitespaces are not allowed';
throws_like { EVAL q["|$x."f "()"] },
X::Syntax::Confused,
'... but whitespaces are not allowed';
}

# RT # 104594
# rakudo had some trouble with lexicals from inside interpolated blocks
{
sub t($p) { t $p-1 if $p-1 > 0; return "{$p}" };
is t(3), 3, 'variables interpoalted into blocks and recursion interact nicely';
is t(3), 3, 'variables interpolated into blocks and recursion interact nicely';
}

# vim: ft=perl6
61 changes: 43 additions & 18 deletions S02-literals/pairs.t
Expand Up @@ -71,18 +71,40 @@ sub f2 (:$a!) { WHAT($a) }
isa_ok $f2(:a), Bool, "in '\$f2(:a)', ':a' is a named";
isa_ok $f2.(:a), Bool, "in '\$f2.(:a)', ':a' is a named";

dies_ok { f2("a" => 42) }, "'\"a\" => 42' is a pair";
dies_ok { f2(("a") => 42) }, "'(\"a\") => 42' is a pair";
dies_ok { f2((a => 42)) }, "'(a => 42)' is a pair";
dies_ok { f2(("a" => 42)) }, "'(\"a\" => 42)' is a pair";
dies_ok { f2((:a(42))) }, "'(:a(42))' is a pair";
dies_ok { f2((:a)) }, "'(:a)' is a pair";
dies_ok { &f2.((:a)) }, 'in \'&f2.((:a))\', \'(:a)\' is a pair';

dies_ok { $f2((:a)) }, "in '\$f2((:a))', '(:a)' is a pair";
dies_ok { $f2.((:a)) }, "in '\$f2.((:a))', '(:a)' is a pair";
dies_ok { $f2(((:a))) }, "in '\$f2(((:a)))', '(:a)' is a pair";
dies_ok { $f2.(((:a))) }, "in '\$f2.(((:a)))', '(:a)' is a pair";
throws_like { f2("a" => 42) },
X::AdHoc,
"'\"a\" => 42' is a pair";
throws_like { f2(("a") => 42) },
X::AdHoc,
"'(\"a\") => 42' is a pair";
throws_like { f2((a => 42)) },
X::AdHoc,
"'(a => 42)' is a pair";
throws_like { f2(("a" => 42)) },
X::AdHoc,
"'(\"a\" => 42)' is a pair";
throws_like { f2((:a(42))) },
X::AdHoc,
"'(:a(42))' is a pair";
throws_like { f2((:a)) },
X::AdHoc,
"'(:a)' is a pair";
throws_like { &f2.((:a)) },
X::AdHoc,
'in \'&f2.((:a))\', \'(:a)\' is a pair';

throws_like { $f2((:a)) },
X::AdHoc,
"in '\$f2((:a))', '(:a)' is a pair";
throws_like { $f2.((:a)) },
X::AdHoc,
"in '\$f2.((:a))', '(:a)' is a pair";
throws_like { $f2(((:a))) },
X::AdHoc,
"in '\$f2(((:a)))', '(:a)' is a pair";
throws_like { $f2.(((:a))) },
X::AdHoc,
"in '\$f2.(((:a)))', '(:a)' is a pair";
}

sub f3 ($a) { WHAT($a) }
Expand Down Expand Up @@ -129,24 +151,27 @@ sub f7 (:$bar!) { WHAT($bar) }
{
my $bar = 'bar';

dies_ok { f7($bar => 42) },
"variables cannot be keys of syntactical pairs (1)";
throws_like { f7($bar => 42) },
X::AdHoc,
"variables cannot be keys of syntactical pairs (1)";
}

sub f8 (:$bar!) { WHAT($bar) }
{
my @array = <bar>;

dies_ok { f8(@array => 42) },
"variables cannot be keys of syntactical pairs (2)";
throws_like { f8(@array => 42) },
X::AdHoc,
"variables cannot be keys of syntactical pairs (2)";
}

sub f9 (:$bar!) { WHAT($bar) }
{
my $arrayref = <bar>;

dies_ok { f9($arrayref => 42) },
"variables cannot be keys of syntactical pairs (3)";
throws_like { f9($arrayref => 42) },
X::AdHoc,
"variables cannot be keys of syntactical pairs (3)";
}

{
Expand Down
12 changes: 6 additions & 6 deletions S02-literals/quoting-unicode.t
Expand Up @@ -84,12 +84,12 @@ RIGHT SQUARE BRACKET WITH TICK IN BOTTOM CORNER(U+298D/U+298E)';

# RT #66498
{
eval_dies_ok "q\c[SNOWMAN].\c[COMET]",
"Can't quote a string with a snowman and comet (U+2603 and U+2604)";
eval_dies_ok "'RT 66498' ~~ m\c[SNOWMAN].\c[COMET]",
"Can't quote a regex with a snowman and comet (U+2603 and U+2604)";
throws_like { EVAL "q\c[SNOWMAN].\c[COMET]" },
X::Comp::AdHoc,
"Can't quote a string with a snowman and comet (U+2603 and U+2604)";
throws_like { EVAL "'RT 66498' ~~ m\c[SNOWMAN].\c[COMET]" },
X::Comp::Group,
"Can't quote a regex with a snowman and comet (U+2603 and U+2604)";
}

done;

# vim: ft=perl6
20 changes: 13 additions & 7 deletions S02-literals/quoting.t
Expand Up @@ -162,7 +162,7 @@ Note that non-ASCII tests are kept in quoting-unicode.t
# but see L<news:20050101220112.GF25432@plum.flirble.org>
#?rakudo todo 'retriage'
{
eval_dies_ok "(q\0foo bar\0)";
throws_like { EVAL "(q\0foo bar\0)" }, X::Comp::AdHoc;
}
{ # traditional quote word
Expand Down Expand Up @@ -495,8 +495,12 @@ Hello, World
isa_ok rx:ignorecase{foo}, Regex, 'rx:i{...}';
isa_ok rx:s{foo}, Regex, 'rx:i{...}';
isa_ok rx:sigspace{foo}, Regex, 'rx:i{...}';
eval_dies_ok 'rx:unknown{foo}', 'rx:unknown dies';
eval_dies_ok 'rx:g{foo}', 'g does not make sense on rx//';
throws_like { EVAL 'rx:unknown{foo}' },
X::Syntax::Regex::Adverb,
'rx:unknown dies';
throws_like { EVAL 'rx:g{foo}' },
X::Syntax::Regex::Adverb,
'g does not make sense on rx//';
}
{
Expand All @@ -520,7 +524,9 @@ Hello, World
}
# RT #90124
eval_dies_ok q["@a<"], 'unclosed quote after array variable is an error';
throws_like { EVAL q["@a<"] },
X::Comp::AdHoc,
'unclosed quote after array variable is an error';
# RT #114090
is "foo $( my $x = 3 + 4; "bar" ) baz", 'foo bar baz', 'declaration in interpolation';
Expand Down Expand Up @@ -553,11 +559,11 @@ is <<<\>'n'>>.join('|'), '<>|n', 'texas quotes edge case';
}
{
eval_dies_ok 'q< < >', "Unmatched openers and closers fails to parse";
throws_like { EVAL 'q< < >' },
X::Comp::AdHoc,
"Unmatched openers and closers fails to parse";
is q< \> >, " > ", "Escaped closer produces the opener unescaped";
is q< \< >, " < ", "Escaped opener produces the opener unescaped";
}
done;
# vim: ft=perl6
29 changes: 21 additions & 8 deletions S02-literals/radix.t
Expand Up @@ -25,10 +25,11 @@ is( :10<42>, 0d42, ':10<42> and 0d42 are the same' );
is(:10('0d37'), 0d37, ":10('0d37') overrides default decimal");

# RT #107756
dies_ok { :10(42) }, ':10() really wants a string, not a number';
throws_like { :10(42) },
X::TypeCheck::Binding,
':10() really wants a string, not a number';
}


# L<S29/Conversions/"prefix:<:16>">
# L<S02/General radices/":16<DEAD_BEEF>">

Expand Down Expand Up @@ -169,7 +170,9 @@ is(
}

# L<S02/Exponentials/"not clear whether the exponentiator should be 10 or the radix">
eval_dies_ok '0b1.1e10', 'Ambiguous, illegal syntax doesn\'t work';
throws_like { EVAL '0b1.1e10' },
X::Syntax::Confused,
'Ambiguous, illegal syntax doesn\'t work';

# L<S02/Exponentials/"and this makes it explicit">
# probably don't need a test, but I'll write tests for any example :)
Expand Down Expand Up @@ -211,14 +214,24 @@ is( :2<1.1> * :2<10> ** :2<10>, 6, 'multiplication and exponentiatio
# I think we should go with the method call semantics in all of the ambiguous
# forms, mostly because "no such method: Int::e5" is clearer than silently
# succeeding and the error coming up somewhere else.
dies_ok { 2.e123 }, "2.e123 parses as method call";
dies_ok { 2.foo }, "2.foo parses as method call";
throws_like { 2.e123 },
X::Method::NotFound,
"2.e123 parses as method call";
throws_like { 2.foo },
X::Method::NotFound,
"2.foo parses as method call";

is +'00123', 123, "Leading zeroes stringify correctly";

eval_dies_ok ':2<2>', ':2<2> is illegal';
eval_dies_ok ':10<3a>', ':10<3a> is illegal';
eval_dies_ok ':0<0>', ':0<...> is illegal';
throws_like { EVAL ':2<2>' },
X::AdHoc,
':2<2> is illegal';
throws_like { EVAL ':10<3a>' },
X::AdHoc,
':10<3a> is illegal';
throws_like { EVAL ':0<0>' },
X::Syntax::Number::RadixOutOfRange,
':0<...> is illegal';

for 2..36 {
is EVAL(":{$_}<11>"), $_ + 1, "Adverbial form of base $_ works";
Expand Down
8 changes: 6 additions & 2 deletions S02-literals/sub-calls.t
Expand Up @@ -22,12 +22,16 @@ plan 20;
ok EVAL(q/foo(1); /), 'call with one arg, has parens';
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';
dies_ok { EVAL(q/foo'bar'; /) }, 'call with one arg, has no space and no parens';
throws_like { EVAL q/foo'bar'; / },
X::Syntax::Confused,
'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';

dies_ok { EVAL(q/foo:bar; /) }, 'call with adverb after no space';
throws_like { EVAL q/foo:bar; / },
X::Undeclared::Symbols,
'call with adverb after no space';
ok EVAL(q/foo :bar; /), 'call with adverb after space';

ok EVAL(q/foo(:bar); /), 'call with adverb in parens';
Expand Down
4 changes: 3 additions & 1 deletion S02-literals/subscript.t
Expand Up @@ -11,7 +11,9 @@ plan 2;
lives_ok({ all(@newval2) < any(@oldval); all(@newval1) > all(@oldval) }, "parses correctly, second statement is true");

my %hash = ("foo", "bar");
dies_ok { EVAL '%hash <foo>; 1'}, '%hash \s+ <subscript> doesnt parse';
throws_like { EVAL '%hash <foo>; 1'},
X::Comp::AdHoc,
'%hash \s+ <subscript> doesnt parse';
};

# vim: ft=perl6
28 changes: 19 additions & 9 deletions S02-literals/types.t
Expand Up @@ -5,23 +5,33 @@ use Test;

plan 7;

eval_dies_ok 'class A { }; class A { }', "Can't redeclare a class";
eval_lives_ok 'class G { ... }; class G { }', 'can redeclare stub classes';
eval_dies_ok 'class B is C { }', "Can't inherit from a non-existing class";
eval_dies_ok 'class D does E { }', "Can't do a non-existing role";
eval_dies_ok 'my F $x;', 'Unknown types in type constraints are an error';
throws_like { EVAL 'class A { }; class A { }' },
X::Redeclaration,
"Can't redeclare a class";
lives_ok { EVAL 'class G { ... }; class G { }' },
'can redeclare stub classes';
throws_like { EVAL 'class B is C { }' },
X::Inheritance::UnknownParent,
"Can't inherit from a non-existing class";
throws_like { EVAL 'class D does E { }' },
X::Comp::AdHoc,
"Can't do a non-existing role";
throws_like { EVAL 'my F $x;' },
X::Comp::Group,
'Unknown types in type constraints are an error';

# integration tests - in Rakudo some class names from Parrot leaked through,
# so you couldn't name a class 'Task' - RT #61128

eval_lives_ok 'class Task { has $.a }; Task.new(a => 3 );',
'can call a class "Task" - RT 61128';
lives_ok { EVAL 'class Task { has $.a }; Task.new(a => 3 );' },
'can call a class "Task" - RT 61128';

# L<S02/Bare identifiers/If a postdeclaration is not seen, the compile fails at CHECK
# time>

eval_dies_ok q[caffeine(EVAL('sub caffeine($a){~$a}'))],
'Post declaration necessary';
throws_like { EVAL q[caffeine(EVAL('sub caffeine($a){~$a}'))] },
X::AdHoc,
'Post declaration necessary';

# vim: ft=perl6

48 changes: 36 additions & 12 deletions S02-literals/underscores.t
Expand Up @@ -17,23 +17,41 @@ plan 19;

is 1_0, 10, "Single embedded underscore works";

eval_dies_ok '1__0', "Multiple embedded underscores fail";
throws_like { EVAL '1__0' },
X::Comp::Group,
"Multiple embedded underscores fail";

eval_dies_ok '_10', "Leading underscore fails";
throws_like { EVAL '_10' },
X::AdHoc,
"Leading underscore fails";

eval_dies_ok '10_', "Trailing underscore fails";
throws_like { EVAL '10_' },
X::Syntax::Confused,
"Trailing underscore fails";

eval_dies_ok '10_.0', "Underscore before . fails";
throws_like { EVAL '10_.0' },
X::Syntax::Confused,
"Underscore before . fails";

eval_dies_ok '10._0', "Underscore after . fails";
throws_like { EVAL '10._0' },
X::Method::NotFound,
"Underscore after . fails";

eval_dies_ok '10_e1', "Underscore before e fails";
throws_like { EVAL '10_e1' },
X::Syntax::Confused,
"Underscore before e fails";

eval_dies_ok '10e_1', "Underscore after e fails";
throws_like { EVAL '10e_1' },
X::Syntax::Confused,
"Underscore after e fails";

eval_dies_ok '10_E1', "Underscore before E fails";
throws_like { EVAL '10_E1' },
X::Syntax::Confused,
"Underscore before E fails";

eval_dies_ok '10E_1', "Underscore after E fails";
throws_like { EVAL '10E_1' },
X::Syntax::Confused,
"Underscore after E fails";

ok 3.1_41 == 3.141, "Underscores work with floating point after decimal";

Expand All @@ -47,8 +65,14 @@ is 2e0_1, 20, "Underscores work in the argument for e";

ok 2.1_23 == 2.123, "2.1_23 parses as number";

dies_ok { 2._foo }, "2._foo parses as method call";
dies_ok { 2._123 }, "2._123 parses as method call";
dies_ok { 2._e23 }, "2._23 parses as method call";
throws_like { 2._foo },
X::Method::NotFound,
"2._foo parses as method call";
throws_like { 2._123 },
X::Method::NotFound,
"2._123 parses as method call";
throws_like { 2._e23 },
X::Method::NotFound,
"2._23 parses as method call";

# vim: ft=perl6
4 changes: 3 additions & 1 deletion S02-magicals/env.t
Expand Up @@ -57,7 +57,9 @@ ok(%*ENV<PUGS_ROCKS>:!exists, 'We can remove keys from %*ENV');
ok %*ENV<does_not_exist>:!exists, "exists() returns false on a not defined env var";

# %ENV must not be imported by default
eval_dies_ok("%ENV", '%ENV not visible by default');
throws_like { EVAL "%ENV" },
X::Undeclared,
'%ENV not visible by default';

#?rakudo skip 'import fails, ENV not available: RT #122339'
#?niecza skip 'Action method statement_control:import not yet implemented'
Expand Down

0 comments on commit 89c2de2

Please sign in to comment.