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