Skip to content

Commit 43146d9

Browse files
committed
Replace more eval-dies-ok with throws-like (S04)
1 parent c8dec0b commit 43146d9

File tree

14 files changed

+39
-38
lines changed

14 files changed

+39
-38
lines changed

S04-blocks-and-statements/pointy.t

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ is $str, 'inner', 'return in pointy returns from enclosing sub';
7777

7878
# -> { $^a, $^b } is illegal; you can't mix real sigs with placeholders,
7979
# and the -> introduces a sig of (). TimToady #perl6 2008-May-24
80-
eval-dies-ok(q{{ -> { $^a, $^b } }}, '-> { $^a, $^b } is illegal');
80+
throws-like q{{ -> { $^a, $^b } }}, X::Signature::Placeholder,
81+
'-> { $^a, $^b } is illegal';
8182

8283
# RT #61034
8384
lives-ok {my $x = -> {}; my $y = $x(); },

S04-declarations/constant.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ plan 63;
3232

3333
# RT #69740
3434
{
35-
eval-dies-ok 'constant ($a, $b) = (3, 4)', 'constant no longer takes list';
35+
throws-like 'constant ($a, $b) = (3, 4)', X::Syntax::Missing, 'constant no longer takes list';
3636
}
3737

3838
{
39-
eval-dies-ok 'constant %hash = "nothash"', 'constant hash requires Associative';
39+
throws-like 'constant %hash = "nothash"', X::TypeCheck, 'constant hash requires Associative';
4040
}
4141

4242
{

S04-declarations/implicit-parameter.t

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,15 @@ plan 20;
4343
is(-> $a { $_ }.(42), 'Ack!', 'Even with parameters');
4444
is(-> $_ { $_ }.(42), 42, 'But not when the parameter is $_');
4545

46-
eval-dies-ok( 'sub () { -> { $^a }.() }', 'Placeholders not allowed in ->');
46+
throws-like 'sub () { -> { $^a }.() }', X::Signature::Placeholder,
47+
'Placeholders not allowed in ->';
4748

4849
is(-> { }.arity, 0, '->{} is arity 0, again');
4950
}
5051

5152
{
52-
eval-dies-ok('sub () { $^foo }.(42)', 'Placeholders not allowed in sub()');
53+
throws-like 'sub () { $^foo }.(42)', X::Signature::Placeholder,
54+
'Placeholders not allowed in sub()';
5355
}
5456

5557
# RT #114696

S04-declarations/multiple.t

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ eval-lives-ok 'state $x; state $x',
2020
}
2121

2222
# this is not exactly S04 material
23-
eval-dies-ok 'sub foo {1; }; sub foo($x) {1; };',
24-
'multiple declarations need multi or proto';
23+
throws-like 'sub foo {1; }; sub foo($x) {1; };', X::Redeclaration,
24+
'multiple declarations need multi or proto';
2525

26-
eval-dies-ok 'only sub foo {1; }; sub foo($x) {1; };',
27-
'multiple declarations need multi or proto';
26+
throws-like 'only sub foo {1; }; sub foo($x) {1; };', X::Redeclaration,
27+
'multiple declarations need multi or proto';
2828

2929
#?niecza todo "MMD"
3030
#?rakudo todo 'nom regression RT #125053'

S04-declarations/my.t

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ plan 97;
77
# lexically scoped declarations are visible">
88
{
99

10-
eval-dies-ok('$x; my $x = 42', 'my() variable not yet visible prior to declaration');
10+
throws-like '$foo; my $foo = 42', X::Undeclared, 'my() variable not yet visible prior to declaration';
1111
is(EVAL('my $x = 42; $x'), 42, 'my() variable is visible now (2)');
1212
}
1313

1414

1515
{
1616
my $ret = 42;
17-
eval-dies-ok '$ret = $x ~ my $x;', 'my() variable not yet visible (1)';
17+
throws-like '$ret = $foo ~ my $foo;', X::Undeclared, 'my() variable not yet visible (1)';
1818
is $ret, 42, 'my() variable not yet visible (2)';
1919
}
2020

@@ -38,7 +38,7 @@ plan 97;
3838
is $was_in_sub, 42, 'calling a lexically defined my()-code var worked';
3939
}
4040

41-
eval-dies-ok 'foo(42)', 'my &foo is lexically scoped';
41+
throws-like 'foo(42)', X::Undeclared::Symbols, 'my &foo is lexically scoped';
4242

4343
{
4444
is(do {my $a = 3; $a}, 3, 'do{my $a = 3; $a} works');
@@ -64,7 +64,7 @@ if (1) { # create a new lexical scope
6464
my $b = 1;
6565
ok($b, '$b is available in this scope');
6666
}
67-
eval-dies-ok '$b', '$b is not available in this scope';
67+
throws-like '$b', X::Undeclared, '$b is not available in this scope';
6868

6969
# changing a lexical within a block retains the changed value
7070
my $c = 1;
@@ -105,7 +105,7 @@ $d;
105105
$func2 = sub { $e }; # one to access it
106106
}
107107

