1 # Copyright (C) 2002-2024 Free Software Foundation, Inc.
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)
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.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <https://www.gnu.org/licenses/>.
16 use Automake
::Version
;
20 sub test_version_compare
22 my ($left, $right, $result) = @_;
23 my @leftver = Automake
::Version
::split ($left);
24 my @rightver = Automake
::Version
::split ($right);
27 print "can't grok \"$left\"\n";
33 print "can't grok \"$right\"\n";
37 my $res = Automake
::Version
::compare
(@leftver, @rightver);
40 print "compare (\"$left\", \"$right\") = $res! (not $result?)\n";
44 my $check_expected = ($result == 0 || $result == 1) ?
0 : 1;
45 # Exception for 'foo' fork.
47 if ($right =~ /foo/ && !($left =~ /foo/));
49 my $check = Automake
::Version
::check
($left, $right);
50 if ($check != $check_expected)
52 print "check (\"$left\", \"$right\") = $check! (not $check_expected?)\n";
60 my @version = Automake
::Version
::split ($ver);
63 print "shouldn't grok \"$ver\"\n";
86 ['1.5.4', '1.6.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],
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],
106 '', 'a', '1', '1a', '1.2.3.4', '-1.2'
109 test_version_compare
(@
{$_}) foreach @tests;
110 test_bad_versions
($_) foreach @bad_versions;