1use strict;
2use warnings;
3
4use Test::More;
5use Test::Fatal;
6
7use Moose();
8
9{
10    my $exception = exception {
11        package Foo;
12        use Moose;
13        __PACKAGE__->meta->make_immutable;
14        __PACKAGE__->meta->superclasses("Bar");
15    };
16
17    like(
18        $exception,
19        qr/The 'superclasses' method is read-only when called on an immutable instance/,
20        "calling 'foo' on an immutable instance");
21
22    isa_ok(
23        $exception,
24        "Moose::Exception::CallingReadOnlyMethodOnAnImmutableInstance",
25        "calling 'foo' on an immutable instance");
26
27    is(
28        $exception->method_name,
29        "superclasses",
30        "calling 'foo' on an immutable instance");
31}
32
33{
34    my $exception = exception {
35        package Foo;
36        use Moose;
37        __PACKAGE__->meta->make_immutable;
38        __PACKAGE__->meta->add_method( foo => sub { "foo" } );
39    };
40
41    like(
42        $exception,
43        qr/The 'add_method' method cannot be called on an immutable instance/,
44        "calling 'add_method' on an immutable instance");
45
46    isa_ok(
47        $exception,
48        "Moose::Exception::CallingMethodOnAnImmutableInstance",
49        "calling 'add_method' on an immutable instance");
50
51    is(
52        $exception->method_name,
53        "add_method",
54        "calling 'add_method' on an immutable instance");
55}
56
57done_testing;
58