108-
eval-dies-ok '$e', '$e is not available in this scope';
108+
throws-like '$e', X::Undeclared, '$e is not available in this scope';
109109
is($func2(), 0, '$func2() just returns the $e lexical which is held by the closure');
110110
$func();
111111
is($func2(), 1, '$func() increments the $e lexical which is held by the closure');
@@ -191,7 +191,7 @@ throws-like 'my $z = $z', X::Syntax::Variable::Initializer, name => '$z';
191191
# (but they need to exist by CHECK)
192192
{
193193
eval-lives-ok '&x; 1; sub x {}', '&x does not need to be pre-declared';
194-
eval-dies-ok '&x()', '&x() dies when empty';
194+
throws-like '&x()', X::Undeclared::Symbols, '&x() dies when empty';
195195
}
196196

197197
# RT #62766

S04-declarations/our.t

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,22 @@ is($a, 3, '$a has changed'); # XXX is that right?
4343
our $d3 = 9;
4444
}
4545
{
46-
eval-dies-ok('$d3', "variables aren't seen within other lexical child blocks");
46+
throws-like '$d3', X::Undeclared, "variables aren't seen within other lexical child blocks";
4747
is($D2::d3, 9, "variables are seen within other lexical child blocks via package");
4848

4949
package D3 {
50-
eval-dies-ok('$d3', " ... and not from within child packages");
50+
throws-like '$d3', X::Undeclared, " ... and not from within child packages";
5151
is($D2::d3, 9, " ... and from within child packages via package");
5252
}
5353
}
54-
eval-dies-ok('d3', "variables do not leak from lexical blocks");
54+
throws-like 'd3', X::Undeclared::Symbols, "variables do not leak from lexical blocks";
5555
is($D2::d3, 9, "variables are seen from lexical blocks via pacakage");
5656
}
57-
eval-dies-ok('$d2', 'our() variable not yet visible outside its package');
58-
eval-dies-ok('$d3', 'our() variable not yet visible outside its package');
57+
throws-like '$d2', X::Undeclared, 'our() variable not yet visible outside its package';
58+
throws-like '$d3', X::Undeclared, 'our() variable not yet visible outside its package';
5959

6060
}
61-
eval-dies-ok('$d1', 'our() variable not yet visible outside its package');
61+
throws-like '$d1', X::Undeclared, 'our() variable not yet visible outside its package';
6262
}
6363

6464
# RT #100560, #102876

S04-exception-handlers/catch.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ lives-ok { do {die 'blah'; CATCH {default {}}}; }, 'do block with CATCH {default
227227
# RT #80864
228228
eval-lives-ok 'my %a; %a{ CATCH { } }', 'can define CATCH bock in .{}';
229229
# RT #73988
230-
eval-dies-ok 'do { CATCH {}; CATCH { } }', 'only one CATCH per block allowed';
230+
throws-like 'do { CATCH {}; CATCH { } }', X::Phaser::Multiple, 'only one CATCH per block allowed';
231231
# RT #115184
232232
eval-dies-ok 'try { CATCH { ~$! }; die }', "doesn't segfault";
233233

S04-statement-modifiers/for.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ plan 28;
100100
is $rt66622, 66622, 'statement modifier "for" makes no implicit block';
101101
}
102102

103-
eval-dies-ok '1 for <a b> for <c d>;', 'double statement-modifying for is not allowed';
103+
throws-like '1 for <a b> for <c d>;', X::Syntax::Confused, 'double statement-modifying for is not allowed';
104104

105105
# RT #66606
106106
{

S04-statements/if.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ if Mu { flunk('if (Mu) {} failed'); } else { pass('if (Mu) {} works'); }
109109
}
110110

111111
{
112-
eval-dies-ok('if 1; 2', '"if" requires a block');
112+
throws-like 'if 1; 2', X::Syntax::Missing, '"if" requires a block';
113113
}
114114

115115
# L<S04/"Conditional statements"/The value of the conditional expression may be optionally bound to a closure parameter>
@@ -209,7 +209,7 @@ is-deeply (if 0 { 42 } elsif 0 { 43 }), Empty, "if+elsif evaluates to () when no
209209
is-deeply (if 0 { 42 }), Empty, "if evaluates to () when no block chosen";
210210

211211
# L<S04/Statement parsing/keywords require whitespace>
212-
eval-dies-ok('if($x > 1) {}','keyword needs at least one whitespace after it');
212+
throws-like 'if($x > 1) {}', X::Comp::Group, 'keyword needs at least one whitespace after it';
213213

214214
# RT #76174
215215
# scoping of $_ in 'if' shouldn't break aliasing

S04-statements/loop.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ plan 15;
9797
eval-lives-ok('class A { has $!to; method x { loop { (:$!to); } } };', 'pair colon syntax in a loop refers to an attribute works');
9898

9999
# RT #63760
100-
eval-dies-ok 'loop { say "# RT63760"; last } while 1',
100+
throws-like 'loop { say "# RT63760"; last } while 1', X::Syntax::Confused,
101101
'"loop {} while" is a syntax error (RT 63760)';
102102

103103
# RT #112654

0 commit comments

Comments
 (0)