Move Test::Harness from ext/ to cpan/
[p5sagit/p5-mst-13.2.git] / cpan / Test-Harness / t / nofork.t
CommitLineData
b965d173 1#!/usr/bin/perl -w
2
3# check nofork logic on systems which *can* fork()
4# NOTE maybe a good candidate for xt/author or something.
5
2adbc9b6 6use lib 't/lib';
b965d173 7
8use strict;
9
10use Config;
11use Test::More (
12 $Config{d_fork}
13 ? 'no_plan'
14 : ( 'skip_all' => 'your system already has no fork' )
15);
16use IO::c55Capture; # for util
17
18use TAP::Harness;
19
20sub backticks {
21 my (@args) = @_;
22
23 util::stdout_of( sub { system(@args) and die "error $?" } );
24}
25
5e2a19fc 26my @libs = map "-I$_", @INC;
27my @perl = ( $^X, @libs );
b965d173 28my $mod = 'TAP::Parser::Iterator::Process';
29
30{ # just check the introspective method to start...
31 my $code = qq(print $mod->_use_open3 ? 1 : 2);
32 {
33 my $ans = backticks( @perl, '-MNoFork', "-M$mod", '-e', $code );
34 is( $ans, 2, 'says not to fork' );
35 }
36 {
37 local $ENV{PERL5OPT}; # punt: prevent propogating -MNoFork
38 my $ans = backticks( @perl, "-M$mod", '-e', $code );
39 is( $ans, 1, 'says to fork' );
40 }
41}
42
43{ # and make sure we can run a test
44 my $capture = IO::c55Capture->new_handle;
45 local *STDERR;
46 my $harness = TAP::Harness->new(
47 { verbosity => -2,
5e2a19fc 48 switches => [ @libs, "-MNoFork" ],
b965d173 49 stdout => $capture,
50 }
51 );
2adbc9b6 52 $harness->runtests( 't/sample-tests/simple' );
b965d173 53 my @output = tied($$capture)->dump;
54 is pop @output, "Result: PASS\n", 'status OK';
5e2a19fc 55 pop @output; # get rid of summary line
b965d173 56 is( $output[-1], "All tests successful.\n", 'ran with no fork' );
57}
58
59# vim:ts=4:sw=4:et:sta