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