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