version bump
[gitmo/Moose.git] / t / compat / 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;
b10dde3a 9use Test::Fatal;
4d5c0df2 10
bcbb2654 11use File::Spec;
12use File::Temp 'tempdir';
13
4d438a84 14use Test::Requires {
15 'Module::Refresh' => '0.01', # skip all if not installed
16};
4d5c0df2 17
a05c504e 18=pod
19
20First lets test some of our simple example modules ...
21
d03bd989 22=cut
a05c504e 23
24my @modules = qw[Foo Bar MyMooseA MyMooseB MyMooseObject];
25
26do {
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 38Now, lets try something a little trickier
39and actually change the module itself.
a05c504e 40
41=cut
42
e82d8944 43my $dir = tempdir( "MooseTest-XXXXX", CLEANUP => 1, TMPDIR => 1 );
bcbb2654 44push @INC, $dir;
45
46my $test_module_file = File::Spec->catdir($dir, 'TestBaz.pm');
a05c504e 47
48my $test_module_source_1 = q|
49package TestBaz;
50use Moose;
51has 'foo' => (is => 'ro', isa => 'Int');
521;
53|;
54
55my $test_module_source_2 = q|
56package TestBaz;
57use Moose;
58extends 'Foo';
59has 'foo' => (is => 'rw', isa => 'Int');
601;
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
70use_ok('TestBaz');
71is(TestBaz->meta->name, 'TestBaz', '... initialized the meta correctly');
c1c338c9 72ok(TestBaz->meta->has_attribute('foo'), '... it has the foo attribute as well');
73ok(!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 82is( exception {
cf502796 83 Module::Refresh->new->refresh_module('TestBaz.pm')
b10dde3a 84}, undef, '... successfully refreshed ' );
a05c504e 85
c1c338c9 86is(TestBaz->meta->name, 'TestBaz', '... initialized the meta correctly');
87ok(TestBaz->meta->has_attribute('foo'), '... it has the foo attribute as well');
88ok(TestBaz->isa('Foo'), '... TestBaz is a Foo');
89
a05c504e 90unlink $test_module_file;
91
a28e50e4 92done_testing;