1N/A#!./perl -w
1N/A
1N/ABEGIN {
1N/A chdir 't' if -d 't';
1N/A @INC = ('../lib', 'lib', '.');
1N/A require 'test.pl';
1N/A}
1N/A
1N/Ause strict;
1N/Ause Config;
1N/Ause File::Spec;
1N/Ause File::Path;
1N/A
1N/Amy $path = File::Spec->catdir( 'lib', 'B' );
1N/Aunless (-d $path) {
1N/A mkpath( $path ) or skip_all( 'Cannot create fake module path' );
1N/A}
1N/A
1N/Amy $file = File::Spec->catfile( $path, 'success.pm' );
1N/Alocal *OUT;
1N/Aopen(OUT, '>', $file) or skip_all( 'Cannot write fake backend module');
1N/Aprint OUT while <DATA>;
1N/Aclose *OUT;
1N/A
1N/Aplan( 9 ); # And someone's responsible.
1N/A
1N/A# use() makes it difficult to avoid O::import()
1N/Arequire_ok( 'O' );
1N/A
1N/Amy @args = ('-Ilib', '-MO=success,foo,bar', '-e', '1' );
1N/Amy @lines = get_lines( @args );
1N/A
1N/Ais( $lines[0], 'Compiling!', 'Output should not be saved without -q switch' );
1N/Ais( $lines[1], '(foo) <bar>', 'O.pm should call backend compile() method' );
1N/Ais( $lines[2], '[]', 'Nothing should be in $O::BEGIN_output without -q' );
1N/Ais( $lines[3], '-e syntax OK', 'O.pm should not munge perl output without -qq');
1N/A
1N/A$args[1] = '-MO=-q,success,foo,bar';
1N/A@lines = get_lines( @args );
1N/Aisnt( $lines[1], 'Compiling!', 'Output should not be printed with -q switch' );
1N/A
1N/ASKIP: {
1N/A skip( '-q redirection does not work without PerlIO', 2)
1N/A unless $Config{useperlio};
1N/A is( $lines[1], "[Compiling!", '... but should be in $O::BEGIN_output' );
1N/A
1N/A $args[1] = '-MO=-qq,success,foo,bar';
1N/A @lines = get_lines( @args );
1N/A is( scalar @lines, 3, '-qq should suppress even the syntax OK message' );
1N/A}
1N/A
1N/A$args[1] = '-MO=success,fail';
1N/A@lines = get_lines( @args );
1N/Alike( $lines[1], qr/fail at .eval/,
1N/A 'O.pm should die if backend compile() does not return a subref' );
1N/A
1N/Asub get_lines {
1N/A split(/[\r\n]+/, runperl( args => [ @_ ], stderr => 1 ));
1N/A}
1N/A
1N/AEND {
1N/A 1 while unlink($file);
1N/A rmdir($path); # not "1 while" since there might be more in there
1N/A}
1N/A
1N/A__END__
1N/Apackage B::success;
1N/A
1N/A$| = 1;
1N/Aprint "Compiling!\n";
1N/A
1N/Asub compile {
1N/A return 'fail' if ($_[0] eq 'fail');
1N/A print "($_[0]) <$_[1]>\n";
1N/A return sub { print "[$O::BEGIN_output]\n" };
1N/A}
1N/A
1N/A1;