pacman-key: rename --del to --delete
[pacman-ng.git] / test / util / vercmptest.sh
blob7ebeba534c5930fde0643a6f7e3bf9a583d4bde0
1 #!/bin/bash
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
21 bin='vercmp'
22 # holds counts of tests
23 total=0
24 failure=0
26 # args:
27 # pass ver1 ver2 ret expected
28 pass() {
29 #echo "test: ver1: $1 ver2: $2 ret: $3 expected: $4"
30 #echo " --> pass"
31 echo -n
34 # args:
35 # fail ver1 ver2 ret expected
36 fail() {
37 echo "test: ver1: $1 ver2: $2 ret: $3 expected: $4"
38 echo " ==> FAILURE"
39 failure=$(expr $failure + 1)
42 # args:
43 # runtest ver1 ver2 expected
44 runtest() {
45 # run the test
46 ret=$($bin $1 $2)
47 func='pass'
48 [ $ret -eq $3 ] || func='fail'
49 $func $1 $2 $ret $3
50 total=$(expr $total + 1)
51 # and run its mirror case just to be sure
52 reverse=0
53 [ $3 -eq 1 ] && reverse=-1
54 [ $3 -eq -1 ] && reverse=1
55 ret=$($bin $2 $1)
56 func='pass'
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"
67 exit 1
70 echo "Beginning vercmp tests"
72 # BEGIN TESTS
74 # all similar length, no pkgrel
75 runtest 1.5.0 1.5.0 0
76 runtest 1.5.1 1.5.0 1
78 # mixed length
79 runtest 1.5.1 1.5 1
81 # with pkgrel, simple
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
93 runtest 1.5 1.5-1 0
94 runtest 1.5-1 1.5 0
95 runtest 1.1-1 1.1 0
96 runtest 1.0-1 1.1 -1
97 runtest 1.1-1 1.0 1
99 # alphanumeric versions
100 runtest 1.5b-1 1.5-1 -1
101 runtest 1.5b 1.5 -1
102 runtest 1.5b-1 1.5 -1
103 runtest 1.5b 1.5.1 -1
105 # from the manpage
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
110 runtest 1.0rc 1.0 -1
112 # going crazy? alpha-dotted versions
113 runtest 1.5.a 1.5 1
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
133 runtest 0:1.0 1.0 0
134 runtest 0:1.0 1.1 -1
135 runtest 0:1.1 1.0 1
136 runtest 1:1.0 1.0 1
137 runtest 1:1.0 1.1 1
138 runtest 1:1.1 1.1 1
140 #END TESTS
142 echo
143 if [ $failure -eq 0 ]; then
144 echo "All $total tests successful"
145 exit 0
148 echo "$failure of $total tests failed"
149 exit 1