028d837417cff1c5b9b43433222da83e9e91f985
[platform/upstream/automake.git] / lib / Automake / tests / Version.pl
1 # Copyright (C) 2002, 2003  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 Automake; see the file COPYING.  If not, write to
17 # the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 # Boston, MA 02110-1301, USA.
19
20 use Automake::Version;
21
22 my $failed = 0;
23
24 sub test_version_compare
25 {
26   my ($left, $right, $result) = @_;
27   my @leftver = Automake::Version::split ($left);
28   my @rightver = Automake::Version::split ($right);
29   if ($#leftver == -1)
30   {
31     print "can't grok \"$left\"\n";
32     $failed = 1;
33     return;
34   }
35   if ($#rightver == -1)
36   {
37     print "can't grok \"$right\"\n";
38     $failed = 1;
39     return;
40   }
41   my $res = Automake::Version::compare (@leftver, @rightver);
42   if ($res != $result)
43   {
44     print "compare (\"$left\", \"$right\") = $res! (not $result?)\n";
45     $failed = 1;
46   }
47 }
48
49 my @tests = (
50 # basics
51   ['1.0', '2.0', -1],
52   ['2.0', '1.0', 1],
53   ['1.2', '1.2', 0],
54   ['1.1', '1.2', -1],
55   ['1.2', '1.1', 1],
56 # alphas
57   ['1.4', '1.4g', -1],
58   ['1.4g', '1.5', -1],
59   ['1.4g', '1.4', 1],
60   ['1.5', '1.4g', 1],
61   ['1.4a', '1.4g', -1],
62   ['1.5a', '1.3g', 1],
63   ['1.6a', '1.6a', 0],
64 # micros
65   ['1.5.1', '1.5', 1],
66   ['1.5.0', '1.5', 0],
67   ['1.5.4', '1.6.1', -1],
68 # micros and alphas
69   ['1.5a', '1.5.1', 1],
70   ['1.5a', '1.5.1a', 1],
71   ['1.5a', '1.5.1f', 1],
72   ['1.5', '1.5.1a', -1],
73   ['1.5.1a', '1.5.1f', -1],
74 # special exceptions
75   ['1.6-p5a', '1.6.5a', 0],
76   ['1.6', '1.6-p5a', -1],
77   ['1.6-p4b', '1.6-p5a', -1],
78   ['1.6-p4b', '1.6-foo', 1],
79   ['1.6-p4b', '1.6a-foo', -1]
80 );
81
82 test_version_compare (@{$_}) foreach @tests;
83
84 exit $failed;
85
86 ### Setup "GNU" style for perl-mode and cperl-mode.
87 ## Local Variables:
88 ## perl-indent-level: 2
89 ## perl-continued-statement-offset: 2
90 ## perl-continued-brace-offset: 0
91 ## perl-brace-offset: 0
92 ## perl-brace-imaginary-offset: 0
93 ## perl-label-offset: -2
94 ## cperl-indent-level: 2
95 ## cperl-brace-offset: 0
96 ## cperl-continued-brace-offset: 0
97 ## cperl-label-offset: -2
98 ## cperl-extra-newline-before-brace: t
99 ## cperl-merge-trailing-else: nil
100 ## cperl-continued-statement-offset: 2
101 ## End: