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