Commit | Line | Data |
4d5c0df2 |
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;"; |
d03bd989 |
13 | plan skip_all => "Module::Refresh is required for this test" if $@; |
14 | plan tests => 23; |
4d5c0df2 |
15 | } |
16 | |
a05c504e |
17 | =pod |
18 | |
19 | First lets test some of our simple example modules ... |
20 | |
d03bd989 |
21 | =cut |
a05c504e |
22 | |
23 | my @modules = qw[Foo Bar MyMooseA MyMooseB MyMooseObject]; |
24 | |
25 | do { |
26 | use_ok($_); |
d03bd989 |
27 | |
1808c2da |
28 | is($_->meta->name, $_, 'initialized the meta correctly'); |
d03bd989 |
29 | |
a05c504e |
30 | lives_ok { |
31 | Module::Refresh->new->refresh_module($_ . '.pm') |
1808c2da |
32 | } 'successfully refreshed ' . $_; |
a05c504e |
33 | } foreach @modules; |
34 | |
35 | =pod |
36 | |
c1c338c9 |
37 | Now, lets try something a little trickier |
38 | and actually change the module itself. |
a05c504e |
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 | { |
d03bd989 |
60 | open FILE, ">", $test_module_file |
a05c504e |
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'); |
1808c2da |
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'); |
a05c504e |
70 | |
71 | { |
d03bd989 |
72 | open FILE, ">", $test_module_file |
a05c504e |
73 | || die "Could not open $test_module_file because $!"; |
74 | print FILE $test_module_source_2; |
75 | close FILE; |
76 | } |
4d5c0df2 |
77 | |
78 | lives_ok { |
a05c504e |
79 | Module::Refresh->new->refresh_module($test_module_file) |
1808c2da |
80 | } 'successfully refreshed ' . $test_module_file; |
a05c504e |
81 | |
1808c2da |
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'); |
c1c338c9 |
85 | |
a05c504e |
86 | unlink $test_module_file; |
87 | |
88 | |
89 | |
90 | |
4d5c0df2 |
91 | |