File: 60-version.t

package info (click to toggle)
libtest-valgrind-perl 1.19-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 424 kB
  • sloc: perl: 2,779; makefile: 22
file content (167 lines) | stat: -rw-r--r-- 3,803 bytes parent folder | download | duplicates (3)
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!perl -T

use strict;
use warnings;

use Test::More tests => 6 + 5 + 4 * 9 + 2 * 23 + 2 * 14;

use Test::Valgrind::Version;

sub TVV () { 'Test::Valgrind::Version' }

sub sanitize {
 my $str = shift;

 $str = '(undef)' unless defined $str;
 1 while chomp $str;
 $str =~ s/\n/\\n/g;

 $str;
}

my @command_failures = (
 undef,
 'valgrind',
 '1.2.3',
 'valgrin-1.2.3',
 'VALGRIND-1.2.3',
 "doo dah doo\nvalgrind-1.2.3",
);

for my $failure (@command_failures) {
 my $desc = sanitize $failure;
 local $@;
 eval { TVV->new(command_output => $failure) };
 like $@, qr/^Invalid argument/,
          "\"$desc\" correctly failed to parse as command_output";
}

my @string_failures = (
 undef,
 'valgrind',
 'valgrind-1.2.3',
 'abc',
 'd.e.f',
);

for my $failure (@string_failures) {
 my $desc = sanitize $failure;
 local $@;
 eval { TVV->new(string => $failure) };
 like $@, qr/^Invalid argument/,
          "\"$desc\" correctly failed to parse as string";
}

my @command_valid = (
 'valgrind-1'          => '1.0.0',
 'valgrind-1.2'        => '1.2.0',
 'valgrind-1.2.3'      => '1.2.3',
 'valgrind-1.2.4-rc5'  => '1.2.4',
 'valgrind-1.2.6a'     => '1.2.6',
 'valgrind-1.2.7.'     => '1.2.7',
 'valgrind-1.2.x.8'    => '1.2.0',
 'valgrind-1.10.'      => '1.10.0',
 'valgrind-3.12.0.SVN' => '3.12.0',
);

my @string_valid = map { my $s = $_; $s =~ s/^valgrind-//; $s }
                    @command_valid;

while (@command_valid) {
 my ($output, $exp) = splice @command_valid, 0, 2;
 my $desc = sanitize $output;
 local $@;
 my $res = eval { TVV->new(command_output => $output)->_stringify };
 is $@,   '',   "\"$desc\" is parseable as command_output";
 is $res, $exp, "\"$desc\" parses correctly as command_output";
}

while (@string_valid) {
 my ($str, $exp) = splice @string_valid, 0, 2;
 my $desc = sanitize $str;
 local $@;
 my $res = eval { TVV->new(string => $str)->_stringify };
 is $@,   '',   "\"$desc\" is parseable as string";
 is $res, $exp, "\"$desc\" parses correctly as string";
}

sub tvv_s {
 my ($string) = @_;
 local $@;
 eval { TVV->new(string => $string) };
}

my @compare = (
 '1',       '1',      0,
 '1',       '1.0',    0,
 '1',       '1.0.0',  0,
 '1.1',     '1',      1,
 '1.1',     '1.0',    1,
 '1.1',     '1.0.0',  1,
 '1',       '1.1',    -1,
 '1.0',     '1.1',    -1,
 '1.0.0',   '1.1',    -1,
 '1.1',     '1.2',    -1,
 '1.1.0',   '1.2',    -1,
 '1.1',     '1.2.0',  -1,
 '1.1.0',   '1.2.0',  -1,
 '1',       '1',      0,
 '1.0.1',   '1',      1,
 '1.0.1.0', '1',      1,
 '1.0.0.1', '1',      1,
 '1.0.0.1', '1.0.1',  -1,
 '1.0.0.2', '1.0.1',  -1,
 '3.4.0',   '3.4.1',  -1,
 '3.5.2',   '3.5.1',  1,
 '3.12.0',  '3.1.0',  1,
 '3.1.0',   '3.12.0', -1,
);

while (@compare) {
 my ($left, $right, $exp) = splice @compare, 0, 3;

 my $desc = sanitize($left) . ' <=> ' . sanitize($right);

 $left  = tvv_s($left);
 $right = tvv_s($right);

 my ($err, $res) = '';
 if (defined $left and defined $right) {
  local $@;
  $res = eval { $left <=> $right };
  $err = $@;
 } elsif (defined $right) {
  $res = -2;
 } elsif (defined $left) {
  $res = 2;
 }

 is $err, '',   "\"$desc\" compared without croaking";
 is $res, $exp, "\"$desc\" compared correctly";
}

my @stringify = (
 '1',         '1.0.0',
 '1.0',       '1.0.0',
 '1.0.0',     '1.0.0',
 '1.0.0.0',   '1.0.0',
 '1.2',       '1.2.0',
 '1.2.0',     '1.2.0',
 '1.2.0.0',   '1.2.0',
 '1.2.3',     '1.2.3',
 '1.2.3.0',   '1.2.3',
 '1.2.3.4',   '1.2.3.4',
 '1.2.3.4.0', '1.2.3.4',
 '1.0.3',     '1.0.3',
 '1.0.0.4',   '1.0.0.4',
 '1.2.0.4',   '1.2.0.4',
);

while (@stringify) {
 my ($str, $exp) = splice @stringify, 0, 2;
 my $desc = sanitize($str);
 local $@;
 my $res = eval { my $v = TVV->new(string => $str); "$v" };
 is $@,   '',   "\"$desc\" stringification did not croak";
 is $res, $exp, "\"$desc\" stringified correctly";
}