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