File: o.t

package info (click to toggle)
perl 5.8.4-8sarge6
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 58,128 kB
  • ctags: 31,422
  • sloc: perl: 224,262; ansic: 155,398; sh: 32,253; pascal: 7,747; lisp: 6,121; makefile: 2,341; cpp: 2,035; yacc: 1,019; java: 23
file content (78 lines) | stat: -rwxr-xr-x 1,973 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!./perl -w

BEGIN {
	chdir 't' if -d 't';
	@INC = ('../lib', 'lib', '.');
	require 'test.pl';
}

use strict;
use Config;
use File::Spec;
use File::Path;

my $path = File::Spec->catdir( 'lib', 'B' );
unless (-d $path) {
	mkpath( $path ) or skip_all( 'Cannot create fake module path' );
}

my $file = File::Spec->catfile( $path, 'success.pm' );
local *OUT;
open(OUT, '>', $file) or skip_all( 'Cannot write fake backend module');
print OUT while <DATA>;
close *OUT;

plan( 9 ); # And someone's responsible.

# use() makes it difficult to avoid O::import()
require_ok( 'O' );

my @args = ('-Ilib', '-MO=success,foo,bar', '-e', '1' );
my @lines = get_lines( @args );

is( $lines[0], 'Compiling!', 'Output should not be saved without -q switch' );
is( $lines[1], '(foo) <bar>', 'O.pm should call backend compile() method' );
is( $lines[2], '[]', 'Nothing should be in $O::BEGIN_output without -q' );
is( $lines[3], '-e syntax OK', 'O.pm should not munge perl output without -qq');

$args[1] = '-MO=-q,success,foo,bar';
@lines = get_lines( @args );
isnt( $lines[1], 'Compiling!', 'Output should not be printed with -q switch' );

SKIP: {
	skip( '-q redirection does not work without PerlIO', 2)
		unless $Config{useperlio};
	is( $lines[1], "[Compiling!", '... but should be in $O::BEGIN_output' );

	$args[1] = '-MO=-qq,success,foo,bar';
	@lines = get_lines( @args );
	is( scalar @lines, 3, '-qq should suppress even the syntax OK message' );
}

$args[1] = '-MO=success,fail';
@lines = get_lines( @args );
like( $lines[1], qr/fail at .eval/,
	'O.pm should die if backend compile() does not return a subref' );

sub get_lines {
	split(/[\r\n]+/, runperl( args => [ @_ ], stderr => 1 ));
}

END {
	1 while unlink($file);
	rmdir($path); # not "1 while" since there might be more in there
}

__END__
package B::success;

$| = 1;
print "Compiling!\n";

sub compile {
	return 'fail' if ($_[0] eq 'fail');
	print "($_[0]) <$_[1]>\n";
	return sub { print "[$O::BEGIN_output]\n" };
}

1;