Skip to content

Commit 3076e09

Browse files
committed
dies_ok -> throws_like cleanup, part 1
1 parent ef7e125 commit 3076e09

15 files changed

+50
-35
lines changed

integration/advent2009-day04.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ is fac(2), 2, 'fac(2) works';
1515
is fac(3), 6, 'fac(3) works';
1616
is fac(4), 24, 'fac(4) works';
1717

18-
dies_ok { EVAL(q[ fac('oh noes i am a string')]) }, 'Can only call it with ints';
18+
throws_like { EVAL q[fac('oh noes i am a string')] }, X::TypeCheck::Argument;

integration/advent2009-day06.t

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ my @pi-sin = @pi>>.sin;
1616
is (@a <<+>> @c), [4, 3, 6, 5], 'Dwimmy hyperoperator on arrays of the same length';
1717
is (@a >>+<< @c), [4, 3, 6, 5], 'Non-dwimmy hyperoperator on arrays of the same length';
1818
is (@a <<+>> @b), [4, 3, 6, 5], 'Dwimmy hyperoperator on arrays of different size';
19-
dies_ok {@a >>+<< @b}, 'Non-dwimmy hyperoperator on arrays of different size fails';
19+
throws_like {@a >>+<< @b}, X::HyperOp::NonDWIM,
20+
'Non-dwimmy hyperoperator on arrays of different size fails';
2021
is (@a >>+>> 2), [3, 4, 5, 6], 'Single scalars extend to the right';
2122
is (3 <<+<< @a), [4, 5, 6, 7], 'Single scalars extend to the left';
2223
is (~<<@a), ["1", "2", "3", "4"], 'Hyperoperator with prefix operator';
@@ -30,5 +31,3 @@ is ((-1, 0, 3, 42)>>.Str), ["-1", "0", "3", "42"], 'Hyperoperator used to call .
3031
{
3132
is (@a-copy = @a; @a-copy >>/=>> 2; @a-copy), [1/2, 2/2, 3/2, 4/2], 'In-place operators work';
3233
}
33-
34-
done;

integration/advent2009-day09.t

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ is grade_essay("How to eat a Fish", 0), 0, 'P6 auto unpacking/verification';
5757
ok (entreat()), 'Default values for parameters works';
5858
is (xml_tag("hi")), "hihi>", 'Default values using previously supplied arguments';
5959
nok deactivate("Rakudo Quality Fission"), 'optional parameters';
60-
dies_ok {drawline2(1,2,3,4)}, 'Must be named';
60+
dies_ok {drawline2(1,2,3,4)}, 'wrong number of parameters, no exception object';
6161
ok (drawline2(:x1(3))), 'When you force naming, they are not all required.';
6262
#the required & must-be named (:$var!) test not here, its opposite is 1 up
6363
is (varsum(100,200,30,40,5)), 375, 'Parameters with a * in front can take as many items as you wish';
@@ -66,13 +66,13 @@ is detector(:foo(1), :bar(2), :camel(3)), ("'bar', 'camel'"|"'camel', 'bar'"), '
6666
#?niecza todo 'Capturing arbitrary named parameters as hash'
6767
is (detector(foo => 1, bar => 2, camel => 3)), ("'bar', 'camel'"|"'camel', 'bar'"), 'Same as above test, only passed as hash';
6868
my $t = 3;
69-
dies_ok {up1($t)}, "Can't modify parameters within by default.";
69+
dies_ok {up1($t)}, "Can't modify parameters within by default, no exception object.";
7070
up1_2($t);
7171
is $t, 4, 'Set a parameter to "is rw", and then you can modify';
7272
up1_3($t);
7373
is $t, 4, '"is copy" leaves original alone"';
7474
my @te = <a b c>;
75-
dies_ok {EVAL 'namen(@te)' }, 'Autoflattening doesnt exist';
75+
dies_ok {EVAL 'namen(@te)' }, 'Autoflattening doesnt exist, no exception object';
7676
is (namen(|@te)), ('a','b','c'), "Put a | in front of the variable, and you're ok!";
7777

7878
is <734043054508967647390469416144647854399310>.comb(/.**7/).join('|') , '7340430|5450896|7647390|4694161|4464785|4399310' , 'Test one liner at end of post (part1)';

integration/advent2009-day18.t

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ role SocketPower {
2626
}
2727
}
2828

29-
#~ class Laptop does BatteryPower does SocketPower {}
30-
eval_dies_ok 'class Laptop does BatteryPower does SocketPower {}' , "Method 'find-power-accessories' collides and a resolution must be provided by the class";
29+
#~ class Notebook does BatteryPower does SocketPower {}
30+
throws_like { EVAL 'class Notebook does BatteryPower does SocketPower {}' },
31+
X::AdHoc, # doesn't have its own exception yet
32+
"Method 'find-power-accessories' collides and a resolution must be provided by the class";
3133

