-
Notifications
You must be signed in to change notification settings - Fork 2
/
ndproc-Pipe.t
83 lines (70 loc) · 2.39 KB
/
ndproc-Pipe.t
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
use strict;
use warnings FATAL => 'all';
use File::Copy qw(copy);
use File::Spec::Functions qw(catfile);
use Test::File::Contents;
use Test::More tests => 8;
use App::NDTools::Test;
chdir t_dir or die "Failed to change test dir";
my $test;
my @cmd = ($^X, catfile('..', '..', '..', 'ndproc'), '--module', 'Pipe');
$test = "cmd_absent";
run_ok(
name => $test,
pre => sub { copy("_cfg.alpha.json", "$test.got") },
cmd => [ @cmd, '--path', '{files}', "$test.got" ],
stderr => qr/ ERROR] Command to run should be defined/,
exit => 1
);
$test = "cmd_failed";
run_ok(
name => $test,
pre => sub { copy("_cfg.alpha.json", "$test.got") },
cmd => [ @cmd, '--path', '{files}', '--cmd', $^X . ' -e "exit 222"', "$test.got" ],
stderr => qr/ FATAL] .* exited with 222\./,
exit => 16
);
$test = "malformed_json";
run_ok(
name => $test,
pre => sub { copy("_cfg.alpha.json", "$test.got") },
cmd => [ @cmd, '--cmd', 'echo -n', "$test.got" ],
stderr => qr/ FATAL] Failed to decode 'JSON'/,
exit => 4,
);
$test = "path";
run_ok(
name => $test,
pre => sub { copy("_cfg.alpha.json", "$test.got") },
cmd => [ @cmd, '--path', '{files}', '--cmd', $^X . ' -pe "s/1/42/g"', "$test.got" ],
test => sub { files_eq_or_diff("$test.exp", "$test.got", $test) },
);
$test = "path_absent";
run_ok(
name => $test,
pre => sub { copy("_cfg.alpha.json", "$test.got") },
cmd => [ @cmd, '--cmd', $^X . ' -pe "s/[0-8]/9/g"', "$test.got" ],
test => sub { files_eq_or_diff("$test.exp", "$test.got", $test) },
);
$test = "path_empty"; # means 'full structure'
run_ok(
name => $test,
pre => sub { copy("_cfg.alpha.json", "$test.got") },
cmd => [ @cmd, '--path', '', '--cmd', $^X . ' -pe "s/[0-8]/9/g"', "$test.got" ],
test => sub { files_eq_or_diff("$test.exp", "$test.got", $test) },
);
$test = "path_strict";
run_ok(
name => $test,
pre => sub { copy("_cfg.alpha.json", "$test.got") },
cmd => [ @cmd, '--strict', '--path', '{not_exists}', '--cmd', $^X . ' -pe "s/[0-8]/9/g"', "$test.got" ],
stderr => qr/ FATAL] Failed to lookup path '\{not_exists\}'/,
exit => 4,
);
$test = "preserve";
run_ok(
name => $test,
pre => sub { copy("_cfg.alpha.json", "$test.got") },
cmd => [ @cmd, '--preserve', '{files}{"/etc/hosts"}', '--cmd', $^X . ' -pe "s/[0-8]/9/g"', "$test.got" ],
test => sub { files_eq_or_diff("$test.exp", "$test.got", $test) },
);