File: 05_multi_capture.t

package info (click to toggle)
libipc-system-simple-perl 1.30-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid
  • size: 256 kB
  • sloc: perl: 908; makefile: 4
file content (82 lines) | stat: -rw-r--r-- 1,946 bytes parent folder | download | duplicates (6)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/perl -w
use strict;
use Config;
use Test::More;
use constant NO_SUCH_CMD => "this_command_had_better_not_exist_either";
use constant NOT_AN_EXE  => "not_an_exe.txt";

plan tests => 14;

# We want to invoke our sub-commands using Perl.

my $perl_path = $Config{perlpath};

if ($^O ne 'VMS') {
	$perl_path .= $Config{_exe}
		unless $perl_path =~ m/$Config{_exe}$/i;
}

use_ok("IPC::System::Simple","capture");
chdir("t");

# The tests below for $/ are left in, even though IPC::System::Simple
# never touches $/

# Scalar capture

my $output = capture($perl_path,"output.pl",0);
ok(1);

is($output,"Hello\nGoodbye\n","Scalar capture");
is($/,"\n",'$/ intact');

# List capture

my @output = capture($perl_path,"output.pl",0);
ok(1);

is_deeply(\@output,["Hello\n", "Goodbye\n"],"List capture");
is($/,"\n",'$/ intact');

# List capture with odd $/

{
	local $/ = "e";
	my @odd_output = capture($perl_path,"output.pl",0);
	ok(1);

	is_deeply(\@odd_output,["He","llo\nGoodbye","\n"], 'Odd $/ capture');

}

my $no_output;
eval {
        $no_output = capture(NO_SUCH_CMD,1);
};

like($@,qr/failed to start/, "failed capture");
is($no_output,undef, "No output from failed command");

# Running Perl -v

my $perl_output = capture($perl_path,"-v");
like($perl_output, qr{Larry Wall}, "perl -v contains Larry");

SKIP: {

	# Considering making these tests depend upon the OS,
	# as well as $ENV{AUTHOR_TEST}, since different systems
	# will have different ways of expressing their displeasure
	# at executing a file that's not executable.

	skip('Author test.  Set $ENV{TEST_AUTHOR} to true to run', 2)
		unless $ENV{TEST_AUTHOR};

	chmod(0,NOT_AN_EXE);
	eval { capture(NOT_AN_EXE,1); };
        chmod(0644,NOT_AN_EXE);             # To stop git complaining

	like($@, qr{Permission denied|No such file|The system cannot find the file specified}, "Permission denied on non-exe" );
	like($@, qr{failed to start}, "Non-exe failed to start" );

}