Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Replace some eval-dies-ok in S12-* with throws-like
  • Loading branch information
usev6 committed Sep 27, 2015
1 parent 4321092 commit 9d54b21
Show file tree
Hide file tree
Showing 14 changed files with 29 additions and 17 deletions.
11 changes: 9 additions & 2 deletions S12-attributes/inheritance.t
Expand Up @@ -21,7 +21,8 @@ is $o.accessor, 'blubb', 'accessor can use inherited attribute';
class Artie61500 {
has $!p = 61500;
}
eval-dies-ok 'class Artay61500 is Artie61500 { method bomb { return $!p } }',
throws-like 'class Artay61500 is Artie61500 { method bomb { return $!p } }',
X::Attribute::Undeclared,
'Compile error for subclass to access private attribute of parent';

class Parent {
Expand Down Expand Up @@ -49,7 +50,13 @@ nok $child.report.defined,

# RT #61500
{
eval-dies-ok 'class A { has $!foo = 7 }; class B is A { method x { say $!foo } }; B.new.x', 'rt 61500';
throws-like q{
class RT61500_A { has $!foo = 7 };
class RT61500_B is RT61500_A { method x { say $!foo } };
RT61500_B.new.x
},
X::Attribute::Undeclared,
'rt 61500';
}

# vim: ft=perl6
3 changes: 2 additions & 1 deletion S12-class/anonymous.t
Expand Up @@ -70,6 +70,7 @@ is($t3.x, 42, 'anonymous classes can have attributes');
}

# RT #80024
eval-dies-ok q[anon class C { }; C.WHAT; ], 'anon class is actually anon';
throws-like q[anon class C { }; C.WHAT; ], X::Undeclared::Symbols,
'anon class is actually anon';

# vim: ft=perl6
4 changes: 2 additions & 2 deletions S12-class/attributes.t
Expand Up @@ -107,13 +107,13 @@ is($bar.bar[2], 300, 'array attribute initialized/works');
}

# RT 81718
eval-dies-ok q[
throws-like q[
class RT81718 {
has $.bughunt is rw;
sub bomb { "life is a $.bughunt" }
method meta_bomb { "the good " ~ bomb() }
}
], 'no attr access for sub inside class';
], X::Syntax::NoSelf, 'no attr access for sub inside class';

# RT 74850
#?niecza skip "Unhandled exception: Unable to resolve method ctxzyg in type Method"
Expand Down
3 changes: 2 additions & 1 deletion S12-class/declaration-order.t
Expand Up @@ -15,6 +15,7 @@ A class can only derive already declared classes.

# need eval-lives-ok here because class declarations happen at compile time
eval-lives-ok ' class A {}; class B is A {}; ', "base before derived: lives";
eval-dies-ok ' class D is C {}; class C {}; ', "derived before base: dies";
throws-like ' class D is C {}; class C {}; ', X::Inheritance::UnknownParent,
"derived before base: dies";

# vim: ft=perl6
2 changes: 1 addition & 1 deletion S12-class/lexical.t
Expand Up @@ -17,7 +17,7 @@ eval-lives-ok '{ my class B {} }; { my class B {} }',
'declare classes with the same name in two scopes.';
eval-lives-ok '{ my class B {}; B.new; }',
'can instantiate lexical class';
eval-dies-ok '{ my class B {}; B.new; }; B.new',
throws-like '{ my class B {}; B.new; }; B.new', X::Undeclared::Symbols,
'scope is correctly restricted';

{
Expand Down
3 changes: 2 additions & 1 deletion S12-class/magical-vars.t
Expand Up @@ -119,7 +119,8 @@ class SimpleClass does Bar {}
}

{
eval-dies-ok 'self' , "there is no self outside of a method";
throws-like 'self', X::Syntax::Self::WithoutObject,
"there is no self outside of a method";
}

# vim: ft=perl6
2 changes: 1 addition & 1 deletion S12-class/namespaced.t
Expand Up @@ -40,7 +40,7 @@ class A {
is(A::B.new.x, 2, 'called correct method on class A::B');
is(A::B.new.y, 'b', 'could access attribute in class A::B');
is(A::B.new.z, 'b', 'method access correct attribute in class A::B');
eval-dies-ok(q{ B.new }, 'class A::B not available outside of class as B');
throws-like q{ B.new }, X::Undeclared::Symbols, 'class A::B not available outside of class as B';
}

