Commit | Line | Data |
d4e33868 |
1 | #!./perl -w |
2 | |
3 | BEGIN { |
4 | chdir 't' if -d 't'; |
5 | @INC = ('../lib', 'lib', '.'); |
6 | require 'test.pl'; |
7 | } |
8 | |
9 | use strict; |
10 | use Config; |
11 | use File::Spec; |
12 | use File::Path; |
13 | |
14 | my $path = File::Spec->catdir( 'lib', 'B' ); |
15 | unless (-d $path) { |
16 | mkpath( $path ) or skip_all( 'Cannot create fake module path' ); |
17 | } |
18 | |
19 | my $file = File::Spec->catfile( $path, 'success.pm' ); |
20 | local *OUT; |
21 | open(OUT, '>', $file) or skip_all( 'Cannot write fake backend module'); |
22 | print OUT while <DATA>; |
23 | close *OUT; |
24 | |
25 | plan( 9 ); # And someone's responsible. |
26 | |
27 | # use() makes it difficult to avoid O::import() |
28 | require_ok( 'O' ); |
29 | |
30 | my @args = ('-Ilib', '-MO=success,foo,bar', '-e', '1' ); |
31 | my @lines = get_lines( @args ); |
32 | |
33 | is( $lines[0], '-e syntax OK', 'O.pm should not munge perl output without -qq'); |
34 | is( $lines[1], 'Compiling!', 'Output should not be saved without -q switch' ); |
35 | is( $lines[2], '(foo) <bar>', 'O.pm should call backend compile() method' ); |
36 | is( $lines[3], '[]', 'Nothing should be in $O::BEGIN_output without -q' ); |
37 | |
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' ); |
41 | |
42 | SKIP: { |
43 | skip( '-q redirection does not work without PerlIO', 2) |
44 | unless $Config{useperlio}; |
45 | is( $lines[2], "[Compiling!", '... but should be in $O::BEGIN_output' ); |
46 | |
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' ); |
50 | } |
51 | |
52 | $args[1] = '-MO=success,fail'; |
53 | @lines = get_lines( @args ); |
54 | like( $lines[0], qr/fail at .eval/, |
55 | 'O.pm should die if backend compile() does not return a subref' ); |
56 | |
57 | sub get_lines { |
58 | split(/[\r\n]+/, runperl( args => [ @_ ], stderr => 1 )); |
59 | } |
60 | |
61 | END { |
62 | 1 while unlink($file); |
63 | } |
64 | |
65 | __END__ |
66 | package B::success; |
67 | |
68 | print "Compiling!\n"; |
69 | |
70 | sub compile { |
71 | return 'fail' if ($_[0] eq 'fail'); |
72 | print "($_[0]) <$_[1]>\n"; |
73 | return sub { print "[$O::BEGIN_output]\n" }; |
74 | } |
75 | |
76 | 1; |