This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Rename ext/Test/Harness to ext/Test-Harness
[perl5.git] / ext / Test-Harness / t / nofork.t
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
6 BEGIN {
7     if ( $ENV{PERL_CORE} ) {
8         chdir 't';
9         @INC = ( '../lib', '../ext/Test-Harness/t/lib' );
10     }
11     else {
12         use lib 't/lib';
13     }
14 }
15
16 use strict;
17
18 use Config;
19 use Test::More (
20     $Config{d_fork}
21     ? 'no_plan'
22     : ( 'skip_all' => 'your system already has no fork' )
23 );
24 use IO::c55Capture;    # for util
25
26 use TAP::Harness;
27
28 sub backticks {
29     my (@args) = @_;
30
31     util::stdout_of( sub { system(@args) and die "error $?" } );
32 }
33
34 my @libs = map "-I$_", @INC;
35 my @perl = ( $^X, @libs );
36 my $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,
56             switches  => [ @libs, "-MNoFork" ],
57             stdout    => $capture,
58         }
59     );
60     $harness->runtests( ( $ENV{PERL_CORE} ? '../ext/Test-Harness/' : '' )
61         . 't/sample-tests/simple' );
62     my @output = tied($$capture)->dump;
63     is pop @output, "Result: PASS\n", 'status OK';
64     pop @output;    # get rid of summary line
65     is( $output[-1], "All tests successful.\n", 'ran with no fork' );
66 }
67
68 # vim:ts=4:sw=4:et:sta