Add a plan and tidied the code a little
[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;";
13 plan skip_all => "Module::Refresh is required for this test" if $@;
c1c338c9 14 plan tests => 23;
4d5c0df2 15}
16
a05c504e 17=pod
18
19First lets test some of our simple example modules ...
20
21=cut
22
23my @modules = qw[Foo Bar MyMooseA MyMooseB MyMooseObject];
24
25do {
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
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{
60 open FILE, ">", $test_module_file
61 || die "Could not open $test_module_file because $!";
62 print FILE $test_module_source_1;
63 close FILE;
64}
65
66use_ok('TestBaz');
67is(TestBaz->meta->name, 'TestBaz', '... initialized the meta correctly');
c1c338c9 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{
72 open FILE, ">", $test_module_file
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)
80} '... successfully refreshed ' . $test_module_file;
81
c1c338c9 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');
85
a05c504e 86unlink $test_module_file;
87
88
89
90
4d5c0df2 91