From: Dave Rolsky Date: Sun, 20 May 2012 20:18:29 +0000 (-0500) Subject: More tests for handling of use Moose and MX modules X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a44ebace8aab59d8e99f88fee467faba645c07e8;p=gitmo%2FMooseX-Compiler.git More tests for handling of use Moose and MX modules --- diff --git a/t/remove-use-moose.t b/t/remove-use-moose.t index 5cb5d07..044fdf3 100644 --- a/t/remove-use-moose.t +++ b/t/remove-use-moose.t @@ -3,6 +3,10 @@ use warnings; use lib 't/lib'; +use Test::Requires { + 'MooseX::StrictConstructor' => '0.01', +}; + use Test::MooseX::Compiler qw( save_class ); use Test::More 0.88; @@ -29,6 +33,7 @@ EOF ); my $compiled = $compiler->compile_class(); + like( $compiled, qr/^\#\s*use Moose;\n/m, @@ -63,6 +68,7 @@ EOF ); my $compiled = $compiler->compile_class(); + unlike( $compiled, qr/^\#\s*use Moose;\n/m, @@ -76,4 +82,100 @@ 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 $compiler = MooseX::Compiler->new( + class => 'Test::Class1', + ); + + my $compiled = $compiler->compile_class(); + + like( + $compiled, + qr/^\#\s*use Moose;\n/m, + 'use Moose declaration is commented out in compiled code' + ); + + like( + $compiled, + qr/^\#\s*use MooseX::StrictConstructor;\n/m, + 'use MooseX::StrictConstructor declaration is commented out in compiled code' + ); + + unlike( + $compiled, + qr/^use Moose;\n/m, + 'original use Moose declaration is removed from compiled code' + ); + + unlike( + $compiled, + qr/^use MooseX::StrictConstructor;\n/m, + 'original use MooseX::StrictConstructor declaration is removed from compiled code' + ); +} + +{ + 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 $compiler = MooseX::Compiler->new( + class => 'Test::Class1', + ); + + my $compiled = $compiler->compile_class(); + + like( + $compiled, + qr/^\#\s*use Moose;\n/m, + 'use Moose declaration is commented out in compiled code' + ); + + unlike( + $compiled, + qr/^use Moose;\n/m, + 'original use Moose declaration is removed from compiled code' + ); + + unlike( + $compiled, + qr/^\#\s*use MooseX::StrictConstructor;\n/m, + 'use MooseX::StrictConstructor declaration is not commented out in compiled code' + ); + + like( + $compiled, + qr/^use\s+MooseX::StrictConstructor\s+0\.01\s+\(\)\s*;\n/m, + 'original use MooseX::StrictConstructor declaration is preserved, but () is added to prevent importing' + ); +} + done_testing();