3234
class Laptop does BatteryPower does SocketPower {
3335
method find-power-accessories() {

integration/advent2010-day07.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ use Test;
66

77
plan 8;
88

9-
dies_ok {EVAL '{ $var = 42 }'};
9+
throws_like {EVAL '{ $var = 42 }'}, X::Undeclared;
1010
lives_ok {EVAL '{ my $var = 42 }'};
11-
dies_ok {EVAL '{ my $var = 42 }; say $var'};
11+
throws_like {EVAL '{ my $var = 42 }; say $var'}, X::Undeclared;
1212

1313
sub counter($start_value) {
1414
my $count = $start_value;

integration/advent2011-day11.t

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,16 @@ $order.add_item('Gadget', 25.50);
5555
$order.add_item('Gizmo', 49.00);
5656

5757
lives_ok {$order.this-should-compile},'order total sanity';
58-
dies_ok {$order.but-this-shouldnt},'order total with typo';
58+
throws_like {$order.but-this-shouldnt},
59+
X::Method::NotFound,
60+
'order total with typo';
5961
lives_ok {EVAL '$order.discount'}, 'public method sanity';
60-
dies_ok {EVAL '$order!compute_discount'}, 'private method sanity';
61-
dies_ok {EVAL '$o!Order::compute_discount'}, 'private method sanity';
62+
throws_like {EVAL '$order!compute_discount'},
63+
X::Method::Private::Unqualified,
64+
'private method sanity';
65+
throws_like {EVAL '$o!Order::compute_discount'},
66+
X::Method::Private::Permission,
67+
'private method sanity';
6268

6369
# "...a class may choose to trust another one (or, indeed, any other package)
6470
# to be able to call its private methods. Critically, this is the decision of
@@ -86,5 +92,7 @@ $untrusty.add_item('Contrivance', 60.00);
8692
$untrusty.add_item('Apparatus', 50.00);
8793

8894
lives_ok {$untrusty.try-pub}, 'inheritance public method, (untrusting)';
89-
dies_ok {$untrusty.try-priv}, 'inheritance private method, (untrusting)';
95+
throws_like {$untrusty.try-priv},
96+
X::Method::Private::Permission,
97+
'inheritance private method, (untrusting)';
9098

integration/advent2011-day24.t

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@ multi sub Slurp($filename) {
3131
}
3232
--END--
3333
34-
eval_lives_ok $unambigous ~ 'Slurp("README.md")', 'unambigous multi - lives';
35-
eval_dies_ok $ambigous ~ 'Slurp("README.md")', 'ambigous multi - dies';
34+
lives_ok { EVAL $unambigous ~ 'Slurp("README.md")' },
35+
'unambigous multi - lives';
36+
throws_like { EVAL $ambigous ~ 'Slurp("README.md")' },
37+
X::Multi::Ambiguous,
38+
'ambigous multi - dies';
3639

3740
class Present {
3841
has $.item;
@@ -61,4 +64,3 @@ my $gift = Present.new(:item("sock"));
6164
is $gift.look, "It's wrapped.", "It's wrapped.";
6265
open($gift);
6366
is $gift.look, 'A sock!', 'A sock!';
64-

integration/advent2012-day13.t

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ my %words2 := baggy($slurp1);
2727
is_deeply %words1.keys.sort, %words1.keys.sort, 'standard vs baggy word-count';
2828
is_deeply %words1.values.sort, %words1.values.sort, 'standard vs baggy word-count';
2929
lives_ok {EVAL q<%words1{"the"} = "green">}, 'hash assign (lives)';
30-
dies_ok {EVAL q<%words2{"the"} = "green">}, 'baggy assign (dies)';
30+
throws_like {EVAL q<%words2{"the"} = "green">},
31+
X::Multi::NoMatch,
32+
'baggy assign (dies)';
3133

3234
# use {...}.Bag constructor (dwarring's reply to this post)
3335
# >my $bag = bag "red" => 2, "blue" => 10;

integration/advent2012-day19.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ is (4.7kΩ ± 1kΩ).gist, Measure.new(unit => Unit::ohm, value => 3700/1..5700/1
6464
is (4.7kΩ ± 5%).gist, Measure.new(unit => Unit::ohm, value => 4465/1..4935/1).gist, 'range object';
6565

6666
my $resistance = 4321Ω;
67-
dies_ok {die "resistance is futile" if !($resistance ~~ 4.7kΩ ± 5%)}, 'resistance is futile';
67+
nok $resistance ~~ 4.7kΩ ± 5%, 'resistance is futile';
6868

6969
# Symbols that aren’t operators
7070

integration/advent2013-day02.t

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ nok defined(Dog), 'Type object is undefined';
2222
ok $dog, 'instance is True';
2323
ok defined($dog), 'instance is defined';
2424
is $dog.name, 'Fido', 'Attribute access on instance';
25-
dies_ok { Dog.name }, 'Cannot access attribute on type object';
25+
throws_like { Dog.name },
26+
X::AdHoc, # does not have an Exception object yet
27+
'Cannot access attribute on type object';
2628

2729
multi sniff(Dog:U $dog) {
2830
return "a type object, of course"

0 commit comments

Comments
 (0)