complete re-organization of the test suite
[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     plan tests => 23;    
15 }
16
17 =pod
18
19 First lets test some of our simple example modules ...
20
21 =cut 
22
23 my @modules = qw[Foo Bar MyMooseA MyMooseB MyMooseObject];
24
25 do {
26     use_ok($_);
27     
28     is($_->meta->name, $_, '... initialized the meta correctly');
29     
30     lives_ok {
31         Module::Refresh->new->refresh_module($_ . '.pm')
32     } '... successfully refreshed ' . $_;    
33 } foreach @modules;
34
35 =pod
36
37 Now, lets try something a little trickier
38 and actually change the module itself.
39
40 =cut
41
42 my $test_module_file = 'TestBaz.pm';
43
44 my $test_module_source_1 = q|
45 package TestBaz;
46 use Moose;
47 has 'foo' => (is => 'ro', isa => 'Int');
48 1;
49 |;
50
51 my $test_module_source_2 = q|
52 package TestBaz;
53 use Moose;
54 extends 'Foo';
55 has 'foo' => (is => 'rw', isa => 'Int');
56 1;
57 |;
58
59 {
60     open FILE, ">", $test_module_file 
61         || die "Could not open $test_module_file because $!";
62     print FILE $test_module_source_1;
63     close FILE;
64 }
65
66 use_ok('TestBaz');
67 is(TestBaz->meta->name, 'TestBaz', '... initialized the meta correctly');
68 ok(TestBaz->meta->has_attribute('foo'), '... it has the foo attribute as well');
69 ok(!TestBaz->isa('Foo'), '... TestBaz is not a Foo');
70
71 {
72     open FILE, ">", $test_module_file 
73         || die "Could not open $test_module_file because $!";
74     print FILE $test_module_source_2;
75     close FILE;
76 }
77
78 lives_ok {
79     Module::Refresh->new->refresh_module($test_module_file)
80 } '... successfully refreshed ' . $test_module_file;
81
82 is(TestBaz->meta->name, 'TestBaz', '... initialized the meta correctly');
83 ok(TestBaz->meta->has_attribute('foo'), '... it has the foo attribute as well');
84 ok(TestBaz->isa('Foo'), '... TestBaz is a Foo');
85
86 unlink $test_module_file;
87
88
89
90
91