File: 11-spawn-fail.t

package info (click to toggle)
libsystem-command-perl 1.122-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 228 kB
  • sloc: perl: 550; makefile: 2
file content (44 lines) | stat: -rw-r--r-- 1,008 bytes parent folder | download | duplicates (5)
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
use strict;
use warnings;
use Test::More;
use System::Command;
use Config;

# do not test under Win32
plan skip_all => 'This test script  does not make sense under Win32'
    if $^O eq 'MSWin32';

my @fail = (
    {   cmdline => ['does-not-exist'],
        fail    => qr/^Can't exec\( does-not-exist \): /,
    },
);

plan tests => 2 * @fail;

for my $t (@fail) {

    # run the command
    my $cmd = eval { System::Command->new( @{ $t->{cmdline} } ) };
    ok( !$cmd, "command failed: @{ $t->{cmdline} }" );
    like( $@, $t->{fail}, '... expected error message' );

    # didn't fail?
    if ($cmd) {

        # get the output
        my $output = join '', $cmd->stdout->getlines();
        diag "output:\n", $output;

        # get the errput
        my $errput = join '', $cmd->stderr->getlines();
        diag "errput:\n", $errput;

        # close and check
        $cmd->close();
        diag "exit: " . $cmd->exit;
        diag "signal: " . $cmd->signal;
        diag "core: " . $cmd->core;
    }
}