From: Dave Rolsky Date: Sun, 20 May 2012 21:18:47 +0000 (-0500) Subject: Simplify test code a bit X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6029ad7beb4b3c7882674a9066ba56b2e2208d75;p=gitmo%2FMooseX-Compiler.git Simplify test code a bit --- diff --git a/t/lib/Test/MooseX/Compiler.pm b/t/lib/Test/MooseX/Compiler.pm index 765ced0..665a512 100644 --- a/t/lib/Test/MooseX/Compiler.pm +++ b/t/lib/Test/MooseX/Compiler.pm @@ -19,9 +19,20 @@ sub save_class { my $class = shift; my $code = shift; + my $full_code = <<"EOF"; +package $class; + +use strict; +use warnings; + +$code + +1; +EOF + { local $@; - eval $code; + eval $full_code; die $@ if $@; } @@ -30,7 +41,7 @@ sub save_class { $path->dir()->mkpath( 0, 0755 ); open my $fh, '>', $path; - print {$fh} $code; + print {$fh} $full_code; close $fh; $INC{$pm_file} = $path; diff --git a/t/remove-use-moose.t b/t/remove-use-moose.t index 044fdf3..f095a97 100644 --- a/t/remove-use-moose.t +++ b/t/remove-use-moose.t @@ -14,22 +14,16 @@ use MooseX::Compiler; { my $code = <<'EOF'; -package Test::Class1; - -use strict; -use warnings; - use Moose; sub foo { 42 } - -1; EOF - save_class( 'Test::Class1', $code ); + my $class = 'Test::Class1'; + save_class( $class, $code ); my $compiler = MooseX::Compiler->new( - class => 'Test::Class1', + class => $class, ); my $compiled = $compiler->compile_class(); @@ -49,11 +43,6 @@ EOF { my $code = <<'EOF'; -package Test::Class2; - -use strict; -use warnings; - use Moose 0.1; sub foo { 42 } @@ -61,10 +50,11 @@ sub foo { 42 } 1; EOF - save_class( 'Test::Class1', $code ); + my $class = 'Test::Class2'; + save_class( $class, $code ); my $compiler = MooseX::Compiler->new( - class => 'Test::Class1', + class => $class, ); my $compiled = $compiler->compile_class(); @@ -84,23 +74,17 @@ EOF { my $code = <<'EOF'; -package Test::Class3; - -use strict; -use warnings; - use Moose; use MooseX::StrictConstructor; sub foo { 42 } - -1; EOF - save_class( 'Test::Class1', $code ); + my $class = 'Test::Class3'; + save_class( $class, $code ); my $compiler = MooseX::Compiler->new( - class => 'Test::Class1', + class => $class, ); my $compiled = $compiler->compile_class(); @@ -132,23 +116,17 @@ EOF { my $code = <<'EOF'; -package Test::Class4; - -use strict; -use warnings; - use Moose; use MooseX::StrictConstructor 0.01; sub foo { 42 } - -1; EOF - save_class( 'Test::Class1', $code ); + my $class = 'Test::Class4'; + save_class( $class, $code ); my $compiler = MooseX::Compiler->new( - class => 'Test::Class1', + class => $class, ); my $compiled = $compiler->compile_class();