line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl -w |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# The script tests Arch::Util file-system related functions. |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
813
|
use FindBin; |
|
1
|
|
|
|
|
1151
|
|
|
1
|
|
|
|
|
52
|
|
6
|
1
|
|
|
1
|
|
786
|
use lib "$FindBin::Bin/../perllib"; |
|
1
|
|
|
|
|
604
|
|
|
1
|
|
|
|
|
6
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
1050
|
use Test::More tests => 49; |
|
1
|
|
|
|
|
20762
|
|
|
1
|
|
|
|
|
10
|
|
9
|
1
|
|
|
1
|
|
8
|
use_ok("Arch::Util"); |
|
1
|
|
|
|
|
1032
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
43
|
|
10
|
1
|
|
|
1
|
|
473
|
use_ok("Arch::TempFiles"); |
|
1
|
|
|
|
|
1016
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
44
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
|
|
326
|
my $tmp = Arch::TempFiles->new; |
13
|
1
|
|
|
|
|
5
|
my $dir = $tmp->dir; |
14
|
1
|
50
|
33
|
|
|
124
|
die "Internal: Arch::TempFiles::dir didn't create dir\n" unless $dir && -d $dir; |
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
|
|
10
|
$ENV{HOME} = $dir; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub run_func (@) { |
19
|
17
|
|
|
17
|
|
40
|
my $func = shift; |
20
|
17
|
100
|
|
|
|
55
|
my $cmd = "$func(" . join(", ", map { ref($_) || "scalar" } @_) . ")"; |
|
33
|
|
|
|
|
204
|
|
21
|
17
|
|
|
|
|
39
|
$func = "Arch::Util::$func"; |
22
|
17
|
|
|
|
|
27
|
my $i = -1; |
23
|
17
|
|
|
|
|
33
|
my $args = join(", ", map { $i++; "\$_[$i]" } @_); |
|
33
|
|
|
|
|
41
|
|
|
33
|
|
|
|
|
110
|
|
24
|
17
|
|
|
|
|
43
|
my ($result_assign, $result, @result) = (""); |
25
|
17
|
100
|
66
|
|
|
89
|
if (defined wantarray && !wantarray) { |
|
|
50
|
|
|
|
|
|
26
|
6
|
|
|
|
|
13
|
$result_assign = '$result = '; |
27
|
6
|
|
|
|
|
12
|
$cmd .= " (scalar context)"; |
28
|
|
|
|
|
|
|
} elsif (wantarray) { |
29
|
0
|
|
|
|
|
0
|
$result_assign = '@result = '; |
30
|
0
|
|
|
|
|
0
|
$cmd .= " (list context)"; |
31
|
|
|
|
|
|
|
} |
32
|
17
|
|
|
|
|
2379
|
eval "$result_assign$func($args);"; |
33
|
17
|
50
|
|
|
|
88
|
if ($@) { |
34
|
0
|
|
|
|
|
0
|
fail($cmd . ": $@"); |
35
|
|
|
|
|
|
|
} else { |
36
|
17
|
|
|
|
|
89
|
pass($cmd); |
37
|
|
|
|
|
|
|
} |
38
|
17
|
100
|
|
|
|
11394
|
return unless defined wantarray; |
39
|
6
|
50
|
|
|
|
29
|
return wantarray? @result: $result; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
1
|
|
|
|
|
6
|
my @contents = ( |
43
|
|
|
|
|
|
|
"", |
44
|
|
|
|
|
|
|
"This is a short file.\nReally short.\n", |
45
|
|
|
|
|
|
|
"\n" . ("\0" x 100) . "\n" . ("\t" x 100) . "\n" . (" " x 100), |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
|
48
|
1
|
|
|
|
|
3
|
my $i = 0; |
49
|
1
|
|
|
|
|
3
|
foreach my $content (@contents) { |
50
|
3
|
|
|
|
|
1476
|
my @lines = split("\n", $content); |
51
|
3
|
|
|
|
|
10
|
my $file = "$dir/file" . ++$i; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# save_file |
54
|
3
|
|
|
|
|
11
|
run_func("save_file", $file, $content); |
55
|
3
|
|
|
|
|
100
|
ok(-f $file, "stat created file $file"); |
56
|
3
|
|
|
|
|
1889
|
is(-s $file, length($content), "stat file size"); |
57
|
3
|
50
|
|
|
|
2101
|
open(IN, "<$file") || warn "Can't read $file, expect failures\n"; |
58
|
3
|
|
|
|
|
82
|
my $content2 = join("", ); |
59
|
3
|
|
|
|
|
40
|
close IN; |
60
|
3
|
|
|
|
|
16
|
is($content2, $content, "compare saved content"); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# load_file |
63
|
3
|
|
|
|
|
1775
|
my $content3 = run_func("load_file", $file); |
64
|
3
|
|
|
|
|
12
|
is($content3, $content, "compare loaded content"); |
65
|
|
|
|
|
|
|
# my @lines2 = run_func("load_file", $file); |
66
|
|
|
|
|
|
|
# is_deeply(\@lines2, \@lines, "compare loaded lines"); |
67
|
3
|
|
|
|
|
1687
|
my ($content4, @lines3); |
68
|
3
|
|
|
|
|
13
|
run_func("load_file", $file, \$content4); |
69
|
3
|
|
|
|
|
11
|
is($content4, $content, "compare loaded content ref"); |
70
|
3
|
|
|
|
|
1365
|
run_func("load_file", $file, \@lines3); |
71
|
3
|
|
|
|
|
15
|
is_deeply(\@lines3, \@lines, "compare loaded lines ref"); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
1
|
|
|
|
|
853
|
is(undef, eval { load_file("$dir/unexisting"); 1 }, "check unexisting load"); |
|
1
|
|
|
|
|
27
|
|
|
0
|
|
|
|
|
0
|
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# copy_dir |
77
|
1
|
|
|
|
|
567
|
my $dir2 = $tmp->dir_name; |
78
|
1
|
|
|
|
|
43
|
run_func("copy_dir", $dir, $dir2); |
79
|
1
|
|
|
|
|
36
|
ok(-d $dir2, "stat copied directory"); |
80
|
1
|
|
|
|
|
554
|
ok(-f "$dir2/file$_", "stat copied file$_") foreach 1 .. @contents; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# remove_dir |
83
|
1
|
|
|
|
|
1769
|
run_func("remove_dir", $dir2); |
84
|
1
|
|
|
|
|
102
|
ok(!-d $dir2, "stat removed directory"); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# setup_config_dir |
87
|
1
|
|
|
|
|
582
|
my $dir3 = run_func("setup_config_dir", undef, "archmage", "spells"); |
88
|
1
|
|
|
|
|
15
|
is($dir3, "$dir/.arch-magic/archmage/spells", "check setup'd config dir"); |
89
|
1
|
|
|
|
|
603
|
ok(-d $dir3, "stat $dir3"); |
90
|
1
|
|
|
|
|
538
|
my $dir4 = run_func("setup_config_dir", undef, "archmage"); |
91
|
1
|
|
|
|
|
26
|
is($dir4, "$dir/.arch-magic/archmage", "check setup'd config dir"); |
92
|
1
|
|
|
|
|
735
|
ok(-d $dir4, "stat $dir4"); |
93
|
1
|
|
|
|
|
625
|
my $dir5 = run_func("setup_config_dir", $dir4, 1, 2, 3); |
94
|
1
|
|
|
|
|
8
|
is($dir5, "$dir4/1/2/3", "check setup'd config dir"); |
95
|
1
|
|
|
|
|
596
|
ok(-d $dir5, "stat $dir5"); |