| 1 |
#!./perl -w |
| 2 |
|
| 3 |
BEGIN { |
| 4 |
unshift @INC, 't'; |
| 5 |
require Config; |
| 6 |
if (($Config::Config{'extensions'} !~ /\bB\b/) ){ |
| 7 |
print "1..0 # Skip -- Perl configured without B module\n"; |
| 8 |
exit 0; |
| 9 |
} |
| 10 |
require 'test.pl'; |
| 11 |
} |
| 12 |
|
| 13 |
use strict; |
| 14 |
|
| 15 |
plan( 9 ); # And someone's responsible. |
| 16 |
|
| 17 |
# use() makes it difficult to avoid O::import() |
| 18 |
require_ok( 'O' ); |
| 19 |
|
| 20 |
my @lines = get_lines( '-MO=success,foo,bar' ); |
| 21 |
|
| 22 |
is( $lines[0], 'Compiling!', 'Output should not be saved without -q switch' ); |
| 23 |
is( $lines[1], '(foo) <bar>', 'O.pm should call backend compile() method' ); |
| 24 |
is( $lines[2], '[]', 'Nothing should be in $O::BEGIN_output without -q' ); |
| 25 |
is( $lines[3], '-e syntax OK', 'O.pm should not munge perl output without -qq'); |
| 26 |
|
| 27 |
@lines = get_lines( '-MO=-q,success,foo,bar' ); |
| 28 |
isnt( $lines[1], 'Compiling!', 'Output should not be printed with -q switch' ); |
| 29 |
|
| 30 |
is( $lines[1], "[Compiling!", '... but should be in $O::BEGIN_output' ); |
| 31 |
|
| 32 |
@lines = get_lines( '-MO=-qq,success,foo,bar' ); |
| 33 |
is( scalar @lines, 3, '-qq should suppress even the syntax OK message' ); |
| 34 |
|
| 35 |
@lines = get_lines( '-MO=success,fail' ); |
| 36 |
like( $lines[1], qr/fail at .eval/, |
| 37 |
'O.pm should die if backend compile() does not return a subref' ); |
| 38 |
|
| 39 |
sub get_lines { |
| 40 |
my $compile = shift; |
| 41 |
split(/[\r\n]+/, runperl( switches => [ '-Ilib', '-It', $compile ], |
| 42 |
prog => 1, stderr => 1 )); |
| 43 |
} |