Changelogging
[gitmo/Mouse.git] / t / 060_compat / 001_module_refresh_compat.t
CommitLineData
fde8e43f 1#!/usr/bin/perl
2# This is automatically generated by author/import-moose-test.pl.
3# DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!!
4use t::lib::MooseCompat;
5
6use strict;
7use warnings;
8
9use lib 't/lib', 'lib';
10
11use Test::More;
12use Test::Exception;
13
14use File::Spec;
15use File::Temp 'tempdir';
16
17use Test::Requires {
18 'Module::Refresh' => '0.01', # skip all if not installed
19};
20
21=pod
22
23First lets test some of our simple example modules ...
24
25=cut
26
27my @modules = qw[Foo Bar MyMooseA MyMooseB MyMooseObject];
28
29do {
30 use_ok($_);
31
32 is($_->meta->name, $_, '... initialized the meta correctly');
33
34 lives_ok {
35 Module::Refresh->new->refresh_module($_ . '.pm')
36 } '... successfully refreshed ' . $_;
37} foreach @modules;
38
39=pod
40
41Now, lets try something a little trickier
42and actually change the module itself.
43
44=cut
45
46my $dir = tempdir( "MooseTest-XXXXX", CLEANUP => 1, TMPDIR => 1 );
47push @INC, $dir;
48
49my $test_module_file = File::Spec->catdir($dir, 'TestBaz.pm');
50
51my $test_module_source_1 = q|
52package TestBaz;
53use Mouse;
54has 'foo' => (is => 'ro', isa => 'Int');
551;
56|;
57
58my $test_module_source_2 = q|
59package TestBaz;
60use Mouse;
61extends 'Foo';
62has 'foo' => (is => 'rw', isa => 'Int');
631;
64|;
65
66{
67 open FILE, ">", $test_module_file
68 || die "Could not open $test_module_file because $!";
69 print FILE $test_module_source_1;
70 close FILE;
71}
72
73use_ok('TestBaz');
74is(TestBaz->meta->name, 'TestBaz', '... initialized the meta correctly');
75ok(TestBaz->meta->has_attribute('foo'), '... it has the foo attribute as well');
76ok(!TestBaz->isa('Foo'), '... TestBaz is not a Foo');
77
78{
79 open FILE, ">", $test_module_file
80 || die "Could not open $test_module_file because $!";
81 print FILE $test_module_source_2;
82 close FILE;
83}
84
85lives_ok {
86 Module::Refresh->new->refresh_module('TestBaz.pm')
87} '... successfully refreshed ' . $test_module_file;
88
89is(TestBaz->meta->name, 'TestBaz', '... initialized the meta correctly');
90ok(TestBaz->meta->has_attribute('foo'), '... it has the foo attribute as well');
91ok(TestBaz->isa('Foo'), '... TestBaz is a Foo');
92
93unlink $test_module_file;
94
95done_testing;