]>
Commit | Line | Data |
---|---|---|
38e5a4a5 | 1 | #!/bin/bash |
2cd0a87b DM |
2 | # |
3 | # vercmptest - a test suite for the vercmp/libalpm program | |
4 | # | |
5 | # Copyright (c) 2008 by Dan McGee <dan@archlinux.org> | |
6 | # | |
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. | |
11 | # | |
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. | |
16 | # | |
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/>. | |
19 | ||
20 | # default binary if one was not specified as $1 | |
9263cc58 | 21 | bin=${1:-${PMTEST_UTIL_DIR}vercmp} |
54e1e3e6 | 22 | # holds counts of tests |
d3726bbd AG |
23 | total=92 |
24 | run=0 | |
2cd0a87b DM |
25 | failure=0 |
26 | ||
9263cc58 AG |
27 | # use first arg as our binary if specified |
28 | if ! type -p "$bin"; then | |
29 | echo "Bail out! vercmp binary ($bin) could not be located" | |
30 | exit 1 | |
31 | fi | |
32 | ||
54e1e3e6 DM |
33 | # args: |
34 | # pass ver1 ver2 ret expected | |
35 | pass() { | |
d3726bbd | 36 | echo "ok $run - ver1: $1 ver2: $2 ret: $3" |
54e1e3e6 DM |
37 | } |
38 | ||
2cd0a87b DM |
39 | # args: |
40 | # fail ver1 ver2 ret expected | |
41 | fail() { | |
d3726bbd | 42 | echo "not ok $run - test: ver1: $1 ver2: $2 ret: $3 expected: $4" |
fab66f15 | 43 | ((failure++)) |
2cd0a87b DM |
44 | } |
45 | ||
46 | # args: | |
47 | # runtest ver1 ver2 expected | |
48 | runtest() { | |
54e1e3e6 | 49 | # run the test |
d3726bbd | 50 | ((run++)) |
2cd0a87b | 51 | ret=$($bin $1 $2) |
54e1e3e6 | 52 | func='pass' |
fab66f15 | 53 | [[ -n $ret && $ret -eq $3 ]] || func='fail' |
54e1e3e6 | 54 | $func $1 $2 $ret $3 |
54e1e3e6 | 55 | # and run its mirror case just to be sure |
d3726bbd | 56 | ((run++)) |
54e1e3e6 | 57 | reverse=0 |
fab66f15 DM |
58 | [[ $3 -eq 1 ]] && reverse=-1 |
59 | [[ $3 -eq -1 ]] && reverse=1 | |
54e1e3e6 DM |
60 | ret=$($bin $2 $1) |
61 | func='pass' | |
fab66f15 | 62 | [[ -n $ret && $ret -eq $reverse ]] || func='fail' |
5e4882df | 63 | $func $2 $1 $ret $reverse |
2cd0a87b DM |
64 | } |
65 | ||
d3726bbd AG |
66 | echo "# Running vercmp tests..." |
67 | ||
68 | echo "1..$total" | |
5e4882df | 69 | |
2cd0a87b DM |
70 | # BEGIN TESTS |
71 | ||
72 | # all similar length, no pkgrel | |
73 | runtest 1.5.0 1.5.0 0 | |
2cd0a87b DM |
74 | runtest 1.5.1 1.5.0 1 |
75 | ||
76 | # mixed length | |
2cd0a87b DM |
77 | runtest 1.5.1 1.5 1 |
78 | ||
79 | # with pkgrel, simple | |
80 | runtest 1.5.0-1 1.5.0-1 0 | |
81 | runtest 1.5.0-1 1.5.0-2 -1 | |
82 | runtest 1.5.0-1 1.5.1-1 -1 | |
83 | runtest 1.5.0-2 1.5.1-1 -1 | |
84 | ||
85 | # with pkgrel, mixed lengths | |
86 | runtest 1.5-1 1.5.1-1 -1 | |
87 | runtest 1.5-2 1.5.1-1 -1 | |
88 | runtest 1.5-2 1.5.1-2 -1 | |
89 | ||
90 | # mixed pkgrel inclusion | |
91 | runtest 1.5 1.5-1 0 | |
92 | runtest 1.5-1 1.5 0 | |
54e1e3e6 DM |
93 | runtest 1.1-1 1.1 0 |
94 | runtest 1.0-1 1.1 -1 | |
95 | runtest 1.1-1 1.0 1 | |
2cd0a87b | 96 | |
5e4882df DM |
97 | # alphanumeric versions |
98 | runtest 1.5b-1 1.5-1 -1 | |
99 | runtest 1.5b 1.5 -1 | |
100 | runtest 1.5b-1 1.5 -1 | |
101 | runtest 1.5b 1.5.1 -1 | |
102 | ||
103 | # from the manpage | |
104 | runtest 1.0a 1.0alpha -1 | |
105 | runtest 1.0alpha 1.0b -1 | |
106 | runtest 1.0b 1.0beta -1 | |
107 | runtest 1.0beta 1.0rc -1 | |
108 | runtest 1.0rc 1.0 -1 | |
109 | ||
110 | # going crazy? alpha-dotted versions | |
111 | runtest 1.5.a 1.5 1 | |
112 | runtest 1.5.b 1.5.a 1 | |
113 | runtest 1.5.1 1.5.b 1 | |
114 | ||
115 | # alpha dots and dashes | |
116 | runtest 1.5.b-1 1.5.b 0 | |
117 | runtest 1.5-1 1.5.b -1 | |
118 | ||
30d978a9 DM |
119 | # same/similar content, differing separators |
120 | runtest 2.0 2_0 0 | |
121 | runtest 2.0_a 2_0.a 0 | |
122 | runtest 2.0a 2.0.a -1 | |
123 | runtest 2___a 2_a 1 | |
124 | ||
5c46ba14 DM |
125 | # epoch included version comparisons |
126 | runtest 0:1.0 0:1.0 0 | |
127 | runtest 0:1.0 0:1.1 -1 | |
128 | runtest 1:1.0 0:1.0 1 | |
129 | runtest 1:1.0 0:1.1 1 | |
130 | runtest 1:1.0 2:1.1 -1 | |
131 | ||
132 | # epoch + sometimes present pkgrel | |
133 | runtest 1:1.0 0:1.0-1 1 | |
134 | runtest 1:1.0-1 0:1.1-1 1 | |
135 | ||
136 | # epoch included on one version | |
137 | runtest 0:1.0 1.0 0 | |
138 | runtest 0:1.0 1.1 -1 | |
139 | runtest 0:1.1 1.0 1 | |
140 | runtest 1:1.0 1.0 1 | |
141 | runtest 1:1.0 1.1 1 | |
142 | runtest 1:1.1 1.1 1 | |
143 | ||
2cd0a87b DM |
144 | #END TESTS |
145 | ||
fab66f15 | 146 | if [[ $failure -eq 0 ]]; then |
d3726bbd | 147 | echo "# All $run tests successful" |
2cd0a87b DM |
148 | exit 0 |
149 | fi | |
150 | ||
d3726bbd | 151 | echo "# $failure of $run tests failed" |
2cd0a87b | 152 | exit 1 |