Eviscerate README.macos to match the state of the world
[p5sagit/p5-mst-13.2.git] / ext / B / t / o.t
CommitLineData
d4e33868 1#!./perl -w
2
3BEGIN {
74517a3a 4 unshift @INC, 't';
9cd8f857 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 }
d4e33868 10 require 'test.pl';
11}
12
13use strict;
14use Config;
15use File::Spec;
16use File::Path;
17
18my $path = File::Spec->catdir( 'lib', 'B' );
19unless (-d $path) {
20 mkpath( $path ) or skip_all( 'Cannot create fake module path' );
21}
22
23my $file = File::Spec->catfile( $path, 'success.pm' );
24local *OUT;
25open(OUT, '>', $file) or skip_all( 'Cannot write fake backend module');
26print OUT while <DATA>;
27close *OUT;
28
29plan( 9 ); # And someone's responsible.
30
31# use() makes it difficult to avoid O::import()
32require_ok( 'O' );
33
34my @args = ('-Ilib', '-MO=success,foo,bar', '-e', '1' );
35my @lines = get_lines( @args );
36
9e6e1fbb 37is( $lines[0], 'Compiling!', 'Output should not be saved without -q switch' );
38is( $lines[1], '(foo) <bar>', 'O.pm should call backend compile() method' );
39is( $lines[2], '[]', 'Nothing should be in $O::BEGIN_output without -q' );
40is( $lines[3], '-e syntax OK', 'O.pm should not munge perl output without -qq');
d4e33868 41
42$args[1] = '-MO=-q,success,foo,bar';
43@lines = get_lines( @args );
44isnt( $lines[1], 'Compiling!', 'Output should not be printed with -q switch' );
45
46SKIP: {
47 skip( '-q redirection does not work without PerlIO', 2)
48 unless $Config{useperlio};
9e6e1fbb 49 is( $lines[1], "[Compiling!", '... but should be in $O::BEGIN_output' );
d4e33868 50
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' );
54}
55
56$args[1] = '-MO=success,fail';
57@lines = get_lines( @args );
9e6e1fbb 58like( $lines[1], qr/fail at .eval/,
d4e33868 59 'O.pm should die if backend compile() does not return a subref' );
60
61sub get_lines {
62 split(/[\r\n]+/, runperl( args => [ @_ ], stderr => 1 ));
63}
64
65END {
66 1 while unlink($file);
7589e17d 67 rmdir($path); # not "1 while" since there might be more in there
d4e33868 68}
69
70__END__
71package B::success;
72
9e6e1fbb 73$| = 1;
d4e33868 74print "Compiling!\n";
75
76sub compile {
77 return 'fail' if ($_[0] eq 'fail');
78 print "($_[0]) <$_[1]>\n";
79 return sub { print "[$O::BEGIN_output]\n" };
80}
81
821;