Move important information up in -Si output
[pacman-ng.git] / test / util / vercmptest.sh
blob04b841f7ab3cb4827c970af141a1c628f9a68fcc
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++))
42 # args:
43 # runtest ver1 ver2 expected
44 runtest() {
45 # run the test
46 ret=$($bin $1 $2)
47 func='pass'
48 [[ -n $ret && $ret -eq $3 ]] || func='fail'
49 $func $1 $2 $ret $3
50 ((total++))
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 [[ -n $ret && $ret -eq $reverse ]] || func='fail'
58 $func $2 $1 $ret $reverse
59 ((total++))
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 echo
68 exit 1
71 echo "Running vercmp tests..."
73 # BEGIN TESTS
75 # all similar length, no pkgrel
76 runtest 1.5.0 1.5.0 0
77 runtest 1.5.1 1.5.0 1
79 # mixed length
80 runtest 1.5.1 1.5 1
82 # with pkgrel, simple
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
94 runtest 1.5 1.5-1 0
95 runtest 1.5-1 1.5 0
96 runtest 1.1-1 1.1 0
97 runtest 1.0-1 1.1 -1
98 runtest 1.1-1 1.0 1
100 # alphanumeric versions
101 runtest 1.5b-1 1.5-1 -1
102 runtest 1.5b 1.5 -1
103 runtest 1.5b-1 1.5 -1
104 runtest 1.5b 1.5.1 -1
106 # from the manpage
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
111 runtest 1.0rc 1.0 -1
113 # going crazy? alpha-dotted versions
114 runtest 1.5.a 1.5 1
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
123 runtest 2.0 2_0 0
124 runtest 2.0_a 2_0.a 0
125 runtest 2.0a 2.0.a -1
126 runtest 2___a 2_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
140 runtest 0:1.0 1.0 0
141 runtest 0:1.0 1.1 -1
142 runtest 0:1.1 1.0 1
143 runtest 1:1.0 1.0 1
144 runtest 1:1.0 1.1 1
145 runtest 1:1.1 1.1 1
147 #END TESTS
149 if [[ $failure -eq 0 ]]; then
150 echo "All $total tests successful"
151 echo
152 exit 0
155 echo "$failure of $total tests failed"
156 echo
157 exit 1