versions.t (1855B)
1 #!/usr/bin/perl 2 #$Id: versions.t,v 1.9 2003/08/24 22:33:03 ed Exp $ 3 4 use 5.006; 5 use strict; 6 use warnings; 7 8 use Sort::Versions; 9 use Test::More; 10 11 my @tests; 12 13 while(<DATA>) { 14 if(/^\s*(\S+)\s*([<>])\s*(\S+)\s*$/) { 15 push @tests, $1,$3 if $2 eq "<"; 16 push @tests, $3,$1 if $2 eq ">"; 17 } 18 } 19 20 plan tests => (@tests / 2 * 3) + 3; 21 22 my @l = sort versions qw(1.2 1.2a); 23 is($l[0], "1.2"); 24 25 @l = sort { versioncmp($a, $b) } qw(1.2 1.2a); 26 is($l[0], "1.2"); 27 28 SKIP: { 29 skip "requires perl 5.6.0", 1 unless ($] >= 5.006); 30 @l = sort versioncmp qw(1.2 1.2a); 31 is($l[0], "1.2"); 32 } 33 34 my $i=4; 35 while (@tests) { 36 ($a, $b) = @tests[0, 1]; 37 38 # Test both the versioncmp() and versions() interfaces, in both 39 # the main package and other packages. 40 # 41 is(versions(), -1, "versions($a, $b)"); 42 $i++; 43 44 is(versioncmp($a, $b), -1, "versioncmp($a, $b)"); 45 $i++; 46 47 undef $a; undef $b; # just in case 48 49 eval { 50 package Foo; 51 use Sort::Versions; 52 ($a, $b) = @tests[0, 1]; 53 54 if (versions() != -1) { 55 die "failed versions() in foreign package"; 56 } 57 58 if (versioncmp($a, $b) != -1) { 59 die "failed versioncmp() in foreign package"; 60 } 61 }; 62 if ($@) { 63 fail($@); 64 } 65 else { 66 pass("foreign package tests ($tests[0], $tests[1])"); 67 } 68 69 shift @tests; shift @tests; 70 } 71 72 73 __END__ 74 75 # Simple . only tests 76 1.2 < 1.3 77 1.2 < 1.2.1 78 1.2.1 < 1.3 79 1.2 < 1.2a 80 1.2a < 1.3 81 1.2 < 1.2.b 82 1.2.1 < 1.2a 83 1.2.b < 1.2a 84 85 # Assorted non-numerics 86 a < b 87 a < a.b 88 a.b < a.c 89 a.1 < a.a 90 1 < a 91 1a < a 92 1a < 2 93 94 # Null version point 95 1..1 < 1.1.1 96 97 # Leading 0 tests 98 1 > 0002 99 1.5 > 1.06 100 101 # Handling mixed -. versions 102 1 < 1-1 103 1-1 < 1-2 104 1-2 < 1.2 105 1-2 < 1.0-1 106 1-2 < 1.0 107 1-2 < 1.3 108 1.2-1 < 1.2a-1 109 1.3-4.6-7 < 1.3-4.8 110 1.3-4.6-7 < 1.3-4.6.7 111 1.3-4a-7 < 1.3-4a-7.4 112 113 # 'Bug' reported by pgw99 114 1.2-1 < 1.2.1-1 115 1.2.1-1 < 1.2.1-2 116 1.2.1-2 < 1.3.0-1