fix incompatibilities with TB2
[gitmo/Moose.git] / t / test_moose / with_immutable_tb2.t
1 use strict;
2 use warnings;
3
4 use Test::More;
5
6 BEGIN {
7     use Test::More;
8     plan skip_all => 'These tests are only for Test::Builder 1.005+'
9         if Test::Builder->VERSION < 1.005;
10 }
11
12 {
13     package Foo;
14     use Moose;
15 }
16
17 {
18     package Bar;
19     use Moose;
20 }
21
22 package main;
23
24 use Test::Moose;
25 use TB2::Tester;
26 use TB2::History;   # FIXME - this should not need to be loaded here explicitly
27
28 my ($ret1, $ret2);
29 my $capture = capture {
30     $ret1 = with_immutable {
31         ok(Foo->meta->is_mutable, 'is mutable');
32     } qw(Foo);
33
34     $ret2 = with_immutable {
35         ok(Bar->meta->find_method_by_name('new'), 'can find "new" method');
36     } qw(Bar);
37 };
38
39 my $results = $capture->results;
40
41 my @tests = (
42     [
43         'first test runs while Foo is mutable' => { name => 'is mutable',
44                                                     is_pass => 1,
45                                                    },
46     ],
47     [
48         'first test runs while Foo is immutable' => { name => 'is mutable',
49                                                       is_pass => 0,
50                                                     },
51     ],
52     [
53         'can find "new" while Bar is mutable'   => { name => 'can find "new" method',
54                                                      is_pass => 1,
55                                                    },
56     ],
57     [
58         'can find "new" while Bar is immutable' => { name => 'can find "new" method',
59                                                      is_pass => 1,
60                                                    },
61     ],
62 );
63
64 result_like(shift(@$results), $_->[1], $_->[0]) foreach @tests;
65
66 ok(!$ret1, 'one of the is_immutable tests failed');
67 ok($ret2, 'the find_method_by_name tests passed');
68
69 done_testing;
70