line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Debian; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
38332
|
use 5.008008; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
32
|
|
4
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
16
|
|
|
1
|
|
|
|
|
684
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
6
|
use Test::More; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
7
|
|
8
|
1
|
|
|
1
|
|
373
|
use base 'Exporter'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1455
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @EXPORT = qw( |
11
|
|
|
|
|
|
|
system_is_debian |
12
|
|
|
|
|
|
|
package_is_installed |
13
|
|
|
|
|
|
|
package_isnt_installed |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub system_is_debian(;$) { |
19
|
1
|
|
50
|
1
|
1
|
12
|
my $name = shift || 'System is debian'; |
20
|
1
|
|
|
|
|
16
|
Test::More->builder->ok( -r '/etc/debian_version', $name ); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub _pkg_list($) { |
25
|
4
|
|
|
4
|
|
6
|
my ($name) = @_; |
26
|
4
|
|
|
|
|
7
|
our %dpkg_list; |
27
|
|
|
|
|
|
|
|
28
|
4
|
50
|
|
|
|
130
|
unless(-x '/usr/bin/dpkg') { |
29
|
0
|
|
|
|
|
0
|
Test::More->builder->ok( 0, $name ); |
30
|
0
|
|
|
|
|
0
|
diag '/usr/bin/dpkg is not found or executable'; |
31
|
0
|
|
|
|
|
0
|
return 0; |
32
|
|
|
|
|
|
|
} |
33
|
4
|
100
|
|
|
|
19
|
unless(%dpkg_list) { |
34
|
1
|
|
|
|
|
3354
|
my $pid = open my $fh, '-|', '/usr/bin/dpkg', '--get-selections'; |
35
|
1
|
50
|
|
|
|
35
|
unless($pid) { |
36
|
0
|
|
|
|
|
0
|
my $err = $!; |
37
|
0
|
|
|
|
|
0
|
Test::More->builder->ok( 0, $name ); |
38
|
0
|
|
|
|
|
0
|
diag $!; |
39
|
0
|
|
|
|
|
0
|
return 0; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
264
|
|
|
|
|
6184
|
%dpkg_list = map { ( @$_[0, 1] ) } |
|
264
|
|
|
|
|
1029
|
|
43
|
1
|
|
|
|
|
34505
|
map { [ split /\s+/, $_, 3 ] } <$fh>; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
4
|
|
|
|
|
227
|
return \%dpkg_list; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub package_is_installed($;$) { |
50
|
3
|
|
|
3
|
1
|
867
|
my ($pkg, $name) = @_; |
51
|
|
|
|
|
|
|
|
52
|
3
|
|
33
|
|
|
19
|
$name ||= "$pkg is installed"; |
53
|
3
|
50
|
|
|
|
7
|
my $list = _pkg_list($_) or return 0; |
54
|
|
|
|
|
|
|
|
55
|
3
|
|
|
|
|
35
|
my $tb = Test::More->builder; |
56
|
3
|
|
|
|
|
45
|
my @names = split /\|/, $pkg; |
57
|
3
|
|
|
|
|
13
|
for (@names) { |
58
|
4
|
100
|
|
|
|
13
|
next unless exists $list->{ $_ }; |
59
|
3
|
50
|
|
|
|
17
|
next unless $list->{ $_ } eq 'install'; |
60
|
3
|
|
|
|
|
13
|
return $tb->ok( 1, $name ); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
0
|
return $tb->ok( 0, $name ); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub package_isnt_installed($;$) { |
69
|
1
|
|
|
1
|
1
|
470
|
my ($pkg, $name) = @_; |
70
|
|
|
|
|
|
|
|
71
|
1
|
|
33
|
|
|
9
|
$name ||= "$pkg is not installed"; |
72
|
|
|
|
|
|
|
|
73
|
1
|
50
|
|
|
|
4
|
my $list = _pkg_list($name) or return 0; |
74
|
|
|
|
|
|
|
|
75
|
1
|
|
|
|
|
5
|
my $tb = Test::More->builder; |
76
|
1
|
50
|
|
|
|
13
|
return $tb->ok( 1, $name ) unless exists $list->{ $pkg }; |
77
|
0
|
|
|
|
|
|
return $tb->cmp_ok($list->{ $pkg }, 'ne', 'install', $name); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
1; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 NAME |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Test::Debian - some tests for debian system |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 SYNOPSIS |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
use Test::More; |
90
|
|
|
|
|
|
|
use Test::Debian; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
ok($value, 'test name'); |
93
|
|
|
|
|
|
|
system_is_debian; |
94
|
|
|
|
|
|
|
package_is_installed 'dpkg'; |
95
|
|
|
|
|
|
|
package_is_installed 'dpkg', 'dpkg is installed'; |
96
|
|
|
|
|
|
|
package_isnt_installed 'kde-base'; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 DESCRIPTION |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
The module provides some perl tests for debian system: |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head2 system_is_debian([ $test_name ]) |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Passes if current OS is debian |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head2 package_is_installed($pkg_name [, $test_name ]) |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Passes if package is installed |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head2 package_isnt_installed($pkg_name [, $test_name ]) |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Passes if package isn't installed |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 AUTHOR |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Dmitry E. Oboukhov, Eunera@debian.org |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Copyright (C) 2012 by Dmitry E. Oboukhov |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
125
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.8.8 or, |
126
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=cut |