vercmptest.sh 3.13 KB
Newer Older
1
#!/bin/bash
Dan McGee's avatar
Dan McGee committed
2
3
4
#
# vercmptest - a test suite for the vercmp/libalpm program
#
Allan McRae's avatar
Allan McRae committed
5
#   Copyright (c) 2009-2022 by Pacman Development Team <pacman-dev@lists.archlinux.org>
Dan McGee's avatar
Dan McGee committed
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#   Copyright (c) 2008 by Dan McGee <dan@archlinux.org>
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.

Andrew Gregory's avatar
Andrew Gregory committed
21
22
source "$(dirname "$0")"/../tap.sh || exit 1

Dan McGee's avatar
Dan McGee committed
23
# default binary if one was not specified as $1
24
bin=${1:-${PMTEST_UTIL_DIR}vercmp}
Dan McGee's avatar
Dan McGee committed
25

26
# use first arg as our binary if specified
27
if ! type -p "$bin" &>/dev/null; then
Andrew Gregory's avatar
Andrew Gregory committed
28
	tap_bail "vercmp binary ($bin) could not be located"
29
30
31
	exit 1
fi

Dan McGee's avatar
Dan McGee committed
32
33
# args:
# runtest ver1 ver2 expected
34
tap_runtest() {
Andrew Gregory's avatar
Andrew Gregory committed
35
36
	local ver1=$1 ver2=$2 exp=$3
	tap_is_str "$($bin "$ver1" "$ver2")" "$exp" "$ver1 $ver2"
37
	# and run its mirror case just to be sure
Andrew Gregory's avatar
Andrew Gregory committed
38
39
	(( exp *= -1 ))
	tap_is_str "$($bin "$ver2" "$ver1")" "$exp" "$ver2 $ver1"
Dan McGee's avatar
Dan McGee committed
40
41
}

Andrew Gregory's avatar
Andrew Gregory committed
42
tap_plan 92
Dan McGee's avatar
Dan McGee committed
43
44

# all similar length, no pkgrel
45
46
tap_runtest 1.5.0 1.5.0  0
tap_runtest 1.5.1 1.5.0  1
Dan McGee's avatar
Dan McGee committed
47
48

# mixed length
49
tap_runtest 1.5.1 1.5    1
Dan McGee's avatar
Dan McGee committed
50
51

# with pkgrel, simple
52
53
54
55
tap_runtest 1.5.0-1 1.5.0-1  0
tap_runtest 1.5.0-1 1.5.0-2 -1
tap_runtest 1.5.0-1 1.5.1-1 -1
tap_runtest 1.5.0-2 1.5.1-1 -1
Dan McGee's avatar
Dan McGee committed
56
57

# with pkgrel, mixed lengths
58
59
60
tap_runtest 1.5-1   1.5.1-1 -1
tap_runtest 1.5-2   1.5.1-1 -1
tap_runtest 1.5-2   1.5.1-2 -1
Dan McGee's avatar
Dan McGee committed
61
62

# mixed pkgrel inclusion
63
64
65
66
67
tap_runtest 1.5   1.5-1 0
tap_runtest 1.5-1 1.5   0
tap_runtest 1.1-1 1.1   0
tap_runtest 1.0-1 1.1  -1
tap_runtest 1.1-1 1.0   1
Dan McGee's avatar
Dan McGee committed
68

69
# alphanumeric versions
70
71
72
73
tap_runtest 1.5b-1  1.5-1  -1
tap_runtest 1.5b    1.5    -1
tap_runtest 1.5b-1  1.5    -1
tap_runtest 1.5b    1.5.1  -1
74
75

# from the manpage
76
77
78
79
80
tap_runtest 1.0a     1.0alpha -1
tap_runtest 1.0alpha 1.0b     -1
tap_runtest 1.0b     1.0beta  -1
tap_runtest 1.0beta  1.0rc    -1
tap_runtest 1.0rc    1.0      -1
81
82

# going crazy? alpha-dotted versions
83
84
85
tap_runtest 1.5.a    1.5     1
tap_runtest 1.5.b    1.5.a   1
tap_runtest 1.5.1    1.5.b   1
86
87

# alpha dots and dashes
88
89
tap_runtest 1.5.b-1  1.5.b   0
tap_runtest 1.5-1    1.5.b  -1
90

91
# same/similar content, differing separators
92
93
94
95
tap_runtest 2.0    2_0     0
tap_runtest 2.0_a  2_0.a   0
tap_runtest 2.0a   2.0.a  -1
tap_runtest 2___a  2_a     1
96

97
# epoch included version comparisons
98
99
100
101
102
tap_runtest 0:1.0    0:1.0   0
tap_runtest 0:1.0    0:1.1  -1
tap_runtest 1:1.0    0:1.0   1
tap_runtest 1:1.0    0:1.1   1
tap_runtest 1:1.0    2:1.1  -1
103
104

# epoch + sometimes present pkgrel
105
106
tap_runtest 1:1.0    0:1.0-1  1
tap_runtest 1:1.0-1  0:1.1-1  1
107
108

# epoch included on one version
109
110
111
112
113
114
tap_runtest 0:1.0    1.0   0
tap_runtest 0:1.0    1.1  -1
tap_runtest 0:1.1    1.0   1
tap_runtest 1:1.0    1.0   1
tap_runtest 1:1.0    1.1   1
tap_runtest 1:1.1    1.1   1
115

Andrew Gregory's avatar
Andrew Gregory committed
116
tap_finish