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