Convert all tests to done_testing.
[gitmo/Moose.git] / t / 060_compat / 001_module_refresh_compat.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use lib 't/lib', 'lib';
7
8 use Test::More;
9 use Test::Exception;
10
11 BEGIN {
12     eval "use Module::Refresh;";
13     plan skip_all => "Module::Refresh is required for this test" if $@;
14 }
15
16 =pod
17
18 First lets test some of our simple example modules ...
19
20 =cut
21
22 my @modules = qw[Foo Bar MyMooseA MyMooseB MyMooseObject];
23
24 do {
25     use_ok($_);
26
27     is($_->meta->name, $_, '... initialized the meta correctly');
28
29     lives_ok {
30         Module::Refresh->new->refresh_module($_ . '.pm')
31     } '... successfully refreshed ' . $_;
32 } foreach @modules;
33
34 =pod
35
36 Now, lets try something a little trickier
37 and actually change the module itself.
38
39 =cut
40
41 my $test_module_file = 'TestBaz.pm';
42
43 my $test_module_source_1 = q|
44 package TestBaz;
45 use Moose;
46 has 'foo' => (is => 'ro', isa => 'Int');
47 1;
48 |;
49
50 my $test_module_source_2 = q|
51 package TestBaz;
52 use Moose;
53 extends 'Foo';
54 has 'foo' => (is => 'rw', isa => 'Int');
55 1;
56 |;
57
58 {
59     open FILE, ">", $test_module_file
60         || die "Could not open $test_module_file because $!";
61     print FILE $test_module_source_1;
62     close FILE;
63 }
64
65 use_ok('TestBaz');
66 is(TestBaz->meta->name, 'TestBaz', '... initialized the meta correctly');
67 ok(TestBaz->meta->has_attribute('foo'), '... it has the foo attribute as well');
68 ok(!TestBaz->isa('Foo'), '... TestBaz is not a Foo');
69
70 {
71     open FILE, ">", $test_module_file
72         || die "Could not open $test_module_file because $!";
73     print FILE $test_module_source_2;
74     close FILE;
75 }
76
77 lives_ok {
78     Module::Refresh->new->refresh_module($test_module_file)
79 } '... successfully refreshed ' . $test_module_file;
80
81 is(TestBaz->meta->name, 'TestBaz', '... initialized the meta correctly');
82 ok(TestBaz->meta->has_attribute('foo'), '... it has the foo attribute as well');
83 ok(TestBaz->isa('Foo'), '... TestBaz is a Foo');
84
85 unlink $test_module_file;
86
87 done_testing;