summaryrefslogtreecommitdiff
path: root/t/compat/module_refresh_compat.t
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2015-06-06 17:50:16 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2015-06-06 17:50:16 +0000
commit5ac2026f7eed78958d69d051e7a8e993dcf51205 (patch)
tree298c3d2f08bdfe5689998b11892d72a897985be1 /t/compat/module_refresh_compat.t
downloadMoose-tarball-5ac2026f7eed78958d69d051e7a8e993dcf51205.tar.gz
Diffstat (limited to 't/compat/module_refresh_compat.t')
-rw-r--r--t/compat/module_refresh_compat.t88
1 files changed, 88 insertions, 0 deletions
diff --git a/t/compat/module_refresh_compat.t b/t/compat/module_refresh_compat.t
new file mode 100644
index 0000000..a3a627b
--- /dev/null
+++ b/t/compat/module_refresh_compat.t
@@ -0,0 +1,88 @@
+use strict;
+use warnings;
+
+use lib 't/lib';
+
+use Test::More;
+use Test::Fatal;
+
+use File::Spec;
+use File::Temp 'tempdir';
+
+use Test::Requires 'Module::Refresh'; # skip all if not installed
+
+=pod
+
+First lets test some of our simple example modules ...
+
+=cut
+
+my @modules = qw[Foo Bar MyMooseA MyMooseB MyMooseObject];
+
+do {
+ use_ok($_);
+
+ is($_->meta->name, $_, '... initialized the meta correctly');
+
+ is( exception {
+ Module::Refresh->new->refresh_module($_ . '.pm')
+ }, undef, '... successfully refreshed ' );
+} foreach @modules;
+
+=pod
+
+Now, lets try something a little trickier
+and actually change the module itself.
+
+=cut
+
+my $dir = tempdir( "MooseTest-XXXXX", CLEANUP => 1, TMPDIR => 1 );
+push @INC, $dir;
+
+my $test_module_file = File::Spec->catdir($dir, 'TestBaz.pm');
+
+my $test_module_source_1 = q|
+package TestBaz;
+use Moose;
+has 'foo' => (is => 'ro', isa => 'Int');
+1;
+|;
+
+my $test_module_source_2 = q|
+package TestBaz;
+use Moose;
+extends 'Foo';
+has 'foo' => (is => 'rw', isa => 'Int');
+1;
+|;
+
+{
+ open FILE, ">", $test_module_file
+ || die "Could not open $test_module_file because $!";
+ print FILE $test_module_source_1;
+ close FILE;
+}
+
+use_ok('TestBaz');
+is(TestBaz->meta->name, 'TestBaz', '... initialized the meta correctly');
+ok(TestBaz->meta->has_attribute('foo'), '... it has the foo attribute as well');
+ok(!TestBaz->isa('Foo'), '... TestBaz is not a Foo');
+
+{
+ open FILE, ">", $test_module_file
+ || die "Could not open $test_module_file because $!";
+ print FILE $test_module_source_2;
+ close FILE;
+}
+
+is( exception {
+ Module::Refresh->new->refresh_module('TestBaz.pm')
+}, undef, '... successfully refreshed ' );
+
+is(TestBaz->meta->name, 'TestBaz', '... initialized the meta correctly');
+ok(TestBaz->meta->has_attribute('foo'), '... it has the foo attribute as well');
+ok(TestBaz->isa('Foo'), '... TestBaz is a Foo');
+
+unlink $test_module_file;
+
+done_testing;