summaryrefslogtreecommitdiff
blob: 8527d81765dd4a896e2b6319dab237ebf0666e22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/bin/bash
# Copyright 1999-2020 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=7
source tests-common.sh

inherit llvm

# llvm_check_deps override to disable has_version use.
# in: ${LLVM_SLOT}
# returns 0 if installed (i.e. == LLVM_INSTALLED_SLOT), 1 otherwise
llvm_check_deps() {
	[[ ${LLVM_SLOT} == ${LLVM_INSTALLED_SLOT} ]]
}

# check_prefix <expected> [<args>...]
# Check output of `get_llvm_prefix <args>...`.
check_prefix() {
	local expected=${1}
	shift

	tbegin "get_llvm_prefix ${*}; inst=${LLVM_INSTALLED_SLOT} -> ${expected}"
	prefix=$(get_llvm_prefix "${@}")
	[[ ${prefix} == ${expected} ]] ||
		eerror "got: ${prefix} != exp: ${expected}"
	tend ${?}
}

# check_setup_path <expected>
# Check PATH after pkg_setup.
check_setup_path() {
	local expected=${1}
	shift

	tbegin "pkg_setup; max=${LLVM_MAX_SLOT}; inst=${LLVM_INSTALLED_SLOT} -> PATH=${expected}"
	path=$(llvm_pkg_setup; echo "${PATH}")
	[[ ${path} == ${expected} ]] ||
		eerror "got: ${path} != exp: ${expected}"
	tend ${?}
}


EAPI=7
BROOT=/broot
SYSROOT=/sysroot
ESYSROOT=/sysroot/eprefix
ROOT=/root
EROOT=/root/eprefix

ebegin "Testing check_setup_path without max slot"
eindent
	LLVM_INSTALLED_SLOT=11 \
	check_prefix /sysroot/eprefix/usr/lib/llvm/11
	LLVM_INSTALLED_SLOT=10 \
	check_prefix /sysroot/eprefix/usr/lib/llvm/10
eoutdent

ebegin "Testing check_setup_path with max slot"
eindent
	LLVM_INSTALLED_SLOT=1* \
	check_prefix /sysroot/eprefix/usr/lib/llvm/11 11
	LLVM_INSTALLED_SLOT=1* \
	check_prefix /sysroot/eprefix/usr/lib/llvm/10 10
	LLVM_INSTALLED_SLOT=10 \
	check_prefix /sysroot/eprefix/usr/lib/llvm/10 11
eoutdent

ebegin "Testing check_setup_path option switches"
eindent
	LLVM_INSTALLED_SLOT=11 \
	check_prefix /broot/usr/lib/llvm/11 -b
	LLVM_INSTALLED_SLOT=11 \
	check_prefix /sysroot/eprefix/usr/lib/llvm/11 -d
eoutdent

ebegin "Testing check_setup_path EAPI 6 API"
eindent
	EAPI=6 \
	LLVM_INSTALLED_SLOT=11 \
	check_prefix /usr/lib/llvm/11 -d
eoutdent

BASEPATH=/usr/lib/ccache/bin:/usr/bin:/usr/sbin:/bin:/sbin

# TODO: cross support?
ESYSROOT=

ebegin "Testing pkg_setup with all installed LLVM versions in PATH"
eindent
	LLVM_MAX_SLOT=11 \
	LLVM_INSTALLED_SLOT=1* \
	PATH=${BASEPATH}:/usr/lib/llvm/11/bin \
	check_setup_path "${BASEPATH}:/usr/lib/llvm/11/bin"

	LLVM_MAX_SLOT=10 \
	LLVM_INSTALLED_SLOT=1* \
	PATH=${BASEPATH}:/usr/lib/llvm/11/bin:/usr/lib/llvm/10/bin \
	check_setup_path "${BASEPATH}:/usr/lib/llvm/10/bin:/usr/lib/llvm/11/bin"

	LLVM_MAX_SLOT=11 \
	LLVM_INSTALLED_SLOT=10 \
	PATH=${BASEPATH}:/usr/lib/llvm/10/bin \
	check_setup_path "${BASEPATH}:/usr/lib/llvm/10/bin"
eoutdent

ebegin "Testing pkg_setup with the other LLVM version in PATH"
eindent
	LLVM_MAX_SLOT=11 \
	LLVM_INSTALLED_SLOT=1* \
	PATH=${BASEPATH}:/usr/lib/llvm/10/bin \
	check_setup_path "${BASEPATH}:/usr/lib/llvm/11/bin:/usr/lib/llvm/10/bin"

	LLVM_MAX_SLOT=10 \
	LLVM_INSTALLED_SLOT=1* \
	PATH=${BASEPATH}:/usr/lib/llvm/11/bin \
	check_setup_path "${BASEPATH}:/usr/lib/llvm/10/bin:/usr/lib/llvm/11/bin"
eoutdent

ebegin "Testing pkg_setup with LLVM missing from PATH"
eindent
	LLVM_MAX_SLOT=11 \
	LLVM_INSTALLED_SLOT=1* \
	PATH=${BASEPATH} \
	check_setup_path "${BASEPATH}:/usr/lib/llvm/11/bin"

	LLVM_MAX_SLOT=10 \
	LLVM_INSTALLED_SLOT=1* \
	PATH=${BASEPATH} \
	check_setup_path "${BASEPATH}:/usr/lib/llvm/10/bin"

	LLVM_MAX_SLOT=11 \
	LLVM_INSTALLED_SLOT=10 \
	PATH=${BASEPATH} \
	check_setup_path "${BASEPATH}:/usr/lib/llvm/10/bin"
eoutdent

texit