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"
43 # runtest ver1 ver2 expected
48 [[ -n $ret && $ret -eq $3 ]] || func
='fail'
51 # and run its mirror case just to be sure
53 [[ $3 -eq 1 ]] && reverse
=-1
54 [[ $3 -eq -1 ]] && reverse
=1
57 [[ -n $ret && $ret -eq $reverse ]] || func
='fail'
58 $func $2 $1 $ret $reverse
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"
71 echo "Running vercmp tests..."
75 # all similar length, no pkgrel
83 runtest
1.5.0-1 1.5.0-1 0
84 runtest
1.5.0-1 1.5.0-2 -1
85 runtest
1.5.0-1 1.5.1-1 -1
86 runtest
1.5.0-2 1.5.1-1 -1
88 # with pkgrel, mixed lengths
89 runtest
1.5-1 1.5.1-1 -1
90 runtest
1.5-2 1.5.1-1 -1
91 runtest
1.5-2 1.5.1-2 -1
93 # mixed pkgrel inclusion
100 # alphanumeric versions
101 runtest
1.5b-1
1.5-1 -1
103 runtest
1.5b-1
1.5 -1
104 runtest
1.5b
1.5.1 -1
107 runtest
1.0a
1.0alpha
-1
108 runtest
1.0alpha
1.0b
-1
109 runtest
1.0b
1.0beta
-1
110 runtest
1.0beta
1.0rc
-1
113 # going crazy? alpha-dotted versions
115 runtest
1.5.b
1.5.a
1
116 runtest
1.5.1 1.5.b
1
118 # alpha dots and dashes
119 runtest
1.5.b-1
1.5.b
0
120 runtest
1.5-1 1.5.b
-1
122 # same/similar content, differing separators
124 runtest
2.0_a
2_0.a
0
125 runtest
2.0a
2.0.a
-1
128 # epoch included version comparisons
129 runtest
0:1.0 0:1.0 0
130 runtest
0:1.0 0:1.1 -1
131 runtest
1:1.0 0:1.0 1
132 runtest
1:1.0 0:1.1 1
133 runtest
1:1.0 2:1.1 -1
135 # epoch + sometimes present pkgrel
136 runtest
1:1.0 0:1.0-1 1
137 runtest
1:1.0-1 0:1.1-1 1
139 # epoch included on one version
149 if [[ $failure -eq 0 ]]; then
150 echo "All $total tests successful"
155 echo "$failure of $total tests failed"