6 use Test::More tests => 6 + 6 + 2 * 5 + 2 * 5 + 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 = (
48 for my $failure (@string_failures) {
49 my $desc = sanitize $failure;
51 eval { TVV->new(string => $failure) };
52 like $@, qr/^Invalid argument/,
53 "\"$desc\" correctly failed to parse as string";
57 'valgrind-1' => '1.0.0',
58 'valgrind-1.2' => '1.2.0',
59 'valgrind-1.2.3' => '1.2.3',
60 'valgrind-1.2.4-rc5' => '1.2.4',
61 'valgrind-1.2.6a' => '1.2.6',
64 my @string_valid = map { my $s = $_; $s =~ s/^valgrind-//; $s }
67 while (@command_valid) {
68 my ($output, $exp) = splice @command_valid, 0, 2;
69 my $desc = sanitize $output;
71 my $res = eval { TVV->new(command_output => $output)->_stringify };
72 is $@, '', "\"$desc\" is parseable as command_output";
73 is $res, $exp, "\"$desc\" parses correctly as command_output";
76 while (@string_valid) {
77 my ($str, $exp) = splice @string_valid, 0, 2;
78 my $desc = sanitize $str;
80 my $res = eval { TVV->new(string => $str)->_stringify };
81 is $@, '', "\"$desc\" is parseable as string";
82 is $res, $exp, "\"$desc\" parses correctly as string";
88 eval { TVV->new(string => $string) };
104 '1.1.0', '1.2.0', -1,
109 '1.0.0.1', '1.0.1', -1,
110 '1.0.0.2', '1.0.1', -1,
111 '3.4.0', '3.4.1', -1,
116 my ($left, $right, $exp) = splice @compare, 0, 3;
118 my $desc = sanitize($left) . ' <=> ' . sanitize($right);
120 $left = tvv_s($left);
121 $right = tvv_s($right);
123 my ($err, $res) = '';
124 if (defined $left and defined $right) {
126 $res = eval { $left <=> $right };
128 } elsif (defined $right) {
130 } elsif (defined $left) {
134 is $err, '', "\"$desc\" compared without croaking";
135 is $res, $exp, "\"$desc\" compared correctly";
148 '1.2.3.4', '1.2.3.4',
149 '1.2.3.4.0', '1.2.3.4',
151 '1.0.0.4', '1.0.0.4',
152 '1.2.0.4', '1.2.0.4',
156 my ($str, $exp) = splice @stringify, 0, 2;
157 my $desc = sanitize($str);
159 my $res = eval { my $v = TVV->new(string => $str); "$v" };
160 is $@, '', "\"$desc\" stringification did not croak";
161 is $res, $exp, "\"$desc\" stringified correctly";