File: result.t

package info (click to toggle)
libipc-run-perl 20231003.0-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 844 kB
  • sloc: perl: 6,255; makefile: 5
file content (61 lines) | stat: -rw-r--r-- 1,891 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
use strict;
use warnings;

use IPC::Run qw( harness );
use Test::More tests => 12;

my @perl   = ($^X);
my @exit0  = ( @perl, '-e', q{ exit 0 } );
my @exit42 = ( @perl, '-e', q{ exit 42 } );
my ( @cmds, @expect_full, $first_nonzero, $first_nonzero_full );
if (IPC::Run::Win32_MODE) {
    require IPC::Run::Win32Process;
    require Math::BigInt;

    # Perl exit() doesn't preserve these high exit codes, but cmd.exe does.
    my $exit_max_shifted = IPC::Run::Win32Process->new(
        $ENV{COMSPEC},
        q{cmd.exe /c exit 16777215}
    );
    my $exit_max = IPC::Run::Win32Process->new(
        $ENV{COMSPEC},
        q{cmd.exe /c exit 4294967295}
    );

    # Construct 0xFFFFFFFF00 in a way that works on !USE_64_BIT_INT builds.
    my $expect_exit_max = Math::BigInt->new(0xFFFFFFFF);
    $expect_exit_max->blsft(8);

    @cmds = ( \@exit0, '&', $exit_max, '&', $exit_max_shifted, '&', \@exit42 );
    @expect_full        = ( 0, $expect_exit_max, 0xFFFFFF00, 42 << 8 );
    $first_nonzero      = 0xFFFFFFFF;
    $first_nonzero_full = $expect_exit_max;
}
else {
    my @kill9 = ( @perl, '-e', q{ kill 'KILL', $$ } );

    @cmds = ( \@exit0, '&', \@exit0, '&', \@kill9, '&', \@exit42 );
    @expect_full = ( 0, 0, 9, 42 << 8 );
    $first_nonzero      = 42;
    $first_nonzero_full = 9;
}
my $h = harness(@cmds);
$h->run;

is_deeply(
    [ $h->results ], [ map { $_ >> 8 } @expect_full ],
    'Results of all processes'
);
is_deeply(
    [ $h->full_results ], \@expect_full,
    'Full results of all processes'
);
is( $h->result,      $first_nonzero,      'First non-zero result' );
is( $h->full_result, $first_nonzero_full, 'First non-zero full result' );
foreach my $pos ( 0 .. $#expect_full ) {
    is( $h->result($pos), $expect_full[$pos] >> 8, "Result of process $pos" );
    is(
        $h->full_result($pos), $expect_full[$pos],
        "Full result of process $pos"
    );
}