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