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;"; |
13 | plan skip_all => "Module::Refresh is required for this test" if $@; |
a05c504e |
14 | plan tests => 18; |
4d5c0df2 |
15 | } |
16 | |
a05c504e |
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 | |
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 | |
68 | { |
69 | open FILE, ">", $test_module_file |
70 | || die "Could not open $test_module_file because $!"; |
71 | print FILE $test_module_source_2; |
72 | close FILE; |
73 | } |
4d5c0df2 |
74 | |
75 | lives_ok { |
a05c504e |
76 | Module::Refresh->new->refresh_module($test_module_file) |
77 | } '... successfully refreshed ' . $test_module_file; |
78 | |
79 | unlink $test_module_file; |
80 | |
81 | |
82 | |
83 | |
4d5c0df2 |
84 | |