line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl -w |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# The script tests Arch::Util run-cmd related functions. |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
7891
|
use FindBin; |
|
1
|
|
|
|
|
1141
|
|
|
1
|
|
|
|
|
47
|
|
6
|
1
|
|
|
1
|
|
747
|
use lib "$FindBin::Bin/../perllib"; |
|
1
|
|
|
|
|
732
|
|
|
1
|
|
|
|
|
7
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
1363
|
use Test::More tests => 40; |
|
1
|
|
|
|
|
50612
|
|
|
1
|
|
|
|
|
12
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
8
|
use_ok("Arch::Util", "save_file", "load_file"); |
|
1
|
|
|
|
|
951
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
65
|
|
11
|
1
|
|
|
1
|
|
922
|
use_ok("Arch::TempFiles"); |
|
1
|
|
|
|
|
846
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
33
|
|
12
|
1
|
|
|
1
|
|
622
|
use_ok("Arch::Session"); |
|
1
|
|
|
|
|
796
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
17
|
|
13
|
1
|
|
|
1
|
|
786
|
use_ok("IO::Handle"); |
|
1
|
|
|
|
|
1118
|
|
|
1
|
|
|
|
|
7540
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
39
|
|
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
|
|
974
|
my $tmp = Arch::TempFiles->new; |
16
|
1
|
|
|
|
|
6
|
my $dir = $tmp->dir; |
17
|
1
|
50
|
33
|
|
|
26
|
die "Internal: Arch::TempFiles::dir didn't create dir\n" unless $dir && -d $dir; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub run_func (@) { |
20
|
15
|
|
|
15
|
|
579
|
my $func = shift; |
21
|
15
|
|
33
|
|
|
100
|
my $cmd = "$func(" . join(", ", map { "'" . (ref($_) || $_) . "'" } @_) . ")"; |
|
20
|
|
|
|
|
254
|
|
22
|
15
|
|
|
|
|
43
|
$func = "Arch::Util::$func"; |
23
|
15
|
|
|
|
|
59
|
my ($result_assign, $result, @result) = (""); |
24
|
15
|
100
|
100
|
|
|
180
|
if (defined wantarray && !wantarray) { |
|
|
100
|
|
|
|
|
|
25
|
8
|
|
|
|
|
18
|
$result_assign = '$result = '; |
26
|
8
|
|
|
|
|
17
|
$cmd .= " (scalar context)"; |
27
|
|
|
|
|
|
|
} elsif (wantarray) { |
28
|
5
|
|
|
|
|
25
|
$result_assign = '@result = '; |
29
|
5
|
|
|
|
|
11
|
$cmd .= " (list context)"; |
30
|
|
|
|
|
|
|
} |
31
|
15
|
100
|
|
|
|
2023
|
eval "$result_assign$func(" . (@_ ? '@_' : '') . ");"; |
32
|
15
|
50
|
|
|
|
297
|
if ($@) { |
33
|
0
|
|
|
|
|
0
|
fail($cmd . ": $@"); |
34
|
|
|
|
|
|
|
} else { |
35
|
15
|
|
|
|
|
342
|
pass($cmd); |
36
|
|
|
|
|
|
|
} |
37
|
15
|
100
|
|
|
|
21288
|
return unless defined wantarray; |
38
|
13
|
100
|
|
|
|
249
|
return wantarray? @result: $result; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
1
|
50
|
33
|
|
|
38
|
SKIP: { |
42
|
1
|
|
|
|
|
2
|
skip("no valid /bin/ls and /bin/cp", 29) unless -x "/bin/ls" && -x "/bin/cp"; |
43
|
1
|
|
|
|
|
2
|
my ($ls_output, @ls_output); |
44
|
|
|
|
|
|
|
|
45
|
1
|
|
|
|
|
8
|
$ls_output = run_func("run_cmd", "ls $dir"); |
46
|
1
|
|
|
|
|
13
|
@ls_output = run_func("run_cmd", "ls $dir"); |
47
|
1
|
|
|
|
|
26
|
is($ls_output, "", "check ls empty_dir (scalar)"); |
48
|
1
|
|
|
|
|
682
|
ok(!@ls_output, "check ls empty_dir (list)"); |
49
|
|
|
|
|
|
|
|
50
|
1
|
|
|
|
|
509
|
my $content = "Some unimportant content\n"; |
51
|
1
|
|
|
|
|
5
|
my $file1 = "$dir/file1"; |
52
|
1
|
|
|
|
|
7
|
my $file2 = "$dir/file2"; |
53
|
1
|
|
|
|
|
4
|
my $file3 = "$dir/file3"; |
54
|
1
|
|
|
|
|
22
|
save_file($file1, $content); |
55
|
1
|
|
|
|
|
29
|
ok(-f $file1, "check save_file creation"); |
56
|
|
|
|
|
|
|
|
57
|
1
|
|
|
|
|
641
|
$ls_output = run_func("run_cmd", "ls $dir"); |
58
|
1
|
|
|
|
|
270
|
@ls_output = run_func("run_cmd", "ls $dir"); |
59
|
1
|
|
|
|
|
25
|
is($ls_output, "file1\n", "check ls single_file_dir (scalar)"); |
60
|
1
|
|
|
|
|
690
|
is_deeply(\@ls_output, ["file1"], "check ls single_file_dir (list)"); |
61
|
|
|
|
|
|
|
|
62
|
1
|
|
|
|
|
929
|
run_func("run_cmd", "cp $file1 $file2"); |
63
|
1
|
|
|
|
|
21
|
run_func("run_cmd", "cp", $file1, $file3); |
64
|
1
|
|
|
|
|
81
|
ok(-f $file2, "check cp file creation 1"); |
65
|
1
|
|
|
|
|
647
|
ok(-f $file3, "check cp file creation 2"); |
66
|
1
|
|
|
|
|
649
|
is(load_file($file2), $content, "check cp content 1"); |
67
|
1
|
|
|
|
|
628
|
is(load_file($file3), $content, "check cp content 2"); |
68
|
|
|
|
|
|
|
|
69
|
1
|
|
|
|
|
595
|
$ls_output = run_func("run_cmd", "ls $dir"); |
70
|
1
|
|
|
|
|
26
|
@ls_output = run_func("run_cmd", "ls $dir"); |
71
|
1
|
|
|
|
|
23
|
is($ls_output, "file1\nfile2\nfile3\n", "check ls three_file_dir (scalar)"); |
72
|
1
|
|
|
|
|
449
|
is_deeply(\@ls_output, [qw(file1 file2 file3)], "check ls three_file_dir (list)"); |
73
|
|
|
|
|
|
|
|
74
|
1
|
|
|
|
|
691
|
my $ls_output2 = run_func("run_cmd", "ls $dir $dir"); |
75
|
1
|
|
|
|
|
17
|
my @ls_output2 = run_func("run_cmd", "ls $dir $dir"); |
76
|
1
|
|
|
|
|
39
|
my $ls_output3 = run_func("run_cmd", "ls", $dir, $dir); |
77
|
1
|
|
|
|
|
24
|
my @ls_output3 = run_func("run_cmd", "ls", $dir, $dir); |
78
|
1
|
|
|
|
|
27
|
$ls_output2 =~ s/^(.*:|)\n//mg; |
79
|
1
|
|
|
|
|
18
|
$ls_output3 =~ s/^(.*:|)\n//mg; |
80
|
1
|
|
|
|
|
9
|
@ls_output2 = grep { !/^(.*:|)$/ } @ls_output2; |
|
9
|
|
|
|
|
29
|
|
81
|
1
|
|
|
|
|
5
|
@ls_output3 = grep { !/^(.*:|)$/ } @ls_output3; |
|
9
|
|
|
|
|
26
|
|
82
|
1
|
|
|
|
|
16
|
is($ls_output2, $ls_output x 2, "check ls three_file_dir x 2 (scalar)"); |
83
|
1
|
|
|
|
|
647
|
is(@ls_output2, @ls_output * 2, "check ls three_file_dir x 2 (list)"); |
84
|
1
|
|
|
|
|
3212
|
is($ls_output3, $ls_output x 2, "check ls three_file_dir x 2 (scalar)"); |
85
|
1
|
|
|
|
|
602
|
is(@ls_output3, @ls_output * 2, "check ls three_file_dir x 2 (list)"); |
86
|
|
|
|
|
|
|
|
87
|
1
|
|
|
|
|
570
|
my $fh = run_func("run_pipe_from", "ls", $dir); |
88
|
1
|
|
|
|
|
123
|
my @files = map { chomp; $_ } $fh->getlines; |
|
3
|
|
|
|
|
107
|
|
|
3
|
|
|
|
|
19
|
|
89
|
1
|
|
|
|
|
18
|
is_deeply(\@files, \@ls_output, "check ls pipe lines"); |
90
|
1
|
|
|
|
|
868
|
$fh->close; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
1
|
|
|
|
|
60
|
my $arch_backend = run_func("arch_backend"); |
94
|
1
|
|
|
|
|
9
|
my $is_tla_functional = run_func("is_tla_functional"); |
95
|
|
|
|
|
|
|
|
96
|
1
|
50
|
|
|
|
42
|
SKIP: { |
97
|
1
|
|
|
|
|
20
|
skip "No functional arch backend", 5 unless $is_tla_functional; |
98
|
0
|
|
|
|
|
0
|
run_func("run_tla", "-h"); |
99
|
0
|
|
|
|
|
0
|
my $tla_output = run_func("run_tla", "--version"); |
100
|
0
|
|
|
|
|
0
|
my @tla_output = run_func("run_tla", "--version"); |
101
|
0
|
|
|
|
|
0
|
like($tla_output, qr/\b(Tom Lord|Arch|Bazaar|tla|baz)\b/, "check $arch_backend --version output (scalar)"); |
102
|
0
|
|
|
|
|
0
|
ok(@tla_output > 0, "check $arch_backend --version output (list)"); |
103
|
|
|
|
|
|
|
} |