class C {
Expand Down
4 changes: 2 additions & 2 deletions S12-class/self-inheritance.t
Expand Up @@ -12,8 +12,8 @@ audreyt I suspect compile time is the correct answer
=end pod

eval-dies-ok 'role RA does RA { }; 1', "Testing `role A does A`";
eval-dies-ok 'class CA is CA { }; 1', "Testing `class A is A`";
throws-like 'role RA does RA { }; 1', X::InvalidType, "Testing `role A does A`";
throws-like 'class CA is CA { }; 1', X::Inheritance::SelfInherit, "Testing `class A is A`";


# vim: ft=perl6
3 changes: 2 additions & 1 deletion S12-class/stubs.t
Expand Up @@ -23,7 +23,8 @@ lives-ok { sub {...} }, 'not execued stub code is fine';
dies-ok { (sub {...}).() ~ '' }, 'execued stub code goes BOOM when used';
dies-ok { use fatal; (sub { ... }).() }, 'exeucted stub code goes BOOM under fatal';

eval-dies-ok q[my class StubbedButNotDeclared { ... }], 'stubbing a class but not providing a definition dies';
throws-like q[my class StubbedButNotDeclared { ... }], X::Package::Stubbed,
'stubbing a class but not providing a definition dies';

# RT #81060
{
Expand Down
2 changes: 1 addition & 1 deletion S12-coercion/coercion-types.t
Expand Up @@ -13,7 +13,7 @@ plan 18;
}
isa-ok f(42), Str, 'Coercion type coerces';
is f(42), '42', 'Coercion type coerces to correct value';
eval-dies-ok q[ sub g(Str(Cool) $x) { $x }; g(Any) ],
throws-like q[ sub g(Str(Cool) $x) { $x }; g(Any) ], X::TypeCheck::Binding,
'coercion type still type-checks';
}

Expand Down
3 changes: 2 additions & 1 deletion S12-methods/indirect_notation.t
Expand Up @@ -44,7 +44,8 @@ class T2 {
is( a($o: $seed), $seed, "The indirect object notation call with argument with ()" );

my $name = 'a';
eval-dies-ok('$name $o: $seed', 'Indirect object notation and indirect method calls cannot be combined');
throws-like '$name $o: $seed', X::Syntax::Confused,
'Indirect object notation and indirect method calls cannot be combined';

#?niecza 2 skip 'Invocant handling is NYI'
is (b $o: 21, 21), 42, "The indirect object notation call with multiple arguments without ()";
Expand Down
2 changes: 1 addition & 1 deletion S12-methods/syntax.t
Expand Up @@ -16,7 +16,7 @@ $_ = A.new();

is .doit, 'empty', 'plain call with no args';
is .doit(), 'empty', 'method call with parens and no args';
eval-dies-ok '.doit ()', '.doit () illegal';
throws-like '.doit ()', X::Syntax::Confused, '.doit () illegal';
is .doit\ (), 'empty', 'method call with unspace';

is (.doit: 1, 2, 3), 'a:1|b:2!3', 'list op with colon';
Expand Down
2 changes: 1 addition & 1 deletion S12-methods/trusts.t
Expand Up @@ -20,7 +20,7 @@ class Trustee {
}
}

eval-dies-ok 'Truster.new()!Truster::get-x-priv',
throws-like 'Truster.new()!Truster::get-x-priv', X::Method::Private::Permission,
'can not access private method without a trust';
is Trustee.x(Truster.new(x => 5)), 5, 'can access private method with trust';
is Trustee.x(ChildTruster.new(x => 5)), 5, 'can access private method with trust + subclass';
Expand Down
2 changes: 1 addition & 1 deletion S12-subset/subtypes.t
Expand Up @@ -106,7 +106,7 @@ Tests subtypes, specifically in the context of multimethod dispatch.
{
subset HasA of Str where /a/;
lives-ok { my HasA $x = 'bla' }, 'where /regex/ works (positive)';
eval-dies-ok 'my HasA $x = "foo"', 'where /regex/ works (negative)';
throws-like 'my HasA $x = "foo"', X::TypeCheck::Assignment, 'where /regex/ works (negative)';
}

# You can write just an expression rather than a block after where in a sub
Expand Down

0 comments on commit 9d54b21

Please sign in to comment.