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