module refresh test
[gitmo/Moose.git] / t / 105_module_refresh_bug.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 $@;
a05c504e 14 plan tests => 18;
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
37Now, lets try something a little trickier ...
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{
59 open FILE, ">", $test_module_file
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');
67
68{
69 open FILE, ">", $test_module_file
70 || die "Could not open $test_module_file because $!";
71 print FILE $test_module_source_2;
72 close FILE;
73}
4d5c0df2 74
75lives_ok {
a05c504e 76 Module::Refresh->new->refresh_module($test_module_file)
77} '... successfully refreshed ' . $test_module_file;
78
79unlink $test_module_file;
80
81
82
83
4d5c0df2 84