1# -*- Mode: cperl; coding: utf-8; -*-
2
3use strict;
4use CPAN::Version;
5use vars qw($D $N);
6
7# for debugging uncomment the next two lines
8# use CPAN;
9# $CPAN::DEBUG = 16384;
10
11while (<DATA>) {
12  next if tr/.// > 1 && $]<5.006; # multidot tests are not for pre-5.6.0
13  last if /^__END__$/;
14  chomp;
15  s/\s*#.*//;
16  push @$D, [ split ];
17}
18
19$N = scalar @$D;
20print "1..$N\n";
21
22my $has_sort_versions = eval { require Sort::Versions; 1 };
23my $has_versionpm = eval q{ use version 0.7203; 1 };
24my $has_perl_versionpm = eval { require Perl::Version; 1 };
25while (@$D) {
26  my($l,$r,$exp) = @{shift @$D};
27  my $res = CPAN::Version->vcmp($l,$r);
28  if ($res != $exp){
29    print "# l[$l]r[$r]exp[$exp]res[$res]\n";
30    print "not ";
31  }
32  my @other = ();
33  if ($has_sort_versions) {
34    if (Sort::Versions::versioncmp($l,$r) != $res) {
35      push @other, sprintf "SV: %d", Sort::Versions::versioncmp($l,$r);
36    }
37  }
38  if ($has_versionpm) {
39    local $^W;
40    my $vpack = "version"; # hide the name from 5.004
41    my $vres = eval { $vpack->new($l) cmp $vpack->new($r); };
42    if ($@) {
43      push @other, "v.pm: $@";
44    } elsif ($vres != $res) {
45      push @other, sprintf "v.pm: %d", $vres;
46    }
47  }
48  if ($has_perl_versionpm) {
49    local $^W;
50    my $vpack = "Perl::Version"; # hide the name from 5.004
51    my $vres = eval { $vpack->new($l) cmp $vpack->new($r); };
52    if ($@) {
53      push @other, "PV: $@";
54    } elsif ($vres != $res) {
55      push @other, sprintf "PV: %d", $vres;
56    }
57  }
58  my $other = @other ? " (".join("; ", @other).")" : "";
59  printf "ok %2d # %12s %12s %3d%s\n", $N-@$D, $l, $r, $res, $other;
60  die "Panic" if CPAN::Version->vgt($l,$r) && CPAN::Version->vlt($l,$r);
61}
62
63__END__
640 0 0
651 0 1
660 1 -1
671 1 0
681.1 0.0a 1
691.1a 0.0 1
701.2.3 1.1.1 1
71v1.2.3 v1.1.1 1
72v1.2.3 v1.2.1 1
73v1.2.3 v1.2.11 -1
74v2.4 2.004000 -1
75v2.4 2.004 0
761.2.3 1.2.11 -1
771.9 1.10 1
78VERSION VERSION 0
790.02 undef 1
801.57_00 1.57 1
811.5700 1.57 1
821.57_01 1.57 1
831.88_51 1.8801 1
841.8_8_5_1 1.8801 1
850.2.10 0.2 -1
8620000000.00 19990108 1
871.00 0.96 1
880.7.2 0.7 -1
890.7.02 0.7 -1
900.07.02 0.7 -1
911.3a5 1.3 1
92undef 1.00 -1
93v1.0 undef 1
94v0.2.4 0.24 -1
95v1.0.22 122 -1
961.0.22 122 -1
975.00556 v5.5.560 0
985.005056 v5.5.56 0
995.00557 v5.5.560 1
1005.00056 v5.0.561 -1
1010.0.2 0.000002 0
1021.0.3 1.000003 0
1031.0.1 1.000001 0
1040.0.1 0.000001 0
1050.01.04 0.001004 0
1060.05.18 0.005018 0
1074.08.00 4.008000 0
1080.001.004 0.001004 0
1090.005.018 0.005018 0
1104.008.000 4.008000 0
1114.008.000 4.008 1
112v4.8 4.008 0
113v4.8.0 4.008000 0
114v1.99.1_1 1.98 -1
115v2.3999 v2.4000 -1
116v2.3999 2.004000 1
117v2.3999 2.999999 1
118v2.1000 2.999999 1
1190123 123 -1
120v2.005 2.005 0
121v1.0 1.0 0
122v1.0 1.000 0
123v1.0 1.000000 0
124__END__
125
126# Local Variables:
127# mode: cperl
128# cperl-indent-level: 2
129# End:
130