File: 10-action-code.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 (55 lines) | stat: -rw-r--r-- 1,430 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
#! perl

use strict;
use warnings;

use Config;
use Test::More 0.89;

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

{
	my $action;
	our $callback = sub {};
	my %args = (
		code    => '$::callback->()',
		message => 'callback',
	);
	lives_ok { $action = ExtUtils::Builder::Action::Code->new(%args) } 'Can create new object';

	{
		my @actions;
		local $callback = sub { push @actions, 1 };

		lives_ok { $action->execute(quiet => 1) } 'Can execute command';
		is_deeply(\@actions, [1], 'Command is executed quietly');
	}

	{
		my (@actions, @messages);
		local $callback = sub { push @actions, 2 };

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

		is_deeply(\@actions, [2], 'Command is executed with logging');
		is_deeply($output, "callback\n", 'Got the message');
	}

	my @serialized = $action->to_command;
	is(scalar(@serialized), 1, 'Got one command');
	my ($command, @arguments) = @{ shift @serialized };
	ok(-x $command, 'Command is executable');
	is_deeply(\@arguments, [ '-e', $args{code} ], 'to_command gives correct arguments');
	is($action->to_code, $args{code}, 'to_code is "$input"');

	is($action->preference, 'execute', 'Prefered means is "execute"');
	is($action->preference(qw/code command/), 'code', 'Prefered means between "code" and "command" is "code"');
}

done_testing;