3 # vercmptest - a test suite for the vercmp/libalpm program
5 # Copyright (c) 2008 by Dan McGee <dan@archlinux.org>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 # default binary if one was not specified as $1
22 # holds counts of tests
27 # pass ver1 ver2 ret expected
29 #echo "test: ver1: $1 ver2: $2 ret: $3 expected: $4"
35 # fail ver1 ver2 ret expected
37 echo "test: ver1: $1 ver2: $2 ret: $3 expected: $4"
39 failure
=$
(expr $failure + 1)
43 # runtest ver1 ver2 expected
48 [ $ret -eq $3 ] || func
='fail'
50 total
=$
(expr $total + 1)
51 # and run its mirror case just to be sure
53 [ $3 -eq 1 ] && reverse
=-1
54 [ $3 -eq -1 ] && reverse
=1
57 [ $ret -eq $reverse ] || func
='fail'
58 $func $2 $1 $ret $reverse
59 total
=$
(expr $total + 1)
62 # use first arg as our binary if specified
63 [ -n "$1" ] && bin
="$1"
65 if ! type -p "$bin"; then
66 echo "vercmp binary ($bin) could not be located"
70 echo "Beginning vercmp tests"
74 # all similar length, no pkgrel
82 runtest
1.5.0-1 1.5.0-1 0
83 runtest
1.5.0-1 1.5.0-2 -1
84 runtest
1.5.0-1 1.5.1-1 -1
85 runtest
1.5.0-2 1.5.1-1 -1
87 # with pkgrel, mixed lengths
88 runtest
1.5-1 1.5.1-1 -1
89 runtest
1.5-2 1.5.1-1 -1
90 runtest
1.5-2 1.5.1-2 -1
92 # mixed pkgrel inclusion
99 # alphanumeric versions
100 runtest
1.5b-1
1.5-1 -1
102 runtest
1.5b-1
1.5 -1
103 runtest
1.5b
1.5.1 -1
106 runtest
1.0a
1.0alpha
-1
107 runtest
1.0alpha
1.0b
-1
108 runtest
1.0b
1.0beta
-1
109 runtest
1.0beta
1.0rc
-1
112 # going crazy? alpha-dotted versions
114 runtest
1.5.b
1.5.a
1
115 runtest
1.5.1 1.5.b
1
117 # alpha dots and dashes
118 runtest
1.5.b-1
1.5.b
0
119 runtest
1.5-1 1.5.b
-1
121 # epoch included version comparisons
122 runtest
0:1.0 0:1.0 0
123 runtest
0:1.0 0:1.1 -1
124 runtest
1:1.0 0:1.0 1
125 runtest
1:1.0 0:1.1 1
126 runtest
1:1.0 2:1.1 -1
128 # epoch + sometimes present pkgrel
129 runtest
1:1.0 0:1.0-1 1
130 runtest
1:1.0-1 0:1.1-1 1
132 # epoch included on one version
143 if [ $failure -eq 0 ]; then
144 echo "All $total tests successful"
148 echo "$failure of $total tests failed"