eec0c8ed5a5a40f95e0328ae965c1e9a277f0aea
[platform/upstream/automake.git] / tests / pm / Version.pl
1 # Copyright (C) 2002, 2003, 2009, 2011 Free Software Foundation, Inc.
2 #
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2, or (at your option)
6 # any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
16 use Automake::Version;
17
18 my $failed = 0;
19
20 sub test_version_compare
21 {
22   my ($left, $right, $result) = @_;
23   my @leftver = Automake::Version::split ($left);
24   my @rightver = Automake::Version::split ($right);
25   if ($#leftver == -1)
26   {
27     print "can't grok \"$left\"\n";
28     $failed = 1;
29     return;
30   }
31   if ($#rightver == -1)
32   {
33     print "can't grok \"$right\"\n";
34     $failed = 1;
35     return;
36   }
37   my $res = Automake::Version::compare (@leftver, @rightver);
38   if ($res != $result)
39   {
40     print "compare (\"$left\", \"$right\") = $res! (not $result?)\n";
41     $failed = 1;
42   }
43
44   my $check_expected = ($result == 0 || $result == 1) ? 0 : 1;
45   # Exception for 'foo' fork.
46   $check_expected = 1
47     if ($right =~ /foo/ && !($left =~ /foo/));
48
49   my $check = Automake::Version::check ($left, $right);
50   if ($check != $check_expected)
51   {
52     print "check (\"$left\", \"$right\") = $check! (not $check_expected?)\n";
53     $failed = 1;
54   }
55 }
56
57 sub test_bad_versions
58 {
59   my ($ver) = @_;
60   my @version = Automake::Version::split ($ver);
61   if ($#version != -1)
62   {
63     print "shouldn't grok \"$ver\"\n";
64     $failed = 1;
65   }
66 }
67
68 my @tests = (
69 # basics
70   ['1.0', '2.0', -1],
71   ['2.0', '1.0', 1],
72   ['1.2', '1.2', 0],
73   ['1.1', '1.2', -1],
74   ['1.2', '1.1', 1],
75 # alphas
76   ['1.4', '1.4g', -1],
77   ['1.4g', '1.5', -1],
78   ['1.4g', '1.4', 1],
79   ['1.5', '1.4g', 1],
80   ['1.4a', '1.4g', -1],
81   ['1.5a', '1.3g', 1],
82   ['1.6a', '1.6a', 0],
83 # micros
84   ['1.5.1', '1.5', 1],
85   ['1.5.0', '1.5', 0],
86   ['1.5.4', '1.6.1', -1],
87 # micros and alphas
88   ['1.5a', '1.5.1', 1],
89   ['1.5a', '1.5.1a', 1],
90   ['1.5a', '1.5.1f', 1],
91   ['1.5', '1.5.1a', -1],
92   ['1.5.1a', '1.5.1f', -1],
93   ['1.5.1f', '1.5.1a', 1],
94   ['1.5.1f', '1.5.1f', 0],
95 # special exceptions
96   ['1.6-p5a', '1.6.5a', 0],
97   ['1.6', '1.6-p5a', -1],
98   ['1.6-p4b', '1.6-p5a', -1],
99   ['1.6-p4b', '1.6-foo', 1],
100   ['1.6-p4b', '1.6a-foo', -1],
101   ['1.6-p5', '1.6.5', 0],
102   ['1.6a-foo', '1.6a-foo', 0],
103 );
104
105 my @bad_versions = (
106   '', 'a', '1', '1a', '1.2.3.4', '-1.2'
107 );
108
109 test_version_compare (@{$_}) foreach @tests;
110 test_bad_versions ($_) foreach @bad_versions;
111
112 exit $failed;
113
114 ### Setup "GNU" style for perl-mode and cperl-mode.
115 ## Local Variables:
116 ## perl-indent-level: 2
117 ## perl-continued-statement-offset: 2
118 ## perl-continued-brace-offset: 0
119 ## perl-brace-offset: 0
120 ## perl-brace-imaginary-offset: 0
121 ## perl-label-offset: -2
122 ## cperl-indent-level: 2
123 ## cperl-brace-offset: 0
124 ## cperl-continued-brace-offset: 0
125 ## cperl-label-offset: -2
126 ## cperl-extra-newline-before-brace: t
127 ## cperl-merge-trailing-else: nil
128 ## cperl-continued-statement-offset: 2
129 ## End: