Convert all tests to done_testing.
[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 $@;
4d5c0df2 14}
15
a05c504e 16=pod
17
18First lets test some of our simple example modules ...
19
d03bd989 20=cut
a05c504e 21
22my @modules = qw[Foo Bar MyMooseA MyMooseB MyMooseObject];
23
24do {
25 use_ok($_);
d03bd989 26
a05c504e 27 is($_->meta->name, $_, '... initialized the meta correctly');
d03bd989 28
a05c504e 29 lives_ok {
30 Module::Refresh->new->refresh_module($_ . '.pm')
d03bd989 31 } '... successfully refreshed ' . $_;
a05c504e 32} foreach @modules;
33
34=pod
35
c1c338c9 36Now, lets try something a little trickier
37and actually change the module itself.
a05c504e 38
39=cut
40
41my $test_module_file = 'TestBaz.pm';
42
43my $test_module_source_1 = q|
44package TestBaz;
45use Moose;
46has 'foo' => (is => 'ro', isa => 'Int');
471;
48|;
49
50my $test_module_source_2 = q|
51package TestBaz;
52use Moose;
53extends 'Foo';
54has 'foo' => (is => 'rw', isa => 'Int');
551;
56|;
57
58{
d03bd989 59 open FILE, ">", $test_module_file
a05c504e 60 || die "Could not open $test_module_file because $!";
61 print FILE $test_module_source_1;
62 close FILE;
63}
64
65use_ok('TestBaz');
66is(TestBaz->meta->name, 'TestBaz', '... initialized the meta correctly');
c1c338c9 67ok(TestBaz->meta->has_attribute('foo'), '... it has the foo attribute as well');
68ok(!TestBaz->isa('Foo'), '... TestBaz is not a Foo');
a05c504e 69
70{
d03bd989 71 open FILE, ">", $test_module_file
a05c504e 72 || die "Could not open $test_module_file because $!";
73 print FILE $test_module_source_2;
74 close FILE;
75}
4d5c0df2 76
77lives_ok {
a05c504e 78 Module::Refresh->new->refresh_module($test_module_file)
79} '... successfully refreshed ' . $test_module_file;
80
c1c338c9 81is(TestBaz->meta->name, 'TestBaz', '... initialized the meta correctly');
82ok(TestBaz->meta->has_attribute('foo'), '... it has the foo attribute as well');
83ok(TestBaz->isa('Foo'), '... TestBaz is a Foo');
84
a05c504e 85unlink $test_module_file;
86
a28e50e4 87done_testing;