DEATH TO ALL zionist ELLIPSES
[gitmo/Moose.git] / t / 060_compat / 001_module_refresh_compat.t
CommitLineData
4d5c0df2 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use lib 't/lib', 'lib';
7
8use Test::More;
9use Test::Exception;
10
11BEGIN {
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
19First lets test some of our simple example modules ...
20
d03bd989 21=cut
a05c504e 22
23my @modules = qw[Foo Bar MyMooseA MyMooseB MyMooseObject];
24
25do {
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 37Now, lets try something a little trickier
38and actually change the module itself.
a05c504e 39
40=cut
41
42my $test_module_file = 'TestBaz.pm';
43
44my $test_module_source_1 = q|
45package TestBaz;
46use Moose;
47has 'foo' => (is => 'ro', isa => 'Int');
481;
49|;
50
51my $test_module_source_2 = q|
52package TestBaz;
53use Moose;
54extends 'Foo';
55has 'foo' => (is => 'rw', isa => 'Int');
561;
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
66use_ok('TestBaz');
1808c2da 67is(TestBaz->meta->name, 'TestBaz', 'initialized the meta correctly');
68ok(TestBaz->meta->has_attribute('foo'), 'it has the foo attribute as well');
69ok(!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
78lives_ok {
a05c504e 79 Module::Refresh->new->refresh_module($test_module_file)
1808c2da 80} 'successfully refreshed ' . $test_module_file;
a05c504e 81
1808c2da 82is(TestBaz->meta->name, 'TestBaz', 'initialized the meta correctly');
83ok(TestBaz->meta->has_attribute('foo'), 'it has the foo attribute as well');
84ok(TestBaz->isa('Foo'), 'TestBaz is a Foo');
c1c338c9 85
a05c504e 86unlink $test_module_file;
87
88
89
90
4d5c0df2 91