File: 10-action-command.t

package info (click to toggle)
libextutils-builder-perl 0.017-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 276 kB
  • sloc: perl: 1,351; makefile: 2
file content (60 lines) | stat: -rw-r--r-- 1,756 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
#! perl

use strict;
use warnings;

use Test::More 0.89;

use ExtUtils::Builder::Action::Command;
use lib 't/lib';
use Test::LivesOK 'lives_ok';

{
	my $action;
	lives_ok { $action = ExtUtils::Builder::Action::Command->new(command => [ $^X, '-e0' ]) } 'Can create new object';

	is_deeply($action->to_command, [$^X, '-e0'], 'Returns perl -e0');

	like($action->to_code, qr/ system \( '.*?','-e0' \) \ and \ die /x, 'to_code returns something that might be sensible');

	lives_ok { $action->execute(quiet => 1) } 'Can execute quiet command';

	open my $stdout, '>', \my $output;
	select $stdout;
	lives_ok { $action->execute } 'Can execute logging command';
	select STDOUT;
	close $stdout;

	like($output, qr/\Q$^X\E .+ -e0 \n \z/x, "Got '$^X -e0' as message");

	is($action->preference, 'command', 'Preferred action is "execute"');
}

{
	my $action;
	lives_ok { $action = ExtUtils::Builder::Action::Command->new(command => 'echo Hello World') } 'Can create new object';

	is_deeply($action->to_command, 'echo Hello World', 'Returns perl -e0');

	like($action->to_code, qr/ system \( 'echo\ Hello\ World' \) \ and \ die /x, 'to_code returns something that might be sensible');

	open my $stdout, '>&', *STDOUT or die;
	open my $temp, '+>:crlf', undef or die;
	open STDOUT, '>&', $temp or die;
	open my $messenger, '>', \my $message;
	select $messenger;
	lives_ok { $action->execute } 'Can execute logging command';
	select STDOUT;
	seek($temp, 0, 0);
	my $output = join '', <$temp>;
	open STDOUT, '>&', $stdout or die;
	select STDOUT;

	is($message, "echo Hello World\n", "Got echo Hello World as message");
	is($output, "Hello World\n", 'got Hello World as output');

	is($action->preference, 'command', 'Preferred action is "execute"');
}

done_testing;