6 use Test::More tests => 6 + 5 + 4 * 8 + 2 * 21 + 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',
66 my @string_valid = map { my $s = $_; $s =~ s/^valgrind-//; $s }
69 while (@command_valid) {
70 my ($output, $exp) = splice @command_valid, 0, 2;
71 my $desc = sanitize $output;
73 my $res = eval { TVV->new(command_output => $output)->_stringify };
74 is $@, '', "\"$desc\" is parseable as command_output";
75 is $res, $exp, "\"$desc\" parses correctly as command_output";
78 while (@string_valid) {
79 my ($str, $exp) = splice @string_valid, 0, 2;
80 my $desc = sanitize $str;
82 my $res = eval { TVV->new(string => $str)->_stringify };
83 is $@, '', "\"$desc\" is parseable as string";
84 is $res, $exp, "\"$desc\" parses correctly as string";
90 eval { TVV->new(string => $string) };
106 '1.1.0', '1.2.0', -1,
111 '1.0.0.1', '1.0.1', -1,
112 '1.0.0.2', '1.0.1', -1,
113 '3.4.0', '3.4.1', -1,
118 my ($left, $right, $exp) = splice @compare, 0, 3;
120 my $desc = sanitize($left) . ' <=> ' . sanitize($right);
122 $left = tvv_s($left);
123 $right = tvv_s($right);
125 my ($err, $res) = '';
126 if (defined $left and defined $right) {
128 $res = eval { $left <=> $right };
130 } elsif (defined $right) {
132 } elsif (defined $left) {
136 is $err, '', "\"$desc\" compared without croaking";
137 is $res, $exp, "\"$desc\" compared correctly";
150 '1.2.3.4', '1.2.3.4',
151 '1.2.3.4.0', '1.2.3.4',
153 '1.0.0.4', '1.0.0.4',
154 '1.2.0.4', '1.2.0.4',
158 my ($str, $exp) = splice @stringify, 0, 2;
159 my $desc = sanitize($str);
161 my $res = eval { my $v = TVV->new(string => $str); "$v" };
162 is $@, '', "\"$desc\" stringification did not croak";
163 is $res, $exp, "\"$desc\" stringified correctly";