Commit | Line | Data |
fde8e43f |
1 | #!/usr/bin/perl |
2 | # This is automatically generated by author/import-moose-test.pl. |
3 | # DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!! |
4 | use t::lib::MooseCompat; |
5 | |
6 | use strict; |
7 | use warnings; |
8 | |
9 | use lib 't/lib', 'lib'; |
10 | |
11 | use Test::More; |
12 | use Test::Exception; |
13 | |
14 | use File::Spec; |
15 | use File::Temp 'tempdir'; |
16 | |
17 | use Test::Requires { |
18 | 'Module::Refresh' => '0.01', # skip all if not installed |
19 | }; |
20 | |
21 | =pod |
22 | |
23 | First lets test some of our simple example modules ... |
24 | |
25 | =cut |
26 | |
27 | my @modules = qw[Foo Bar MyMooseA MyMooseB MyMooseObject]; |
28 | |
29 | do { |
30 | use_ok($_); |
31 | |
32 | is($_->meta->name, $_, '... initialized the meta correctly'); |
33 | |
34 | lives_ok { |
35 | Module::Refresh->new->refresh_module($_ . '.pm') |
36 | } '... successfully refreshed ' . $_; |
37 | } foreach @modules; |
38 | |
39 | =pod |
40 | |
41 | Now, lets try something a little trickier |
42 | and actually change the module itself. |
43 | |
44 | =cut |
45 | |
46 | my $dir = tempdir( "MooseTest-XXXXX", CLEANUP => 1, TMPDIR => 1 ); |
47 | push @INC, $dir; |
48 | |
49 | my $test_module_file = File::Spec->catdir($dir, 'TestBaz.pm'); |
50 | |
51 | my $test_module_source_1 = q| |
52 | package TestBaz; |
53 | use Mouse; |
54 | has 'foo' => (is => 'ro', isa => 'Int'); |
55 | 1; |
56 | |; |
57 | |
58 | my $test_module_source_2 = q| |
59 | package TestBaz; |
60 | use Mouse; |
61 | extends 'Foo'; |
62 | has 'foo' => (is => 'rw', isa => 'Int'); |
63 | 1; |
64 | |; |
65 | |
66 | { |
67 | open FILE, ">", $test_module_file |
68 | || die "Could not open $test_module_file because $!"; |
69 | print FILE $test_module_source_1; |
70 | close FILE; |
71 | } |
72 | |
73 | use_ok('TestBaz'); |
74 | is(TestBaz->meta->name, 'TestBaz', '... initialized the meta correctly'); |
75 | ok(TestBaz->meta->has_attribute('foo'), '... it has the foo attribute as well'); |
76 | ok(!TestBaz->isa('Foo'), '... TestBaz is not a Foo'); |
77 | |
78 | { |
79 | open FILE, ">", $test_module_file |
80 | || die "Could not open $test_module_file because $!"; |
81 | print FILE $test_module_source_2; |
82 | close FILE; |
83 | } |
84 | |
85 | lives_ok { |
86 | Module::Refresh->new->refresh_module('TestBaz.pm') |
87 | } '... successfully refreshed ' . $test_module_file; |
88 | |
89 | is(TestBaz->meta->name, 'TestBaz', '... initialized the meta correctly'); |
90 | ok(TestBaz->meta->has_attribute('foo'), '... it has the foo attribute as well'); |
91 | ok(TestBaz->isa('Foo'), '... TestBaz is a Foo'); |
92 | |
93 | unlink $test_module_file; |
94 | |
95 | done_testing; |