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