5 @INC = ('../lib', 'lib', '.');
7 if (($Config::Config{'extensions'} !~ /\bB\b/) ){
8 print "1..0 # Skip -- Perl configured without B module\n";
19 my $path = File::Spec->catdir( 'lib', 'B' );
21 mkpath( $path ) or skip_all( 'Cannot create fake module path' );
24 my $file = File::Spec->catfile( $path, 'success.pm' );
26 open(OUT, '>', $file) or skip_all( 'Cannot write fake backend module');
27 print OUT while <DATA>;
30 plan( 9 ); # And someone's responsible.
32 # use() makes it difficult to avoid O::import()
35 my @args = ('-Ilib', '-MO=success,foo,bar', '-e', '1' );
36 my @lines = get_lines( @args );
38 is( $lines[0], 'Compiling!', 'Output should not be saved without -q switch' );
39 is( $lines[1], '(foo) <bar>', 'O.pm should call backend compile() method' );
40 is( $lines[2], '[]', 'Nothing should be in $O::BEGIN_output without -q' );
41 is( $lines[3], '-e syntax OK', 'O.pm should not munge perl output without -qq');
43 $args[1] = '-MO=-q,success,foo,bar';
44 @lines = get_lines( @args );
45 isnt( $lines[1], 'Compiling!', 'Output should not be printed with -q switch' );
48 skip( '-q redirection does not work without PerlIO', 2)
49 unless $Config{useperlio};
50 is( $lines[1], "[Compiling!", '... but should be in $O::BEGIN_output' );
52 $args[1] = '-MO=-qq,success,foo,bar';
53 @lines = get_lines( @args );
54 is( scalar @lines, 3, '-qq should suppress even the syntax OK message' );
57 $args[1] = '-MO=success,fail';
58 @lines = get_lines( @args );
59 like( $lines[1], qr/fail at .eval/,
60 'O.pm should die if backend compile() does not return a subref' );
63 split(/[\r\n]+/, runperl( args => [ @_ ], stderr => 1 ));
67 1 while unlink($file);
68 rmdir($path); # not "1 while" since there might be more in there
78 return 'fail' if ($_[0] eq 'fail');
79 print "($_[0]) <$_[1]>\n";
80 return sub { print "[$O::BEGIN_output]\n" };