6 use Test::More tests => 6 + 5 + 4 * 9 + 2 * 23 + 2 * 14;
8 use Test::Valgrind::Version;
10 sub TVV () { 'Test::Valgrind::Version' }
15 $str = '(undef)' unless defined $str;
22 my @command_failures = (
28 "doo dah doo\nvalgrind-1.2.3",
31 for my $failure (@command_failures) {
32 my $desc = sanitize $failure;
34 eval { TVV->new(command_output => $failure) };
35 like $@, qr/^Invalid argument/,
36 "\"$desc\" correctly failed to parse as command_output";
39 my @string_failures = (
47 for my $failure (@string_failures) {
48 my $desc = sanitize $failure;
50 eval { TVV->new(string => $failure) };
51 like $@, qr/^Invalid argument/,
52 "\"$desc\" correctly failed to parse as string";
56 'valgrind-1' => '1.0.0',
57 'valgrind-1.2' => '1.2.0',
58 'valgrind-1.2.3' => '1.2.3',
59 'valgrind-1.2.4-rc5' => '1.2.4',
60 'valgrind-1.2.6a' => '1.2.6',
61 'valgrind-1.2.7.' => '1.2.7',
62 'valgrind-1.2.x.8' => '1.2.0',
63 'valgrind-1.10.' => '1.10.0',
64 'valgrind-3.12.0.SVN' => '3.12.0',
67 my @string_valid = map { my $s = $_; $s =~ s/^valgrind-//; $s }
70 while (@command_valid) {
71 my ($output, $exp) = splice @command_valid, 0, 2;
72 my $desc = sanitize $output;
74 my $res = eval { TVV->new(command_output => $output)->_stringify };
75 is $@, '', "\"$desc\" is parseable as command_output";
76 is $res, $exp, "\"$desc\" parses correctly as command_output";
79 while (@string_valid) {
80 my ($str, $exp) = splice @string_valid, 0, 2;
81 my $desc = sanitize $str;
83 my $res = eval { TVV->new(string => $str)->_stringify };
84 is $@, '', "\"$desc\" is parseable as string";
85 is $res, $exp, "\"$desc\" parses correctly as string";
91 eval { TVV->new(string => $string) };
107 '1.1.0', '1.2.0', -1,
112 '1.0.0.1', '1.0.1', -1,
113 '1.0.0.2', '1.0.1', -1,
114 '3.4.0', '3.4.1', -1,
116 '3.12.0', '3.1.0', 1,
117 '3.1.0', '3.12.0', -1,
121 my ($left, $right, $exp) = splice @compare, 0, 3;
123 my $desc = sanitize($left) . ' <=> ' . sanitize($right);
125 $left = tvv_s($left);
126 $right = tvv_s($right);
128 my ($err, $res) = '';
129 if (defined $left and defined $right) {
131 $res = eval { $left <=> $right };
133 } elsif (defined $right) {
135 } elsif (defined $left) {
139 is $err, '', "\"$desc\" compared without croaking";
140 is $res, $exp, "\"$desc\" compared correctly";
153 '1.2.3.4', '1.2.3.4',
154 '1.2.3.4.0', '1.2.3.4',
156 '1.0.0.4', '1.0.0.4',
157 '1.2.0.4', '1.2.0.4',
161 my ($str, $exp) = splice @stringify, 0, 2;
162 my $desc = sanitize($str);
164 my $res = eval { my $v = TVV->new(string => $str); "$v" };
165 is $@, '', "\"$desc\" stringification did not croak";
166 is $res, $exp, "\"$desc\" stringified correctly";