Skip to content

Commit

Permalink
More dies_ok -> throws_like cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lizmat committed Aug 15, 2014
1 parent 20d6f3b commit bf6c3cb
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 17 deletions.
13 changes: 9 additions & 4 deletions integration/advent2009-day09.t
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ is grade_essay("How to eat a Fish", 0), 0, 'P6 auto unpacking/verification';
ok (entreat()), 'Default values for parameters works';
is (xml_tag("hi")), "hihi>", 'Default values using previously supplied arguments';
nok deactivate("Rakudo Quality Fission"), 'optional parameters';
dies_ok {drawline2(1,2,3,4)}, 'wrong number of parameters, no exception object';
throws_like {drawline2(1,2,3,4)},
X::AdHoc,
'wrong number of parameters, no exception object';
ok (drawline2(:x1(3))), 'When you force naming, they are not all required.';
#the required & must-be named (:$var!) test not here, its opposite is 1 up
is (varsum(100,200,30,40,5)), 375, 'Parameters with a * in front can take as many items as you wish';
Expand All @@ -66,21 +68,24 @@ is detector(:foo(1), :bar(2), :camel(3)), ("'bar', 'camel'"|"'camel', 'bar'"), '
#?niecza todo 'Capturing arbitrary named parameters as hash'
is (detector(foo => 1, bar => 2, camel => 3)), ("'bar', 'camel'"|"'camel', 'bar'"), 'Same as above test, only passed as hash';
my $t = 3;
dies_ok {up1($t)}, "Can't modify parameters within by default, no exception object.";
throws_like {up1($t)},
X::AdHoc,
"Can't modify parameters within by default, no exception object.";
up1_2($t);
is $t, 4, 'Set a parameter to "is rw", and then you can modify';
up1_3($t);
is $t, 4, '"is copy" leaves original alone"';
my @te = <a b c>;
dies_ok {EVAL 'namen(@te)' }, 'Autoflattening doesnt exist, no exception object';
throws_like {EVAL 'namen(@te)' },
X::AdHoc,
'Autoflattening doesnt exist, no exception object';
is (namen(|@te)), ('a','b','c'), "Put a | in front of the variable, and you're ok!";

is <734043054508967647390469416144647854399310>.comb(/.**7/).join('|') , '7340430|5450896|7647390|4694161|4464785|4399310' , 'Test one liner at end of post (part1)';
{
is '7340430'.fmt("%b").trans("01" => " #") , '### ## ### ' , 'Test one liner at end of post (part2)';
}

done;
#type constraint on parameters skipped, due to that part of Day 9 being just a caution

#test done, below is the day's one-liner (in case you wish to enable it :) )
Expand Down
8 changes: 6 additions & 2 deletions integration/code-blocks-as-sub-args.t
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ Test a bug where sub args of type Sub do not get handled correctly.

sub foo (Sub $code, Str $a, Str $b) { return $a.WHAT } #OK not used

dies_ok {foo(-> { die "test" }, "a", "b")}, 'pointy block is not a sub';
throws_like {foo(-> { die "test" }, "a", "b")},
X::TypeCheck::Binding,
'pointy block is not a sub';
lives_ok {foo( sub { die "test" }, 'a', 'b')}, 'anonymous sub as argument not executed';

sub foo2 (Sub $code, Str $a, Str $b?) { return $a.WHAT } #OK not used

dies_ok {foo2(-> { die "test" }, "a", "b")}, 'pointy block is not a sub (with optional last arg)';
throws_like {foo2(-> { die "test" }, "a", "b")},
X::TypeCheck::Binding,
'pointy block is not a sub (with optional last arg)';
lives_ok {foo2( sub { die "test" }, 'a', 'b')}, 'anonymous sub as argument not executed (with optional last arg)';

# vim: ft=perl6
8 changes: 6 additions & 2 deletions integration/no-indirect-new.t
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ plan 2;
{
class A { has $.b }

eval_dies_ok "new A", 'parameterless prefixed new is allowed';
throws_like { EVAL "new A" },
X::Undeclared::Symbols,
'parameterless prefixed new is allowed';

eval_dies_ok( "new A( :b('bulbous bouffant') )", 'what looks like a constructor call is really a coersion to A, and should therefore be disallowed' );
throws_like { EVAL "new A( :b('bulbous bouffant') )" },
X::Obsolete,
'what looks like a constructor call is really a coersion to A, and should therefore be disallowed';
}

# vim: ft=perl6
6 changes: 3 additions & 3 deletions integration/real-strings.t
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ plan 20;
is $x.trans(['a'] => ['b']), 'b', 'same for split(Str)';
}

dies_ok { for "a b c".split(/\s/) -> $foo { $foo = $foo; } }, 'variables returned from split and passed to pointy block are still ro';
throws_like { for "a b c".split(/\s/) -> $foo { $foo = $foo; } },
X::AdHoc, # no exception type yet
'variables returned from split and passed to pointy block are still ro';

# used to be RT #55962

Expand Down Expand Up @@ -81,6 +83,4 @@ is "helo".substr(0,3).trans, 'hel', 'substr returns P6 strings (RT 76564, RT 710
'Still works with strings returned from slurp() (lives)';
}

done;

# vim: ft=perl6
2 changes: 1 addition & 1 deletion integration/role-composition-vs-attribute.t
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ plan 10;
role AAAA {
has Int $!aaaa;
}
dies_ok { EVAL q:to/CODE/ }, 'unknown attribute dies at compile time';
throws_like { EVAL q:to/CODE/ }, X::Attribute::Undeclared, 'unknown attribute dies at compile time';
class Zop does AAAA {
method zippo { $!zzzz++ } # first time
method zappo { $!zzzz++ } # second time, without $/ internally
Expand Down
12 changes: 7 additions & 5 deletions integration/weird-errors.t
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ is_run(
'presence of postcircumfix does not lead to redeclaration warnings',
);

eval_dies_ok 'time(1, 2, 3)', 'time() with arguments dies';
throws_like { EVAL 'time(1, 2, 3)' },
X::Undeclared::Symbols,
'time() with arguments dies';

# RT #76996
#?niecza todo
Expand All @@ -56,17 +58,17 @@ lives_ok { Any .= (); CATCH { when X::Method::NotFound {1} } }, 'Typed, non-inte

# RT #77246
{
eval_dies_ok('_~*.A', 'weird string that once parsed in rakudo');
dies_ok { EVAL '_~*.A' }, 'weird string that once parsed in rakudo';
}

# RT #115284
{
eval_lives_ok('say(;:[])', 'weird code that used to parsefail rakudo');
lives_ok { EVAL 'say(;:[])' }, 'weird code that used to parsefail rakudo';
}

# RT #76432
{
eval_lives_ok('class A {
lives_ok { EVAL 'class A {
has %!x;
method m {
Expand All @@ -75,7 +77,7 @@ lives_ok { Any .= (); CATCH { when X::Method::NotFound {1} } }, 'Typed, non-inte
%!x<bar> = 42;
}
}', "still able to parse statement after sub decl ending in newline");
}' }, "still able to parse statement after sub decl ending in newline";
}

# RT #116268
Expand Down

0 comments on commit bf6c3cb

Please sign in to comment.