add eclass from gentoo main repo

This commit is contained in:
ace
2021-02-06 20:03:46 +03:00
parent 6d4415db6c
commit 4620f15444
222 changed files with 66533 additions and 0 deletions

View File

@ -0,0 +1,31 @@
#!/bin/bash
# Copyright 1999-2015 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
source tests-common.sh
inherit autotools
test-it() {
tbegin "eaclocal_amflags $1: $2"
printf "ACLOCAL_AMFLAGS = %b\n" "$2" > Makefile.am
local flags=$(eaclocal_amflags) exp=${3:-$2}
[[ "${flags}" == "${exp}" ]]
if ! tend $? ; then
printf '### INPUT:\n%s\n' "$2"
printf '### FILE:\n%s\n' "$(<Makefile.am)"
printf '### EXPECTED:\n%s\n' "${exp}"
printf '### ACTUAL:\n%s\n' "${flags}"
fi
rm Makefile.am
}
test-it simple "-Im4"
test-it simple "-I m4 -I lakdjfladsfj /////"
test-it shell-exec '`echo hi`' "hi"
test-it shell-exec '`echo {0..3}`' "0 1 2 3"
test-it multiline '-I oneline \\\n\t-I twoline' "-I oneline -I twoline"
texit

142
eclass/tests/distutils-r1.sh Executable file
View File

@ -0,0 +1,142 @@
#!/bin/bash
# Copyright 1999-2020 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=7
PYTHON_COMPAT=( python3_8 )
source tests-common.sh
test-phase_name_free() {
local ph=${1}
if declare -f "${ph}"; then
die "${ph} function declared while name reserved for phase!"
fi
if declare -f "${ph}_all"; then
die "${ph}_all function declared while name reserved for phase!"
fi
}
test-distutils_enable_tests() {
local runner=${1}
local exp_IUSE=${2}
local exp_RESTRICT=${3}
local exp_BDEPEND=${4}
local IUSE=${IUSE}
local RESTRICT=${RESTRICT}
local BDEPEND=${BDEPEND}
tbegin "${runner}"
distutils_enable_tests "${runner}"
local ret var val
for var in IUSE RESTRICT BDEPEND; do
local exp_var=exp_${var}
# (this normalizes whitespace)
read -d $'\0' -r -a val <<<"${!var}"
val=${val[*]}
if [[ ${val} != "${!exp_var}" ]]; then
eindent
eerror "${var} expected: ${!exp_var}"
eerror "${var} actual: ${val}"
eoutdent
ret=1
tret=1
fi
done
tend ${ret}
}
test-DISTUTILS_USE_SETUPTOOLS() {
local DISTUTILS_USE_SETUPTOOLS=${1}
local exp_BDEPEND=${2}
local exp_RDEPEND=${3}
tbegin "${1}"
local BDEPEND=
local RDEPEND=
unset _DISTUTILS_R1
inherit distutils-r1
local ret var val
for var in BDEPEND RDEPEND; do
local exp_var=exp_${var}
# (this normalizes whitespace)
read -d $'\0' -r -a val <<<"${!var}"
val=${val[*]}
if [[ ${val} != "${!exp_var}" ]]; then
eindent
eerror "${var} expected: ${!exp_var}"
eerror "${var} actual: ${val}"
eoutdent
ret=1
tret=1
fi
done
tend ${ret}
}
DISTUTILS_USE_SETUPTOOLS=no
inherit distutils-r1
tbegin "sane function names"
test-phase_name_free python_prepare
test-phase_name_free python_configure
test-phase_name_free python_compile
test-phase_name_free python_test
test-phase_name_free python_install
tend
einfo distutils_enable_tests
eindent
BASE_IUSE="python_targets_python3_8"
BASE_DEPS="python_targets_python3_8? ( dev-lang/python:3.8 ) >=dev-lang/python-exec-2:=[python_targets_python3_8(-)?,-python_single_target_python3_8(-)]"
TEST_RESTRICT="!test? ( test )"
einfo "empty RDEPEND"
eindent
RDEPEND=""
test-distutils_enable_tests pytest \
"${BASE_IUSE} test" "${TEST_RESTRICT}" "${BASE_DEPS} test? ( >=dev-python/pytest-4.5.0[${PYTHON_USEDEP}] )"
test-distutils_enable_tests nose \
"${BASE_IUSE} test" "${TEST_RESTRICT}" "${BASE_DEPS} test? ( >=dev-python/nose-1.3.7-r4[${PYTHON_USEDEP}] )"
test-distutils_enable_tests unittest \
"${BASE_IUSE}" "" "${BASE_DEPS}"
test-distutils_enable_tests setup.py \
"${BASE_IUSE}" "" "${BASE_DEPS}"
eoutdent
einfo "non-empty RDEPEND"
eindent
BASE_RDEPEND="dev-python/foo[${PYTHON_USEDEP}]"
RDEPEND=${BASE_RDEPEND}
test-distutils_enable_tests pytest \
"${BASE_IUSE} test" "${TEST_RESTRICT}" "${BASE_DEPS} test? ( ${BASE_RDEPEND} >=dev-python/pytest-4.5.0[${PYTHON_USEDEP}] )"
test-distutils_enable_tests nose \
"${BASE_IUSE} test" "${TEST_RESTRICT}" "${BASE_DEPS} test? ( ${BASE_RDEPEND} >=dev-python/nose-1.3.7-r4[${PYTHON_USEDEP}] )"
test-distutils_enable_tests unittest \
"${BASE_IUSE} test" "${TEST_RESTRICT}" "${BASE_DEPS} test? ( ${BASE_RDEPEND} )"
test-distutils_enable_tests setup.py \
"${BASE_IUSE} test" "${TEST_RESTRICT}" "${BASE_DEPS} test? ( ${BASE_RDEPEND} )"
eoutdent
eoutdent
einfo DISTUTILS_USE_SETUPTOOLS
eindent
SETUPTOOLS_DEP=">=dev-python/setuptools-42.0.2[python_targets_python3_8(-)?,-python_single_target_python3_8(-)]"
test-DISTUTILS_USE_SETUPTOOLS no "${BASE_DEPS}" "${BASE_DEPS}"
test-DISTUTILS_USE_SETUPTOOLS bdepend "${BASE_DEPS} ${SETUPTOOLS_DEP}" "${BASE_DEPS}"
test-DISTUTILS_USE_SETUPTOOLS rdepend "${BASE_DEPS} ${SETUPTOOLS_DEP}" "${BASE_DEPS} ${SETUPTOOLS_DEP}"
test-DISTUTILS_USE_SETUPTOOLS pyproject.toml "${BASE_DEPS} dev-python/pyproject2setuppy[python_targets_python3_8(-)?,-python_single_target_python3_8(-)]" "${BASE_DEPS}"
test-DISTUTILS_USE_SETUPTOOLS manual "${BASE_DEPS}" "${BASE_DEPS}"
eoutdent
texit

View File

@ -0,0 +1,122 @@
#!/bin/bash
# Copyright 1999-2020 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=7
PYTHON_COMPAT=( python3_8 )
source tests-common.sh
test-distutils_enable_tests() {
local runner=${1}
local exp_IUSE=${2}
local exp_RESTRICT=${3}
local exp_BDEPEND=${4}
local IUSE=${IUSE}
local RESTRICT=${RESTRICT}
local BDEPEND=${BDEPEND}
tbegin "${runner}"
distutils_enable_tests "${runner}"
local ret var
for var in IUSE RESTRICT BDEPEND; do
local exp_var=exp_${var}
# (this normalizes whitespace)
read -d $'\0' -r -a val <<<"${!var}"
val=${val[*]}
if [[ ${val} != "${!exp_var}" ]]; then
eindent
eerror "${var} expected: ${!exp_var}"
eerror "${var} actual: ${val}"
eoutdent
ret=1
tret=1
fi
done
tend ${ret}
}
test-DISTUTILS_USE_SETUPTOOLS() {
local DISTUTILS_USE_SETUPTOOLS=${1}
local exp_BDEPEND=${2}
local exp_RDEPEND=${3}
tbegin "${1}"
local BDEPEND=
local RDEPEND=
unset _DISTUTILS_R1
inherit distutils-r1
local ret var val
for var in BDEPEND RDEPEND; do
local exp_var=exp_${var}
# (this normalizes whitespace)
read -d $'\0' -r -a val <<<"${!var}"
val=${val[*]}
if [[ ${val} != "${!exp_var}" ]]; then
eindent
eerror "${var} expected: ${!exp_var}"
eerror "${var} actual: ${val}"
eoutdent
ret=1
tret=1
fi
done
tend ${ret}
}
DISTUTILS_USE_SETUPTOOLS=no
DISTUTILS_SINGLE_IMPL=1
inherit distutils-r1
einfo distutils_enable_tests
eindent
BASE_IUSE="+python_single_target_python3_8"
BASE_DEPS="python_single_target_python3_8? ( dev-lang/python:3.8 >=dev-lang/python-exec-2:=[python_targets_python3_8] )"
TEST_RESTRICT="!test? ( test )"
einfo "empty RDEPEND"
eindent
RDEPEND=""
test-distutils_enable_tests pytest \
"${BASE_IUSE} test" "${TEST_RESTRICT}" "${BASE_DEPS} test? ( python_single_target_python3_8? ( >=dev-python/pytest-4.5.0[python_targets_python3_8(-)] ) )"
test-distutils_enable_tests nose \
"${BASE_IUSE} test" "${TEST_RESTRICT}" "${BASE_DEPS} test? ( python_single_target_python3_8? ( >=dev-python/nose-1.3.7-r4[python_targets_python3_8(-)] ) )"
test-distutils_enable_tests unittest \
"${BASE_IUSE}" "" "${BASE_DEPS}"
test-distutils_enable_tests setup.py \
"${BASE_IUSE}" "" "${BASE_DEPS}"
eoutdent
einfo "non-empty RDEPEND"
eindent
BASE_RDEPEND="dev-python/foo[${PYTHON_SINGLE_USEDEP}]"
RDEPEND=${BASE_RDEPEND}
test-distutils_enable_tests pytest \
"${BASE_IUSE} test" "${TEST_RESTRICT}" "${BASE_DEPS} test? ( ${BASE_RDEPEND} python_single_target_python3_8? ( >=dev-python/pytest-4.5.0[python_targets_python3_8(-)] ) )"
test-distutils_enable_tests nose \
"${BASE_IUSE} test" "${TEST_RESTRICT}" "${BASE_DEPS} test? ( ${BASE_RDEPEND} python_single_target_python3_8? ( >=dev-python/nose-1.3.7-r4[python_targets_python3_8(-)] ) )"
test-distutils_enable_tests unittest \
"${BASE_IUSE} test" "${TEST_RESTRICT}" "${BASE_DEPS} test? ( ${BASE_RDEPEND} )"
test-distutils_enable_tests setup.py \
"${BASE_IUSE} test" "${TEST_RESTRICT}" "${BASE_DEPS} test? ( ${BASE_RDEPEND} )"
eoutdent
eoutdent
einfo DISTUTILS_USE_SETUPTOOLS
eindent
SETUPTOOLS_DEP="python_single_target_python3_8? ( >=dev-python/setuptools-42.0.2[python_targets_python3_8(-)] )"
test-DISTUTILS_USE_SETUPTOOLS no "${BASE_DEPS}" "${BASE_DEPS}"
test-DISTUTILS_USE_SETUPTOOLS bdepend "${BASE_DEPS} ${SETUPTOOLS_DEP}" "${BASE_DEPS}"
test-DISTUTILS_USE_SETUPTOOLS rdepend "${BASE_DEPS} ${SETUPTOOLS_DEP}" "${BASE_DEPS} ${SETUPTOOLS_DEP}"
test-DISTUTILS_USE_SETUPTOOLS pyproject.toml "${BASE_DEPS} python_single_target_python3_8? ( dev-python/pyproject2setuppy[python_targets_python3_8(-)] )" "${BASE_DEPS}"
test-DISTUTILS_USE_SETUPTOOLS manual "${BASE_DEPS}" "${BASE_DEPS}"
eoutdent
texit

177
eclass/tests/eapi7-ver.sh Executable file
View File

@ -0,0 +1,177 @@
#!/bin/bash
# Copyright 1999-2017 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
EAPI=6
source tests-common.sh
inherit eapi7-ver
teq() {
local expected=${1}; shift
tbegin "${*} -> ${expected}"
local got=$("${@}")
[[ ${got} == ${expected} ]]
tend ${?} "returned: ${got}"
}
teqr() {
local expected=$1; shift
tbegin "$* -> ${expected}"
"$@"
local ret=$?
[[ ${ret} -eq ${expected} ]]
tend $? "returned: ${ret}"
}
txf() {
tbegin "XFAIL: ${*}"
local got=$("${@}" 2>&1)
[[ ${got} == die:* ]]
tend ${?} "function did not die"
}
teq 1 ver_cut 1 1.2.3
teq 1 ver_cut 1-1 1.2.3
teq 1.2 ver_cut 1-2 1.2.3
teq 2.3 ver_cut 2- 1.2.3
teq 1.2.3 ver_cut 1- 1.2.3
teq 3b ver_cut 3-4 1.2.3b_alpha4
teq alpha ver_cut 5 1.2.3b_alpha4
teq 1.2 ver_cut 1-2 .1.2.3
teq .1.2 ver_cut 0-2 .1.2.3
teq 2.3 ver_cut 2-3 1.2.3.
teq 2.3. ver_cut 2- 1.2.3.
teq 2.3. ver_cut 2-4 1.2.3.
teq 1-2.3 ver_rs 1 - 1.2.3
teq 1.2-3 ver_rs 2 - 1.2.3
teq 1-2-3.4 ver_rs 1-2 - 1.2.3.4
teq 1.2-3-4 ver_rs 2- - 1.2.3.4
teq 1.2.3 ver_rs 2 . 1.2-3
teq 1.2.3.a ver_rs 3 . 1.2.3a
teq 1.2-alpha-4 ver_rs 2-3 - 1.2_alpha4
teq 1.23-b_alpha4 ver_rs 3 - 2 "" 1.2.3b_alpha4
teq a1b_2-c-3-d4e5 ver_rs 3-5 _ 4-6 - a1b2c3d4e5
teq .1-2.3 ver_rs 1 - .1.2.3
teq -1.2.3 ver_rs 0 - .1.2.3
# truncating range
teq 1.2 ver_cut 0-2 1.2.3
teq 2.3 ver_cut 2-5 1.2.3
teq "" ver_cut 4 1.2.3
teq "" ver_cut 0 1.2.3
teq "" ver_cut 4- 1.2.3
teq 1.2.3 ver_rs 0 - 1.2.3
teq 1.2.3 ver_rs 3 . 1.2.3
teq 1.2.3 ver_rs 3- . 1.2.3
teq 1.2.3 ver_rs 3-5 . 1.2.3
txf ver_cut foo 1.2.3
txf ver_rs -3 _ a1b2c3d4e5
txf ver_rs 5-3 _ a1b2c3d4e5
# Tests from Portage's test_vercmp.py
teqr 0 ver_test 6.0 -gt 5.0
teqr 0 ver_test 5.0 -gt 5
teqr 0 ver_test 1.0-r1 -gt 1.0-r0
teqr 0 ver_test 999999999999999999 -gt 999999999999999998 # 18 digits
teqr 0 ver_test 1.0.0 -gt 1.0
teqr 0 ver_test 1.0.0 -gt 1.0b
teqr 0 ver_test 1b -gt 1
teqr 0 ver_test 1b_p1 -gt 1_p1
teqr 0 ver_test 1.1b -gt 1.1
teqr 0 ver_test 12.2.5 -gt 12.2b
teqr 0 ver_test 4.0 -lt 5.0
teqr 0 ver_test 5 -lt 5.0
teqr 0 ver_test 1.0_pre2 -lt 1.0_p2
teqr 0 ver_test 1.0_alpha2 -lt 1.0_p2
teqr 0 ver_test 1.0_alpha1 -lt 1.0_beta1
teqr 0 ver_test 1.0_beta3 -lt 1.0_rc3
teqr 0 ver_test 1.001000000000000001 -lt 1.001000000000000002
teqr 0 ver_test 1.00100000000 -lt 1.001000000000000001
teqr 0 ver_test 999999999999999998 -lt 999999999999999999
teqr 0 ver_test 1.01 -lt 1.1
teqr 0 ver_test 1.0-r0 -lt 1.0-r1
teqr 0 ver_test 1.0 -lt 1.0-r1
teqr 0 ver_test 1.0 -lt 1.0.0
teqr 0 ver_test 1.0b -lt 1.0.0
teqr 0 ver_test 1_p1 -lt 1b_p1
teqr 0 ver_test 1 -lt 1b
teqr 0 ver_test 1.1 -lt 1.1b
teqr 0 ver_test 12.2b -lt 12.2.5
teqr 0 ver_test 4.0 -eq 4.0
teqr 0 ver_test 1.0 -eq 1.0
teqr 0 ver_test 1.0-r0 -eq 1.0
teqr 0 ver_test 1.0 -eq 1.0-r0
teqr 0 ver_test 1.0-r0 -eq 1.0-r0
teqr 0 ver_test 1.0-r1 -eq 1.0-r1
teqr 1 ver_test 1 -eq 2
teqr 1 ver_test 1.0_alpha -eq 1.0_pre
teqr 1 ver_test 1.0_beta -eq 1.0_alpha
teqr 1 ver_test 1 -eq 0.0
teqr 1 ver_test 1.0-r0 -eq 1.0-r1
teqr 1 ver_test 1.0-r1 -eq 1.0-r0
teqr 1 ver_test 1.0 -eq 1.0-r1
teqr 1 ver_test 1.0-r1 -eq 1.0
teqr 1 ver_test 1.0 -eq 1.0.0
teqr 1 ver_test 1_p1 -eq 1b_p1
teqr 1 ver_test 1b -eq 1
teqr 1 ver_test 1.1b -eq 1.1
teqr 1 ver_test 12.2b -eq 12.2
# A subset of tests from Paludis
teqr 0 ver_test 1.0_alpha -gt 1_alpha
teqr 0 ver_test 1.0_alpha -gt 1
teqr 0 ver_test 1.0_alpha -lt 1.0
teqr 0 ver_test 1.2.0.0_alpha7-r4 -gt 1.2_alpha7-r4
teqr 0 ver_test 0001 -eq 1
teqr 0 ver_test 01 -eq 001
teqr 0 ver_test 0001.1 -eq 1.1
teqr 0 ver_test 01.01 -eq 1.01
teqr 0 ver_test 1.010 -eq 1.01
teqr 0 ver_test 1.00 -eq 1.0
teqr 0 ver_test 1.0100 -eq 1.010
teqr 0 ver_test 1-r00 -eq 1-r0
# Additional tests
teqr 0 ver_test 0_rc99 -lt 0
teqr 0 ver_test 011 -eq 11
teqr 0 ver_test 019 -eq 19
teqr 0 ver_test 1.2 -eq 001.2
teqr 0 ver_test 1.2 -gt 1.02
teqr 0 ver_test 1.2a -lt 1.2b
teqr 0 ver_test 1.2_pre1 -gt 1.2_pre1_beta2
teqr 0 ver_test 1.2_pre1 -lt 1.2_pre1_p2
teqr 0 ver_test 1.00 -lt 1.0.0
teqr 0 ver_test 1.010 -eq 1.01
teqr 0 ver_test 1.01 -lt 1.1
teqr 0 ver_test 1.2_pre08-r09 -eq 1.2_pre8-r9
teqr 0 ver_test 0 -lt 576460752303423488 # 2**59
teqr 0 ver_test 0 -lt 9223372036854775808 # 2**63
# Bad number or ordering of arguments
txf ver_test 1
txf ver_test 1 -lt 2 3
txf ver_test -lt 1 2
# Bad operators
txf ver_test 1 "<" 2
txf ver_test 1 lt 2
txf ver_test 1 -foo 2
# Malformed versions
txf ver_test "" -ne 1
txf ver_test 1. -ne 1
txf ver_test 1ab -ne 1
txf ver_test b -ne 1
txf ver_test 1-r1_pre -ne 1
txf ver_test 1-pre1 -ne 1
txf ver_test 1_foo -ne 1
txf ver_test 1_pre1.1 -ne 1
txf ver_test 1-r1.0 -ne 1
txf ver_test cvs.9999 -ne 9999
texit

View File

@ -0,0 +1,147 @@
#!/bin/bash
# Copyright 1999-2017 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
EAPI=6
source tests-common.sh
inherit eapi7-ver versionator
cutting() {
local x
for x in {1..1000}; do
ver_cut 1 1.2.3
ver_cut 1-2 1.2.3
ver_cut 2- 1.2.3
ver_cut 1- 1.2.3
ver_cut 3-4 1.2.3b_alpha4
ver_cut 5 1.2.3b_alpha4
ver_cut 1-2 .1.2.3
ver_cut 0-2 .1.2.3
ver_cut 2-3 1.2.3.
ver_cut 2- 1.2.3.
ver_cut 2-4 1.2.3.
done >/dev/null
}
cutting_versionator() {
local x
for x in {1..100}; do
get_version_component_range 1 1.2.3
get_version_component_range 1-2 1.2.3
get_version_component_range 2- 1.2.3
get_version_component_range 1- 1.2.3
get_version_component_range 3-4 1.2.3b_alpha4
get_version_component_range 5 1.2.3b_alpha4
get_version_component_range 1-2 .1.2.3
get_version_component_range 0-2 .1.2.3
get_version_component_range 2-3 1.2.3.
get_version_component_range 2- 1.2.3.
get_version_component_range 2-4 1.2.3.
done >/dev/null
}
replacing() {
local x
for x in {1..1000}; do
ver_rs 1 - 1.2.3
ver_rs 2 - 1.2.3
ver_rs 1-2 - 1.2.3.4
ver_rs 2- - 1.2.3.4
ver_rs 2 . 1.2-3
ver_rs 3 . 1.2.3a
ver_rs 2-3 - 1.2_alpha4
#ver_rs 3 - 2 "" 1.2.3b_alpha4
#ver_rs 3-5 _ 4-6 - a1b2c3d4e5
ver_rs 1 - .1.2.3
ver_rs 0 - .1.2.3
done >/dev/null
}
replacing_versionator() {
local x
for x in {1..100}; do
replace_version_separator 1 - 1.2.3
replace_version_separator 2 - 1.2.3
replace_version_separator 1-2 - 1.2.3.4
replace_version_separator 2- - 1.2.3.4
replace_version_separator 2 . 1.2-3
replace_version_separator 3 . 1.2.3a
replace_version_separator 2-3 - 1.2_alpha4
#replace_version_separator 3 - 2 "" 1.2.3b_alpha4
#replace_version_separator 3-5 _ 4-6 - a1b2c3d4e5
replace_version_separator 1 - .1.2.3
replace_version_separator 0 - .1.2.3
done >/dev/null
}
comparing() {
local x
for x in {1..1000}; do
ver_test 1b_p1 -le 1_p1
ver_test 1.1b -le 1.1
ver_test 12.2.5 -le 12.2b
ver_test 4.0 -le 5.0
ver_test 5 -le 5.0
ver_test 1.0_pre2 -le 1.0_p2
ver_test 1.0_alpha2 -le 1.0_p2
ver_test 1.0_alpha1 -le 1.0_beta1
ver_test 1.0_beta3 -le 1.0_rc3
ver_test 1.001000000000000001 -le 1.001000000000000002
done
}
comparing_versionator() {
local x
for x in {1..100}; do
version_is_at_least 1b_p1 1_p1
version_is_at_least 1.1b 1.1
version_is_at_least 12.2.5 12.2b
version_is_at_least 4.0 5.0
version_is_at_least 5 5.0
version_is_at_least 1.0_pre2 1.0_p2
version_is_at_least 1.0_alpha2 1.0_p2
version_is_at_least 1.0_alpha1 1.0_beta1
version_is_at_least 1.0_beta3 1.0_rc3
version_is_at_least 1.001000000000000001 1.001000000000000002
done
}
get_times() {
local factor=${1}; shift
echo "${*}"
local real=()
local user=()
for x in {1..5}; do
while read tt tv; do
case ${tt} in
real) real+=( $(dc -e "${tv} ${factor} * p") );;
user) user+=( $(dc -e "${tv} ${factor} * p") );;
esac
done < <( ( time -p "${@}" ) 2>&1 )
done
[[ ${#real[@]} == 5 ]] || die "Did not get 5 real times"
[[ ${#user[@]} == 5 ]] || die "Did not get 5 user times"
local sum
for v in real user; do
vr="${v}[*]"
sum=$(dc -e "${!vr} + + + + 3 k 5 / p")
vr="${v}[@]"
printf '%s %4.2f %4.2f %4.2f %4.2f %4.2f => %4.2f avg\n' \
"${v}" "${!vr}" "${sum}"
done
}
export LC_ALL=C
get_times 1 cutting
get_times 10 cutting_versionator
get_times 1 replacing
get_times 10 replacing_versionator
get_times 1 comparing
get_times 10 comparing_versionator

78
eclass/tests/eapi8-dosym.sh Executable file
View File

@ -0,0 +1,78 @@
#!/bin/bash
# Copyright 2020 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=7
source tests-common.sh
inherit eapi8-dosym
dosym() {
echo "$1"
}
# reference implementation using GNU realpath
ref_canonicalize() {
realpath -m -s "$1"
}
ref_dosym_r() {
local link=$(realpath -m -s "/${2#/}")
realpath -m -s --relative-to="$(dirname "${link}")" "$1"
}
randompath() {
dd if=/dev/urandom bs=128 count=1 2>/dev/null | LC_ALL=C sed \
-e 's/[^a-zA-M]//g;s/[A-E]/\/.\//g;s/[F-J]/\/..\//g;s/[K-M]/\//g' \
-e 's/^/\//;q'
}
teq() {
local expected=$1; shift
tbegin "$* -> ${expected}"
local got=$("$@")
[[ ${got} == "${expected}" ]]
tend $? "returned: ${got}"
}
for f in ref_canonicalize "_dosym8_canonicalize"; do
# canonicalize absolute paths
teq / ${f} /
teq /foo/baz/quux ${f} /foo/bar/../baz/quux
teq /foo ${f} /../../../foo
teq /bar ${f} /foo//./..///bar
teq /baz ${f} /foo/bar/../../../baz
teq /a/d/f/g ${f} /a/b/c/../../d/e/../f/g
done
# canonicalize relative paths (not actually used)
teq . _dosym8_canonicalize .
teq foo _dosym8_canonicalize foo
teq foo _dosym8_canonicalize ./foo
teq ../foo _dosym8_canonicalize ../foo
teq ../baz _dosym8_canonicalize foo/bar/../../../baz
for f in ref_dosym_r "dosym8 -r"; do
teq ../../bin/foo ${f} /bin/foo /usr/bin/foo
teq ../../../doc/foo-1 \
${f} /usr/share/doc/foo-1 /usr/share/texmf-site/doc/fonts/foo
teq ../../opt/bar/foo ${f} /opt/bar/foo /usr/bin/foo
teq ../c/d/e ${f} /a/b/c/d/e a/b/f/g
teq b/f ${f} /a/b///./c/d/../e/..//../f /a/././///g/../h
teq ../h ${f} /a/././///g/../h /a/b///./c/d/../e/..//../f
teq . ${f} /foo /foo/bar
teq .. ${f} /foo /foo/bar/baz
teq '../../fo . o/b ar' ${f} '/fo . o/b ar' '/baz / qu .. ux/qu x'
teq '../../f"o\o/b$a[]r' ${f} '/f"o\o/b$a[]r' '/ba\z/qu$u"x/qux'
done
# set RANDOMTESTS to a positive number to enable random tests
for (( i = 0; i < RANDOMTESTS; i++ )); do
targ=$(randompath)
link=$(randompath)
out=$(ref_dosym_r "${targ}" "${link}")
teq "${out}" dosym8 -r "${targ}" "${link}"
done
texit

69
eclass/tests/estack_eshopts.sh Executable file
View File

@ -0,0 +1,69 @@
#!/bin/bash
# Copyright 1999-2017 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
source tests-common.sh
inherit estack
test-it() {
local s0 s1 s2
tbegin "push/pop '$*'"
s0=$(shopt -p)
t eshopts_push $*
s1=$(shopt -p)
t eshopts_pop
s2=$(shopt -p)
[[ ${s0} == "${s2}" ]] && \
[[ ${s1} == *"shopt $*"* ]]
tend $?
}
# should handle bug #395025
for arg in nullglob dotglob extglob ; do
for flag in s u ; do
test-it -${flag} ${arg}
done
done
# test 'set' options
set -f
tbegin "set +f"
s0=$-
t eshopts_push +f
s1=$-
t eshopts_pop
s2=$-
[[ ${s0} == "${s2}" ]] &&
[[ ${s1} != *f* ]]
tend $?
set +f
tbegin "set -f"
s0=$-
t eshopts_push -f
s1=$-
t eshopts_pop
s2=$-
[[ ${s0} == "${s2}" ]] &&
[[ ${s1} == *f* ]]
tend $?
tbegin "multi push/pop"
s0=$(shopt -p)
t eshopts_push -s dotglob
t eshopts_push -u dotglob
t eshopts_push -s extglob
t eshopts_push -u dotglob
t eshopts_push -s dotglob
t eshopts_pop
t eshopts_pop
t eshopts_pop
t eshopts_pop
t eshopts_pop
s1=$(shopt -p)
[[ ${s0} == "${s1}" ]]
tend $?
texit

52
eclass/tests/estack_estack.sh Executable file
View File

@ -0,0 +1,52 @@
#!/bin/bash
# Copyright 1999-2017 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
source tests-common.sh
inherit estack
tbegin "initial stack state"
estack_pop teststack
# Should be empty and thus return 1
[[ $? -eq 1 ]]
tend $?
tbegin "simple push/pop"
estack_push ttt 1
pu=$?
estack_pop ttt
po=$?
[[ ${pu}${po} == "00" ]]
tend $?
tbegin "simple push/pop var"
estack_push xxx "boo ga boo"
pu=$?
estack_pop xxx i
po=$?
[[ ${pu}${po} == "00" ]] && [[ ${i} == "boo ga boo" ]]
tend $?
tbegin "multi push/pop"
estack_push yyy {1..10}
pu=$?
i=0
while estack_pop yyy ; do
: $(( i++ ))
done
[[ ${pu} -eq 0 && ${i} -eq 10 ]]
tend $?
tbegin "umask push/pop"
u0=$(umask)
eumask_push 0000
pu=$?
u1=$(umask)
eumask_pop
po=$?
u2=$(umask)
[[ ${pu}${po}:${u0}:${u1}:${u2} == "00:${u0}:0000:${u0}" ]]
tend $?
texit

99
eclass/tests/estack_evar.sh Executable file
View File

@ -0,0 +1,99 @@
#!/bin/bash
# Copyright 1999-2017 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
source tests-common.sh
inherit estack
tbegin "simple push/pop"
VAR=1
evar_push VAR
pu=$?
VAR=2
evar_pop
po=$?
[[ ${pu}${po}${VAR} == "001" ]]
tend $?
tbegin "unset push/pop"
unset VAR
evar_push VAR
pu=$?
VAR=2
evar_pop
po=$?
[[ ${pu}${po}${VAR+set} == "00" ]]
tend $?
tbegin "empty push/pop"
VAR=
evar_push VAR
pu=$?
VAR=2
evar_pop
po=$?
[[ ${pu}${po}${VAR+set}${VAR} == "00set" ]]
tend $?
tbegin "export push/pop"
export VAR=exported
evar_push VAR
pu=$?
VAR=2
evar_pop
po=$?
var=$(bash -c 'echo ${VAR}')
[[ ${pu}${po}${var} == "00exported" ]]
tend $?
tbegin "unexport push/pop"
unset VAR
VAR=not-exported
evar_push VAR
pu=$?
VAR=2
evar_pop
po=$?
var=$(bash -c 'echo ${VAR+set}')
[[ ${pu}${po}${VAR}${var} == "00not-exported" ]]
tend $?
tbegin "multi push/pop"
A=a B=b C=c
evar_push A B C
pu=$?
A=A B=B C=C
evar_pop 1
po1=$?
[[ ${A}${B}${C} == "ABc" ]]
po2=$?
evar_pop 2
po3=$?
var=$(bash -c 'echo ${VAR+set}')
[[ ${pu}${po1}${po2}${po3}${A}${B}${C} == "0000abc" ]]
tend $?
tbegin "simple push_set/pop"
VAR=1
evar_push_set VAR 2
pu=$?
[[ ${VAR} == "2" ]]
po1=$?
evar_pop
po2=$?
[[ ${pu}${po1}${po2}${VAR} == "0001" ]]
tend $?
tbegin "unset push_set/pop"
VAR=1
evar_push_set VAR
pu=$?
[[ ${VAR+set} != "set" ]]
po1=$?
evar_pop
po2=$?
[[ ${pu}${po1}${po2}${VAR} == "0001" ]]
tend $?
texit

175
eclass/tests/flag-o-matic.sh Executable file
View File

@ -0,0 +1,175 @@
#!/bin/bash
# Copyright 1999-2019 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
source tests-common.sh
inherit flag-o-matic
CFLAGS="-a -b -c=1 --param l1-cache-size=32"
CXXFLAGS="-x -y -z=2"
LDFLAGS="-l -m -n=3 -Wl,--remove-me"
ftend() {
local ret=$?
local msg="Failed; flags are:"
local flag
for flag in $(all-flag-vars) ; do
msg+=$'\n\t'"${flag}=${!flag}"
done
tend ${ret} "${msg}"
}
tbegin "is-flag"
! (is-flag 1 2 3) 2>/dev/null
ftend
tbegin "is-ldflag"
! (is-ldflag 1 2 3) 2>/dev/null
ftend
while read exp flag ; do
[[ -z ${exp}${flag} ]] && continue
tbegin "is-flagq ${flag}"
is-flagq ${flag}
[[ ${exp} -eq $? ]]
ftend
done <<<"
1 -L
0 -a
0 -x
"
while read exp flag ; do
[[ -z ${exp}${flag} ]] && continue
tbegin "is-ldflagq ${flag}"
is-ldflagq "${flag}"
[[ ${exp} -eq $? ]]
ftend
done <<<"
1 -a
0 -n=*
1 -n
"
tbegin "strip-unsupported-flags for -z=2"
strip-unsupported-flags
[[ ${CFLAGS} == "--param l1-cache-size=32" ]] && [[ ${CXXFLAGS} == "-z=2" ]] && [[ ${LDFLAGS} == "" ]]
ftend
CFLAGS="-O2 -B/foo -O1"
CXXFLAGS="-O2 -B/foo -O1"
LDFLAGS="-O2 -B/foo -O1"
tbegin "strip-unsupported-flags for '-B/foo'"
strip-unsupported-flags
[[ ${CFLAGS} == "-O2 -B/foo -O1" ]] && [[ ${CXXFLAGS} == "-O2 -B/foo -O1" ]] && [[ ${LDFLAGS} == "-O2 -B/foo -O1" ]]
ftend
CFLAGS="-O2 -B /foo -O1"
CXXFLAGS="-O2 -B /foo -O1"
LDFLAGS="-O2 -B /foo -O1"
tbegin "strip-unsupported-flags for '-B /foo'"
strip-unsupported-flags
[[ ${CFLAGS} == "-O2 -B /foo -O1" ]] && [[ ${CXXFLAGS} == "-O2 -B /foo -O1" ]] && [[ ${LDFLAGS} == "-O2 -B /foo -O1" ]]
ftend
for var in $(all-flag-vars) ; do
eval ${var}=\"-filter -filter-glob -foo-${var%FLAGS}\"
done
tbegin "filter-flags basic"
filter-flags -filter
(
for var in $(all-flag-vars) ; do
val=${!var}
[[ ${val} == "-filter-glob -foo-${var%FLAGS}" ]] || exit 1
done
)
ftend
tbegin "filter-flags glob"
filter-flags '-filter-*'
(
for var in $(all-flag-vars) ; do
val=${!var}
[[ ${val} == "-foo-${var%FLAGS}" ]] || exit 1
done
)
ftend
tbegin "strip-flags basic"
CXXFLAGS+=" -O999 "
strip-flags
[[ -z ${CFLAGS}${LDFLAGS}${CPPFLAGS} && ${CXXFLAGS} == "-O2" ]]
ftend
tbegin "replace-flags basic"
CFLAGS="-O0 -foo"
replace-flags -O0 -O1
[[ ${CFLAGS} == "-O1 -foo" ]]
ftend
tbegin "replace-flags glob"
CXXFLAGS="-O0 -mcpu=bad -cow"
replace-flags '-mcpu=*' -mcpu=good
[[ ${CXXFLAGS} == "-O0 -mcpu=good -cow" ]]
ftend
tbegin "append-cflags basic"
CFLAGS=
append-cflags -O0
[[ ${CFLAGS} == " -O0" ]]
ftend
tbegin "append-cflags -DFOO='a b c'"
CFLAGS=
append-cflags '-DFOO="a b c"'
[[ ${CFLAGS} == ' -DFOO="a b c"' ]]
ftend
tbegin "raw-ldflags"
LDFLAGS='-Wl,-O1 -Wl,--as-needed -Wl,-z,now -flto'
LDFLAGS=$(raw-ldflags)
[[ ${LDFLAGS} == '-O1 --as-needed -z now' ]]
ftend
tbegin "test-flags-CC (valid flags)"
out=$(test-flags-CC -O3)
[[ $? -eq 0 && ${out} == "-O3" ]]
ftend
tbegin "test-flags-CC (valid flags, absolute path)"
absolute_CC=$(type -P $(tc-getCC))
out=$(CC=${absolute_CC} test-flags-CC -O3)
[[ $? -eq 0 && ${out} == "-O3" ]]
ftend
tbegin "test-flags-CC (invalid flags)"
out=$(test-flags-CC -finvalid-flag)
[[ $? -ne 0 && -z ${out} ]]
ftend
if type -P clang >/dev/null ; then
tbegin "test-flags-CC (valid flags w/clang)"
out=$(CC=clang test-flags-CC -O3)
[[ $? -eq 0 && ${out} == "-O3" ]]
ftend
tbegin "test-flags-CC (invalid flags w/clang)"
out=$(CC=clang test-flags-CC -finvalid-flag)
[[ $? -ne 0 && -z ${out} ]]
ftend
tbegin "test-flags-CC (gcc-valid but clang-invalid flags)"
out=$(CC=clang test-flags-CC -finline-limit=1200)
[[ $? -ne 0 && -z ${out} ]]
ftend
tbegin "test-flags-CC (unused flags w/clang)"
out=$(CC=clang test-flags-CC -Wl,-O1)
[[ $? -eq 0 && ${out} == "-Wl,-O1" ]]
ftend
fi
texit

208
eclass/tests/git-r3.sh Executable file
View File

@ -0,0 +1,208 @@
#!/bin/bash
# Copyright 1999-2019 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
# git no longer allows ext: protocol, meh
exit 0
EAPI=7
source tests-common.sh
inherit git-r3
testdir=${pkg_root}/git
mkdir "${testdir}" || die "unable to mkdir testdir"
cd "${testdir}" || die "unable to cd to testdir"
EGIT3_STORE_DIR=store
mkdir "${EGIT3_STORE_DIR}" || die "unable to mkdir store"
test_file() {
local fn=${1}
local expect=${2}
if [[ ! -f ${fn} ]]; then
eerror "${fn} does not exist (not checked out?)"
else
local got=$(<"${fn}")
if [[ ${got} != ${expect} ]]; then
eerror "${fn}, expected: ${expect}, got: ${got}"
else
return 0
fi
fi
return 1
}
test_no_file() {
local fn=${1}
if [[ -f ${fn} ]]; then
eerror "${fn} exists (wtf?!)"
else
return 0
fi
return 1
}
test_repo_clean() {
local P=${P}_${FUNCNAME#test_}
(
mkdir repo
cd repo
git init -q
echo test > file
git add file
git commit -m 1 -q
echo other-text > file2
git add file2
git commit -m 2 -q
) || die "unable to prepare repo"
# we need to use an array to preserve whitespace
local EGIT_REPO_URI=(
"ext::git daemon --export-all --base-path=. --inetd %G/repo"
)
tbegin "fetching from a simple repo"
(
git-r3_src_unpack
test_file "${WORKDIR}/${P}/file" test && \
test_file "${WORKDIR}/${P}/file2" other-text
) &>fetch.log
eend ${?} || cat fetch.log
}
test_repo_revert() {
local P=${P}_${FUNCNAME#test_}
(
cd repo
git revert -n HEAD^
git commit -m r1 -q
) || die "unable to prepare repo"
# we need to use an array to preserve whitespace
local EGIT_REPO_URI=(
"ext::git daemon --export-all --base-path=. --inetd %G/repo"
)
tbegin "fetching revert"
(
git-r3_src_unpack
test_no_file "${WORKDIR}/${P}/file" && \
test_file "${WORKDIR}/${P}/file2" other-text
) &>fetch.log
eend ${?} || cat fetch.log
}
test_repo_branch() {
local P=${P}_${FUNCNAME#test_}
(
cd repo
git branch -q other-branch HEAD^
git checkout -q other-branch
echo one-more > file3
git add file3
git commit -m 3 -q
git checkout -q master
) || die "unable to prepare repo"
# we need to use an array to preserve whitespace
local EGIT_REPO_URI=(
"ext::git daemon --export-all --base-path=. --inetd %G/repo"
)
local EGIT_BRANCH=other-branch
tbegin "switching branches"
(
git-r3_src_unpack
test_file "${WORKDIR}/${P}/file" test && \
test_file "${WORKDIR}/${P}/file2" other-text && \
test_file "${WORKDIR}/${P}/file3" one-more
) &>fetch.log
eend ${?} || cat fetch.log
}
test_repo_merge() {
local P=${P}_${FUNCNAME#test_}
(
cd repo
git branch -q one-more-branch HEAD^
git checkout -q one-more-branch
echo foobarbaz > file3
git add file3
git commit -m 3b -q
git checkout -q master
git merge -m 4 -q one-more-branch
) || die "unable to prepare repo"
# we need to use an array to preserve whitespace
local EGIT_REPO_URI=(
"ext::git daemon --export-all --base-path=. --inetd %G/repo"
)
tbegin "fetching a merge commit"
(
git-r3_src_unpack
test_no_file "${WORKDIR}/${P}/file" && \
test_file "${WORKDIR}/${P}/file2" other-text && \
test_file "${WORKDIR}/${P}/file3" foobarbaz
) &>fetch.log
eend ${?} || cat fetch.log
}
test_repo_revert_merge() {
local P=${P}_${FUNCNAME#test_}
(
cd repo
git branch -q to-be-reverted
git checkout -q to-be-reverted
echo trrm > file3
git add file3
git commit -m 5b -q
git checkout -q master
echo trrm > file2
git add file2
git commit -m 5 -q
git merge -m 6 -q to-be-reverted
echo trrm > file
git add file
git commit -m 7 -q
git revert -m 1 -n HEAD^
git commit -m 7r -q
) || die "unable to prepare repo"
# we need to use an array to preserve whitespace
local EGIT_REPO_URI=(
"ext::git daemon --export-all --base-path=. --inetd %G/repo"
)
tbegin "fetching a revert of a merge commit"
(
git-r3_src_unpack
test_file "${WORKDIR}/${P}/file" trrm && \
test_file "${WORKDIR}/${P}/file2" trrm && \
test_file "${WORKDIR}/${P}/file3" foobarbaz
) &>fetch.log
eend ${?} || cat fetch.log
}
test_repo_clean
test_repo_revert
test_repo_branch
test_repo_merge
test_repo_revert_merge
texit

64
eclass/tests/git-r3_GIT_DIR.sh Executable file
View File

@ -0,0 +1,64 @@
#!/bin/bash
# Copyright 1999-2019 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=7
source tests-common.sh
inherit git-r3
testdir=${pkg_root}/git
mkdir "${testdir}" || die "unable to mkdir testdir"
cd "${testdir}" || die "unable to cd to testdir"
EGIT3_STORE_DIR=store
mkdir "${EGIT3_STORE_DIR}" || die "unable to mkdir store"
git() { :; }
# Test cleaning up canonical repo URI
test_repouri() {
local uri=${1}
local expect=${2}
local -x GIT_DIR
tbegin "GIT_DIR for ${uri}"
_git-r3_set_gitdir "${uri}" &>/dev/null
local got=${GIT_DIR#${EGIT3_STORE_DIR}/}
[[ ${expect} == ${got} ]]
tend ${?} || eerror "Expected: ${expect}, got: ${got}"
}
test_repouri git://git.overlays.gentoo.org/proj/portage.git proj_portage.git
test_repouri https://git.overlays.gentoo.org/gitroot/proj/portage.git proj_portage.git
test_repouri git+ssh://git@git.overlays.gentoo.org/proj/portage.git proj_portage.git
test_repouri git://anongit.freedesktop.org/mesa/mesa mesa_mesa.git
test_repouri ssh://git.freedesktop.org/git/mesa/mesa mesa_mesa.git
test_repouri http://anongit.freedesktop.org/git/mesa/mesa.git mesa_mesa.git
test_repouri http://cgit.freedesktop.org/mesa/mesa/ mesa_mesa.git
test_repouri https://code.google.com/p/snakeoil/ snakeoil.git
test_repouri git://git.code.sf.net/p/xournal/code xournal_code.git
test_repouri http://git.code.sf.net/p/xournal/code xournal_code.git
test_repouri git://git.gnome.org/glibmm glibmm.git
test_repouri https://git.gnome.org/browse/glibmm glibmm.git
test_repouri ssh://USERNAME@git.gnome.org/git/glibmm glibmm.git
test_repouri git://git.kernel.org/pub/scm/git/git.git git_git.git
test_repouri http://git.kernel.org/pub/scm/git/git.git git_git.git
test_repouri https://git.kernel.org/pub/scm/git/git.git git_git.git
test_repouri https://git.kernel.org/cgit/git/git.git/ git_git.git
#test_repouri git@github.com:gentoo/identity.gentoo.org.git gentoo_identity.gentoo.org.git
test_repouri https://github.com/gentoo/identity.gentoo.org.git gentoo_identity.gentoo.org.git
#test_repouri git@bitbucket.org:mgorny/python-exec.git mgorny_python-exec.git
test_repouri https://mgorny@bitbucket.org/mgorny/python-exec.git mgorny_python-exec.git
texit

39
eclass/tests/git-r3_subrepos.sh Executable file
View File

@ -0,0 +1,39 @@
#!/bin/bash
# Copyright 1999-2019 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=7
source tests-common.sh
inherit git-r3
# Test getting submodule URIs
test_subrepos() {
local suburi=${1}
local expect=( "${@:2}" )
tbegin "subrepos for ${suburi} -> ${expect[0]}${expect[1]+...}"
local subrepos
_git-r3_set_subrepos "${suburi}" "${repos[@]}"
[[ ${expect[@]} == ${subrepos[@]} ]]
tend ${?} || eerror "Expected: ${expect[@]}, got: ${subrepos[@]}"
}
# parent repos
repos=( http://foohub/fooman/foo.git git://foohub/fooman/foo.git )
# absolute URI
test_subrepos http://foo/bar http://foo/bar
test_subrepos /foo/bar /foo/bar
# plain relative URI
test_subrepos ./baz http://foohub/fooman/foo.git/baz git://foohub/fooman/foo.git/baz
# backward relative URIs
test_subrepos ../baz.git http://foohub/fooman/baz.git git://foohub/fooman/baz.git
test_subrepos ../../bazman/baz.git http://foohub/bazman/baz.git git://foohub/bazman/baz.git
texit

View File

@ -0,0 +1,38 @@
#!/bin/bash
# Copyright 1999-2015 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
source tests-common.sh
inherit linux-info
test_get_running_version() {
local test_kv=$1 major=$2 minor=$3 patch=$4 extra=$5
tbegin "get_running_version ${test_kv}"
uname() { echo "${test_kv}" ; }
ROOT=/:/:/:/: get_running_version
local r=$?
[[ ${r} -eq 0 &&
${major} == "${KV_MAJOR}" &&
${minor} == "${KV_MINOR}" &&
${patch} == "${KV_PATCH}" &&
${extra} == "${KV_EXTRA}" ]]
tend $? "FAIL: {ret: ${r}==0} {major: ${major}==${KV_MAJOR}} {minor: ${minor}==${KV_MINOR}} {patch: ${patch}==${KV_PATCH}} {extra: ${extra}==${KV_EXTRA}}"
}
tests=(
# KV_FULL MAJOR MINOR PATCH EXTRA
1.2.3 1 2 3 ''
1.2.3.4 1 2 3 .4
1.2.3-ver+1.4 1 2 3 -ver+1.4
1.2-kern.3 1 2 0 -kern.3
1.2+kern.5 1 2 0 +kern.5
1.2.3_blah 1 2 3 _blah
3.2.1-zen-vs2.3.2.5+ 3 2 1 -zen-vs2.3.2.5+
)
for (( i = 0; i < ${#tests[@]}; i += 5 )) ; do
test_get_running_version "${tests[@]:i:5}"
done
texit

138
eclass/tests/llvm.sh Executable file
View File

@ -0,0 +1,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

65
eclass/tests/multilib.sh Executable file
View File

@ -0,0 +1,65 @@
#!/bin/bash
# Copyright 2020 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
source tests-common.sh
inherit multilib
# Run 'multilib_env' and check what variables it expands to
test-multilib_env() {
local target=$1 exp_abi=$2 exp_vars=" $3"
tbegin "expand-target $1"
# Reset default
unset MULTILIB_ABIS
unset DEFAULT_ABI
CFLAGS_default=
LDFLAGS_default=
LIBDIR_default=lib
CHOST_default=${target}
CTARGET_default=${CHOST_default}
LIBDIR_default=lib
multilib_env ${target}
local actual_abi="${DEFAULT_ABI}:${MULTILIB_ABIS}"
local actual_vars=""
local abi var v
for abi in ${MULTILIB_ABIS}; do
actual_vars+=" ${abi}? ("
for var in CHOST LIBDIR CFLAGS LDFLAGS; do
v=${var}_${abi}
actual_vars+=" ${var}=${!v}"
done
actual_vars+=" )"
done
[[ "${exp_abi}" == "${actual_abi}" && "${exp_vars}" == "${actual_vars}" ]]
if ! tend $? ; then
printf '### EXPECTED ABI: %s\n' "${exp_abi}"
printf '### ACTUAL ABI: %s\n' "${actual_abi}"
printf '### EXPECTED VARS: %s\n' "${exp_vars}"
printf '### ACTUAL VARS: %s\n' "${actual_vars}"
fi
}
# Pick a few interesting targets from:
# $ grep -h -o -R 'CHOST=.*' ../../profiles/ | sort -u
test-multilib_env \
"x86_64-pc-linux-gnu" \
"amd64:amd64 x86" \
"amd64? ( CHOST=x86_64-pc-linux-gnu LIBDIR=lib64 CFLAGS=-m64 LDFLAGS= ) x86? ( CHOST=i686-pc-linux-gnu LIBDIR=lib CFLAGS=-m32 LDFLAGS= )"
test-multilib_env \
"x86_64-pc-linux-gnux32" \
"x32:x32 amd64 x86" \
"x32? ( CHOST=x86_64-pc-linux-gnux32 LIBDIR=libx32 CFLAGS=-mx32 LDFLAGS= ) amd64? ( CHOST=x86_64-pc-linux-gnu LIBDIR=lib64 CFLAGS=-m64 LDFLAGS= ) x86? ( CHOST=i686-pc-linux-gnu LIBDIR=lib CFLAGS=-m32 LDFLAGS= )"
test-multilib_env \
"x86_64-gentoo-linux-musl" \
"default:default" \
"default? ( CHOST=x86_64-gentoo-linux-musl LIBDIR=lib CFLAGS= LDFLAGS= )"
texit

View File

@ -0,0 +1,50 @@
#!/bin/bash
# Copyright 1999-2015 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
source tests-common.sh
inherit multiprocessing
test-makeopts_jobs() {
local exp=$1; shift
tbegin "makeopts_jobs($1${2+; inf=${2}}) == ${exp}"
local indirect=$(MAKEOPTS="$*" makeopts_jobs)
local direct=$(makeopts_jobs "$@")
if [[ "${direct}" != "${indirect}" ]] ; then
tend 1 "Mismatch between MAKEOPTS/cli: '${indirect}' != '${direct}'"
else
[[ ${direct} == "${exp}" ]]
tend $? "Got back: ${act}"
fi
}
tests=(
999 "-j"
999 "--jobs"
999 "-j -l9"
1 ""
1 "-l9 -w"
1 "-l9 -w-j4"
1 "-l9--jobs=3"
1 "-l9--jobs=8"
2 "-j2"
3 "-j 3"
4 "-l3 -j 4 -w"
5 "--jobs=5"
6 "--jobs 6"
7 "-l3 --jobs 7 -w"
4 "-j1 -j 2 --jobs 3 --jobs=4"
8 " -j 8 "
999 "-kj"
4 "-kj4"
5 "-kj 5"
)
for (( i = 0; i < ${#tests[@]}; i += 2 )) ; do
test-makeopts_jobs "${tests[i]}" "${tests[i+1]}"
done
# test custom inf value
test-makeopts_jobs 645 "-j" 645
texit

View File

@ -0,0 +1,48 @@
#!/bin/bash
# Copyright 1999-2015 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
source tests-common.sh
inherit multiprocessing
test-makeopts_loadavg() {
local exp=$1; shift
tbegin "makeopts_loadavg($1${2+; inf=${2}}) == ${exp}"
local indirect=$(MAKEOPTS="$*" makeopts_loadavg)
local direct=$(makeopts_loadavg "$@")
if [[ "${direct}" != "${indirect}" ]] ; then
tend 1 "Mismatch between MAKEOPTS/cli: '${indirect}' != '${direct}'"
else
[[ ${direct} == "${exp}" ]]
tend $? "Got back: ${direct}"
fi
}
tests=(
999 "-j"
999 "-l"
999 ""
9 "-l9 -w"
9 "-l 9 -w-j4"
3 "-l3 -j 4 -w"
5 "--load-average=5"
6 "--load-average 6"
7 "-l3 --load-average 7 -w"
4 "-j1 -j 2 --load-average 3 --load-average=4"
3 " --max-load=3 -x"
8 " -l 8 "
999 "-kl"
4 "-kl4"
5 "-kl 5"
2.3 "-l 2.3"
999 "-l 2.3.4"
)
for (( i = 0; i < ${#tests[@]}; i += 2 )) ; do
test-makeopts_loadavg "${tests[i]}" "${tests[i+1]}"
done
# test custom inf value
test-makeopts_loadavg 645 "-l" 645
texit

216
eclass/tests/python-utils-r1.sh Executable file
View File

@ -0,0 +1,216 @@
#!/bin/bash
# Copyright 1999-2020 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=7
source tests-common.sh
test_var() {
local var=${1}
local impl=${2}
local expect=${3}
tbegin "${var} for ${impl}"
local ${var}
_python_export ${impl} PYTHON ${var}
[[ ${!var} == ${expect} ]] || eerror "(${impl}: ${var}: ${!var} != ${expect}"
tend ${?}
}
test_is() {
local func=${1}
local expect=${2}
tbegin "${func} (expecting: ${expect})"
${func}
[[ ${?} == ${expect} ]]
tend ${?}
}
test_fix_shebang() {
local from=${1}
local to=${2}
local expect=${3}
local args=( "${@:4}" )
tbegin "python_fix_shebang${args[@]+ ${args[*]}} from ${from} to ${to} (exp: ${expect})"
echo "${from}" > "${tmpfile}"
output=$( EPYTHON=${to} python_fix_shebang "${args[@]}" -q "${tmpfile}" 2>&1 )
if [[ ${?} != 0 ]]; then
if [[ ${expect} != FAIL ]]; then
echo "${output}"
tend 1
else
tend 0
fi
else
[[ $(<"${tmpfile}") == ${expect} ]] \
|| eerror "${from} -> ${to}: $(<"${tmpfile}") != ${expect}"
tend ${?}
fi
}
tmpfile=$(mktemp)
inherit python-utils-r1
test_var EPYTHON python2_7 python2.7
test_var PYTHON python2_7 /usr/bin/python2.7
if [[ -x /usr/bin/python2.7 ]]; then
test_var PYTHON_SITEDIR python2_7 "/usr/lib*/python2.7/site-packages"
test_var PYTHON_INCLUDEDIR python2_7 /usr/include/python2.7
test_var PYTHON_LIBPATH python2_7 "/usr/lib*/libpython2.7$(get_libname)"
test_var PYTHON_CONFIG python2_7 /usr/bin/python2.7-config
test_var PYTHON_CFLAGS python2_7 "*-I/usr/include/python2.7*"
test_var PYTHON_LIBS python2_7 "*-lpython2.7*"
fi
test_var PYTHON_PKG_DEP python2_7 '*dev-lang/python*:2.7'
test_var PYTHON_SCRIPTDIR python2_7 /usr/lib/python-exec/python2.7
test_var EPYTHON python3_6 python3.6
test_var PYTHON python3_6 /usr/bin/python3.6
if [[ -x /usr/bin/python3.6 ]]; then
abiflags=$(/usr/bin/python3.6 -c 'import sysconfig; print(sysconfig.get_config_var("ABIFLAGS"))')
test_var PYTHON_SITEDIR python3_6 "/usr/lib*/python3.6/site-packages"
test_var PYTHON_INCLUDEDIR python3_6 "/usr/include/python3.6${abiflags}"
test_var PYTHON_LIBPATH python3_6 "/usr/lib*/libpython3.6${abiflags}$(get_libname)"
test_var PYTHON_CONFIG python3_6 "/usr/bin/python3.6${abiflags}-config"
test_var PYTHON_CFLAGS python3_6 "*-I/usr/include/python3.6*"
test_var PYTHON_LIBS python3_6 "*-lpython3.6*"
fi
test_var PYTHON_PKG_DEP python3_6 '*dev-lang/python*:3.6'
test_var PYTHON_SCRIPTDIR python3_6 /usr/lib/python-exec/python3.6
test_var EPYTHON python3_7 python3.7
test_var PYTHON python3_7 /usr/bin/python3.7
if [[ -x /usr/bin/python3.7 ]]; then
abiflags=$(/usr/bin/python3.7 -c 'import sysconfig; print(sysconfig.get_config_var("ABIFLAGS"))')
test_var PYTHON_SITEDIR python3_7 "/usr/lib/python3.7/site-packages"
test_var PYTHON_INCLUDEDIR python3_7 "/usr/include/python3.7${abiflags}"
test_var PYTHON_LIBPATH python3_7 "/usr/lib*/libpython3.7${abiflags}$(get_libname)"
test_var PYTHON_CONFIG python3_7 "/usr/bin/python3.7${abiflags}-config"
test_var PYTHON_CFLAGS python3_7 "*-I/usr/include/python3.7*"
test_var PYTHON_LIBS python3_7 "*-lpython3.7*"
fi
test_var PYTHON_PKG_DEP python3_7 '*dev-lang/python*:3.7'
test_var PYTHON_SCRIPTDIR python3_7 /usr/lib/python-exec/python3.7
test_var EPYTHON python3_8 python3.8
test_var PYTHON python3_8 /usr/bin/python3.8
if [[ -x /usr/bin/python3.8 ]]; then
abiflags=$(/usr/bin/python3.8 -c 'import sysconfig; print(sysconfig.get_config_var("ABIFLAGS"))')
test_var PYTHON_SITEDIR python3_8 "/usr/lib/python3.8/site-packages"
test_var PYTHON_INCLUDEDIR python3_8 "/usr/include/python3.8${abiflags}"
test_var PYTHON_LIBPATH python3_8 "/usr/lib*/libpython3.8${abiflags}$(get_libname)"
test_var PYTHON_CONFIG python3_8 "/usr/bin/python3.8${abiflags}-config"
test_var PYTHON_CFLAGS python3_8 "*-I/usr/include/python3.8*"
test_var PYTHON_LIBS python3_8 "*-lpython3.8*"
fi
test_var PYTHON_PKG_DEP python3_8 '*dev-lang/python*:3.8'
test_var PYTHON_SCRIPTDIR python3_8 /usr/lib/python-exec/python3.8
test_var EPYTHON python3_9 python3.9
test_var PYTHON python3_9 /usr/bin/python3.9
if [[ -x /usr/bin/python3.9 ]]; then
abiflags=$(/usr/bin/python3.9 -c 'import sysconfig; print(sysconfig.get_config_var("ABIFLAGS"))')
test_var PYTHON_SITEDIR python3_9 "/usr/lib/python3.9/site-packages"
test_var PYTHON_INCLUDEDIR python3_9 "/usr/include/python3.9${abiflags}"
test_var PYTHON_LIBPATH python3_9 "/usr/lib*/libpython3.9${abiflags}$(get_libname)"
test_var PYTHON_CONFIG python3_9 "/usr/bin/python3.9${abiflags}-config"
test_var PYTHON_CFLAGS python3_9 "*-I/usr/include/python3.9*"
test_var PYTHON_LIBS python3_9 "*-lpython3.9*"
fi
test_var PYTHON_PKG_DEP python3_9 '*dev-lang/python*:3.9'
test_var PYTHON_SCRIPTDIR python3_9 /usr/lib/python-exec/python3.9
test_var EPYTHON pypy3 pypy3
test_var PYTHON pypy3 /usr/bin/pypy3
if [[ -x /usr/bin/pypy3 ]]; then
test_var PYTHON_SITEDIR pypy3 "/usr/lib*/pypy3.?/site-packages"
test_var PYTHON_INCLUDEDIR pypy3 "/usr/lib*/pypy3.?/include"
fi
test_var PYTHON_PKG_DEP pypy3 '*dev-python/pypy3*:0='
test_var PYTHON_SCRIPTDIR pypy3 /usr/lib/python-exec/pypy3
test_is "python_is_python3 python2.7" 1
test_is "python_is_python3 python3.2" 0
test_is "python_is_python3 pypy" 1
test_is "python_is_python3 pypy3" 0
# generic shebangs
test_fix_shebang '#!/usr/bin/python' python2.7 '#!/usr/bin/python2.7'
test_fix_shebang '#!/usr/bin/python' python3.6 '#!/usr/bin/python3.6'
test_fix_shebang '#!/usr/bin/python' pypy3 '#!/usr/bin/pypy3'
# python2/python3 matching
test_fix_shebang '#!/usr/bin/python2' python2.7 '#!/usr/bin/python2.7'
test_fix_shebang '#!/usr/bin/python3' python2.7 FAIL
test_fix_shebang '#!/usr/bin/python3' python2.7 '#!/usr/bin/python2.7' --force
test_fix_shebang '#!/usr/bin/python3' python3.6 '#!/usr/bin/python3.6'
test_fix_shebang '#!/usr/bin/python2' python3.6 FAIL
test_fix_shebang '#!/usr/bin/python2' python3.6 '#!/usr/bin/python3.6' --force
# pythonX.Y matching (those mostly test the patterns)
test_fix_shebang '#!/usr/bin/python2.7' python2.7 '#!/usr/bin/python2.7'
test_fix_shebang '#!/usr/bin/python2.7' python3.2 FAIL
test_fix_shebang '#!/usr/bin/python2.7' python3.2 '#!/usr/bin/python3.2' --force
test_fix_shebang '#!/usr/bin/python3.2' python3.2 '#!/usr/bin/python3.2'
test_fix_shebang '#!/usr/bin/python3.2' python2.7 FAIL
test_fix_shebang '#!/usr/bin/python3.2' python2.7 '#!/usr/bin/python2.7' --force
test_fix_shebang '#!/usr/bin/pypy' python2.7 FAIL
test_fix_shebang '#!/usr/bin/pypy' python2.7 '#!/usr/bin/python2.7' --force
# fancy path handling
test_fix_shebang '#!/mnt/python2/usr/bin/python' python3.6 \
'#!/mnt/python2/usr/bin/python3.6'
test_fix_shebang '#!/mnt/python2/usr/bin/python2' python2.7 \
'#!/mnt/python2/usr/bin/python2.7'
test_fix_shebang '#!/mnt/python2/usr/bin/env python' python2.7 \
'#!/mnt/python2/usr/bin/env python2.7'
test_fix_shebang '#!/mnt/python2/usr/bin/python2 python2' python2.7 \
'#!/mnt/python2/usr/bin/python2.7 python2'
test_fix_shebang '#!/mnt/python2/usr/bin/python3 python2' python2.7 FAIL
test_fix_shebang '#!/mnt/python2/usr/bin/python3 python2' python2.7 \
'#!/mnt/python2/usr/bin/python2.7 python2' --force
test_fix_shebang '#!/usr/bin/foo' python2.7 FAIL
# regression test for bug #522080
test_fix_shebang '#!/usr/bin/python ' python2.7 '#!/usr/bin/python2.7 '
# check _python_impl_matches behavior
test_is "_python_impl_matches python2_7 -2" 0
test_is "_python_impl_matches python3_6 -2" 1
test_is "_python_impl_matches python3_7 -2" 1
test_is "_python_impl_matches pypy3 -2" 1
test_is "_python_impl_matches python2_7 -3" 1
test_is "_python_impl_matches python3_6 -3" 0
test_is "_python_impl_matches python3_7 -3" 0
test_is "_python_impl_matches pypy3 -3" 0
test_is "_python_impl_matches python2_7 -2 python3_6" 0
test_is "_python_impl_matches python3_6 -2 python3_6" 0
test_is "_python_impl_matches python3_7 -2 python3_6" 1
test_is "_python_impl_matches pypy3 -2 python3_6" 1
test_is "_python_impl_matches python2_7 pypy3 -2 python3_6" 0
test_is "_python_impl_matches python3_6 pypy3 -2 python3_6" 0
test_is "_python_impl_matches python3_7 pypy3 -2 python3_6" 1
test_is "_python_impl_matches pypy3 pypy3 -2 python3_6" 0
set -f
test_is "_python_impl_matches python2_7 pypy*" 1
test_is "_python_impl_matches python3_6 pypy*" 1
test_is "_python_impl_matches python3_7 pypy*" 1
test_is "_python_impl_matches pypy3 pypy*" 0
test_is "_python_impl_matches python2_7 python*" 0
test_is "_python_impl_matches python3_6 python*" 0
test_is "_python_impl_matches python3_7 python*" 0
test_is "_python_impl_matches pypy3 python*" 1
set +f
rm "${tmpfile}"
texit

View File

@ -0,0 +1,181 @@
#!/bin/bash
# Copyright 1999-2016 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
source tests-common.sh
EAPI=6
inherit rebar
EPREFIX="${tmpdir}/fakeroot"
S="${WORKDIR}/${P}"
setup() {
mkdir -p "${S}" || die
for pkg in foo-0.1.0 bar-0.1.0; do
mkdir -p "${EPREFIX}$(get_erl_libs)/${pkg}/include" || die
done
cat <<EOF >"${S}/typical.config" || die
%%% Comment
{erl_opts, [debug_info, {src_dirs, ["src"]},
{i, "include"},
{i, "deps/foo/include"},
{i, "../foo/include"}]}.
{port_env, [{"CFLAGS", "\$CFLAGS"}, {"LDFLAGS", "\$LDFLAGS"}]}.
EOF
cat <<EOF >"${S}/typical.config.expected" || die
%%% Comment
{erl_opts, [debug_info, {src_dirs, ["src"]},
{i, "include"},
{i, "${EPREFIX}$(get_erl_libs)/foo-0.1.0/include"},
{i, "../foo/include"}]}.
{port_env, [{"CFLAGS", "\$CFLAGS"}, {"LDFLAGS", "\$LDFLAGS"}]}.
EOF
cat <<EOF >"${S}/inc_one_line.config" || die
%%% Comment
{erl_opts, [debug_info, {src_dirs, ["src"]}, {i, "include"}, {i, "deps/foo/include"}, {i, "../foo/include"}]}.
{port_env, [{"CFLAGS", "\$CFLAGS"}, {"LDFLAGS", "\$LDFLAGS"}]}.
EOF
cat <<EOF >"${S}/inc_one_line.config.expected" || die
%%% Comment
{erl_opts, [debug_info, {src_dirs, ["src"]}, {i, "include"}, {i, "${EPREFIX}$(get_erl_libs)/foo-0.1.0/include"}, {i, "../foo/include"}]}.
{port_env, [{"CFLAGS", "\$CFLAGS"}, {"LDFLAGS", "\$LDFLAGS"}]}.
EOF
}
test_typical_config() {
local diff_rc
local unit_rc
# Prepare
cd "${S}" || die
cp typical.config rebar.config || die
# Run unit
(rebar_fix_include_path foo)
unit_rc=$?
# Test result
diff rebar.config typical.config.expected
diff_rc=$?
[[ ${unit_rc}${diff_rc} = 00 ]]
}
test_typical_config_with_different_name() {
local diff_rc
local unit_rc
# Prepare
cd "${S}" || die
cp typical.config other.config || die
# Run unit
(rebar_fix_include_path foo other.config)
unit_rc=$?
# Test result
diff other.config typical.config.expected
diff_rc=$?
[[ ${unit_rc}${diff_rc} = 00 ]]
}
test_multiple_versions() {
local diff_rc
local unit_rc
# Prepare
cd "${S}" || die
cp typical.config rebar.config || die
mkdir -p "${EPREFIX}$(get_erl_libs)/foo-1.0.0/include" || die
# Run unit
(rebar_fix_include_path foo 2>/dev/null)
unit_rc=$?
# Test result
diff rebar.config typical.config
diff_rc=$?
# Clean up
rm -r "${EPREFIX}$(get_erl_libs)/foo-1.0.0" || die
[[ ${unit_rc}${diff_rc} = 10 ]]
}
test_not_found() {
local diff_rc
local unit_rc
# Prepare
cd "${S}" || die
cp typical.config rebar.config || die
# Run unit
(rebar_fix_include_path fo 2>/dev/null)
unit_rc=$?
# Test result
diff rebar.config typical.config
diff_rc=$?
[[ ${unit_rc}${diff_rc} = 10 ]]
}
test_includes_in_one_line() {
local diff_rc
local unit_rc
# Prepare
cd "${S}" || die
cp inc_one_line.config rebar.config || die
# Run unit
(rebar_fix_include_path foo)
unit_rc=$?
# Test result
diff rebar.config inc_one_line.config.expected
diff_rc=$?
[[ ${unit_rc}${diff_rc} = 00 ]]
}
setup
tbegin "rebar_fix_include_path deals with typical config"
test_typical_config
tend $?
tbegin "rebar_fix_include_path deals with typical config with different name"
test_typical_config_with_different_name
tend $?
tbegin "rebar_fix_include_path fails on multiple versions of dependency"
test_multiple_versions
tend $?
tbegin "rebar_fix_include_path fails if dependency is not found"
test_not_found
tend $?
tbegin "rebar_fix_include_path deals with all includes in one line"
test_includes_in_one_line
tend $?
texit

121
eclass/tests/rebar_remove_deps.sh Executable file
View File

@ -0,0 +1,121 @@
#!/bin/bash
# Copyright 1999-2016 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
source tests-common.sh
EAPI=6
inherit rebar
EPREFIX="${tmpdir}/fakeroot"
S="${WORKDIR}/${P}"
setup() {
mkdir -p "${S}" || die
cat <<EOF >"${S}/rebar.config.expected" || die
%%% Comment
{port_specs, [{"priv/lib/esip_drv.so", ["c_src/esip_codec.c"]}]}.
{deps, []}.
{clean_files, ["c_src/esip_codec.gcda", "c_src/esip_codec.gcno"]}.
EOF
cat <<EOF >"${S}/typical.config" || die
%%% Comment
{port_specs, [{"priv/lib/esip_drv.so", ["c_src/esip_codec.c"]}]}.
{deps, [{stun, ".*", {git, "https://github.com/processone/stun", {tag, "1.0.3"}}},
{fast_tls, ".*", {git, "https://github.com/processone/fast_tls", {tag, "1.0.3"}}},
{p1_utils, ".*", {git, "https://github.com/processone/p1_utils", {tag, "1.0.3"}}}]}.
{clean_files, ["c_src/esip_codec.gcda", "c_src/esip_codec.gcno"]}.
EOF
cat <<EOF >"${S}/deps_one_line.config" || die
%%% Comment
{port_specs, [{"priv/lib/esip_drv.so", ["c_src/esip_codec.c"]}]}.
{deps, [{stun, ".*", {git, "https://github.com/processone/stun", {tag, "1.0.3"}}}, {fast_tls, ".*", {git, "https://github.com/processone/fast_tls", {tag, "1.0.3"}}}, {p1_utils, ".*", {git, "https://github.com/processone/p1_utils", {tag, "1.0.3"}}}]}.
{clean_files, ["c_src/esip_codec.gcda", "c_src/esip_codec.gcno"]}.
EOF
}
test_typical_config() {
local diff_rc
local unit_rc
# Prepare
cd "${S}" || die
cp typical.config rebar.config || die
# Run unit
(rebar_remove_deps)
unit_rc=$?
# Test result
diff rebar.config rebar.config.expected
diff_rc=$?
[[ ${unit_rc}${diff_rc} = 00 ]]
}
test_typical_config_with_different_name() {
local diff_rc
local unit_rc
# Prepare
cd "${S}" || die
cp typical.config other.config || die
# Run unit
(rebar_remove_deps other.config)
unit_rc=$?
# Test result
diff other.config rebar.config.expected
diff_rc=$?
[[ ${unit_rc}${diff_rc} = 00 ]]
}
test_deps_in_one_line() {
local diff_rc
local unit_rc
# Prepare
cd "${S}" || die
cp deps_one_line.config rebar.config || die
# Run unit
(rebar_remove_deps)
unit_rc=$?
# Test result
diff rebar.config rebar.config.expected
diff_rc=$?
[[ ${unit_rc}${diff_rc} = 00 ]]
}
setup
tbegin "rebar_remove_deps deals with typical config"
test_typical_config
tend $?
tbegin "rebar_remove_deps deals with typical config with different name"
test_typical_config_with_different_name
tend $?
tbegin "rebar_remove_deps deals with all deps in one line"
test_deps_in_one_line
tend $?
texit

114
eclass/tests/rebar_set_vsn.sh Executable file
View File

@ -0,0 +1,114 @@
#!/bin/bash
# Copyright 1999-2016 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
source tests-common.sh
EAPI=6
inherit rebar
EPREFIX="${tmpdir}/fakeroot"
S="${WORKDIR}/${P}"
setup() {
mkdir -p "${S}/src" || die
cat <<EOF >"${S}/app.src.expected" || die
%%% Comment
{application, esip,
[{description, "ProcessOne SIP server component in Erlang"},
{vsn, "0"},
{modules, []},
{registered, []},
EOF
cat <<EOF >"${S}/app.src" || die
%%% Comment
{application, esip,
[{description, "ProcessOne SIP server component in Erlang"},
{vsn, git},
{modules, []},
{registered, []},
EOF
}
test_typical_app_src() {
local diff_rc
local unit_rc
# Prepare
cd "${S}" || die
cp app.src "src/${PN}.app.src" || die
# Run unit
(rebar_set_vsn)
unit_rc=$?
# Test result
diff "src/${PN}.app.src" app.src.expected
diff_rc=$?
[[ ${unit_rc}${diff_rc} = 00 ]]
}
test_app_src_missing() {
local unit_rc
# Prepare
cd "${S}" || die
rm -f "src/${PN}.app.src" || die
# Run unit
(rebar_set_vsn 2>/dev/null)
unit_rc=$?
[[ ${unit_rc} = 1 ]]
}
test_set_custom_version() {
local diff_rc
local unit_rc
# Prepare
cd "${S}" || die
cp app.src "src/${PN}.app.src" || die
cat <<EOF >"${S}/custom_app.src.expected" || die
%%% Comment
{application, esip,
[{description, "ProcessOne SIP server component in Erlang"},
{vsn, "1.2.3"},
{modules, []},
{registered, []},
EOF
# Run unit
(rebar_set_vsn 1.2.3)
unit_rc=$?
# Test result
diff "src/${PN}.app.src" custom_app.src.expected
diff_rc=$?
[[ ${unit_rc}${diff_rc} = 00 ]]
}
setup
tbegin "rebar_set_vsn deals with typical app.src"
test_typical_app_src
tend $?
tbegin "rebar_set_vsn fails when app.src is missing"
test_app_src_missing
tend $?
tbegin "rebar_set_vsn sets custom version in app.src"
test_set_custom_version
tend $?
texit

80
eclass/tests/savedconfig.sh Executable file
View File

@ -0,0 +1,80 @@
#!/bin/bash
# Copyright 1999-2019 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=7
source tests-common.sh
inherit savedconfig
quiet() {
local out ret
out=$("$@" 2>&1)
ret=$?
[[ ${ret} -eq 0 ]] || echo "${out}"
return ${ret}
}
sc() { EBUILD_PHASE=install quiet save_config "$@" ; }
rc() { EBUILD_PHASE=prepare quiet restore_config "$@" ; }
cleanup() { rm -rf "${ED}"/* "${T}"/* "${WORKDIR}"/* ; }
test-it() {
local ret=0
tbegin "$@"
mkdir -p "${ED}"/etc/portage/savedconfig
: $(( ret |= $? ))
pushd "${WORKDIR}" >/dev/null
: $(( ret |= $? ))
test
: $(( ret |= $? ))
popd >/dev/null
: $(( ret |= $? ))
tend ${ret}
cleanup
}
test() {
touch f || return 1
sc f || return 1
[[ -f ${ED}/etc/portage/savedconfig/${CATEGORY}/${PF} ]]
}
test-it "simple save_config"
test() {
touch a b c || return 1
sc a b c || return 1
[[ -d ${ED}/etc/portage/savedconfig/${CATEGORY}/${PF} ]]
}
test-it "multi save_config"
test() {
mkdir dir || return 1
touch dir/{a,b,c} || return 1
sc dir || return 1
[[ -d ${ED}/etc/portage/savedconfig/${CATEGORY}/${PF} ]]
}
test-it "dir save_config"
PORTAGE_CONFIGROOT=${D}
test() {
echo "ggg" > f || return 1
rc f || return 1
[[ $(<f) == "ggg" ]]
}
test-it "simple restore_config"
test() {
echo "ggg" > f || return 1
rc f || return 1
[[ $(<f) == "ggg" ]] || return 1
sc f || return 1
echo "hhh" > f || return 1
rc f || return 1
[[ $(<f) == "ggg" ]]
}
test-it "simple restore+save config"
texit

62
eclass/tests/scons-utils.sh Executable file
View File

@ -0,0 +1,62 @@
#!/bin/bash
# Copyright 1999-2019 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
source tests-common.sh
inherit scons-utils
test-scons_clean_makeopts() {
tbegin "scons_clean_makeopts() for ${1}"
local SCONSOPTS ret=0
_scons_clean_makeopts ${1}
if [[ ${SCONSOPTS} != ${2-${1}} ]]; then
eerror "Self-test failed:"
eindent
eerror "MAKEOPTS: ${1}"
eerror "Expected: ${2-${1}}"
eerror "Actual: ${SCONSOPTS}"
eoutdent
ret=1
fi
tend ${ret}
return ${ret}
}
# jobcount expected for non-specified state
jc=$(( $(get_nproc) + 1 ))
# failed test counter
failed=0
# sane MAKEOPTS
test-scons_clean_makeopts '--jobs=14 -k'
test-scons_clean_makeopts '--jobs=14 -k'
test-scons_clean_makeopts '--jobs 15 -k'
test-scons_clean_makeopts '--jobs=16 --keep-going'
test-scons_clean_makeopts '-j17 --keep-going'
test-scons_clean_makeopts '-j 18 --keep-going'
# needing cleaning
test-scons_clean_makeopts '--jobs -k' "--jobs=${jc} -k"
test-scons_clean_makeopts '--jobs --keep-going' "--jobs=${jc} --keep-going"
test-scons_clean_makeopts '-kj' "-kj ${jc}"
# broken by definition (but passed as it breaks make as well)
test-scons_clean_makeopts '-jk'
test-scons_clean_makeopts '--jobs=randum'
test-scons_clean_makeopts '-kjrandum'
# needing stripping
test-scons_clean_makeopts '--load-average=25 -kj16' '-kj16'
test-scons_clean_makeopts '--load-average 25 -k -j17' '-k -j17'
test-scons_clean_makeopts '-j2 HOME=/tmp' '-j2'
test-scons_clean_makeopts '--jobs funnystuff -k' "--jobs=${jc} -k"
# bug #388961
test-scons_clean_makeopts '--jobs -l3' "--jobs=${jc}"
test-scons_clean_makeopts '-j -l3' "-j ${jc}"
texit

View File

@ -0,0 +1,107 @@
#!/bin/bash
# Copyright 1999-2019 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
if ! source /lib/gentoo/functions.sh ; then
echo "Missing functions.sh. Please install sys-apps/gentoo-functions!" 1>&2
exit 1
fi
# Let overlays override this so they can add their own testsuites.
TESTS_ECLASS_SEARCH_PATHS=( .. )
inherit() {
local e path
for e in "$@" ; do
for path in "${TESTS_ECLASS_SEARCH_PATHS[@]}" ; do
local eclass=${path}/${e}.eclass
if [[ -e "${eclass}" ]] ; then
source "${eclass}"
continue 2
fi
done
die "could not find ${e}.eclass"
done
}
EXPORT_FUNCTIONS() { :; }
debug-print() {
[[ ${#} -eq 0 ]] && return
if [[ ${ECLASS_DEBUG_OUTPUT} == on ]]; then
printf 'debug: %s\n' "${@}" >&2
elif [[ -n ${ECLASS_DEBUG_OUTPUT} ]]; then
printf 'debug: %s\n' "${@}" >> "${ECLASS_DEBUG_OUTPUT}"
fi
}
debug-print-function() {
debug-print "${1}, parameters: ${*:2}"
}
debug-print-section() {
debug-print "now in section ${*}"
}
has() {
local needle=$1
shift
local x
for x in "$@"; do
[ "${x}" = "${needle}" ] && return 0
done
return 1
}
use() { has "$1" ${IUSE} ; }
die() {
echo "die: $*" 1>&2
exit 1
}
has_version() {
portageq has_version / "$@"
}
tret=0
tbegin() {
ebegin "Testing $*"
}
texit() {
rm -rf "${tmpdir}"
exit ${tret}
}
tend() {
t eend "$@"
}
t() {
"$@"
local ret=$?
: $(( tret |= ${ret} ))
return ${ret}
}
tmpdir="${PWD}/tmp"
pkg_root="${tmpdir}/$0/${RANDOM}"
T="${pkg_root}/temp"
D="${pkg_root}/image"
WORKDIR="${pkg_root}/work"
ED=${D}
mkdir -p "${D}" "${T}" "${WORKDIR}"
dodir() {
mkdir -p "${@/#/${ED}/}"
}
elog() { einfo "$@" ; }
IUSE=""
CATEGORY="dev-eclass"
PN="tests"
PV="0"
P="${PN}-${PV}"
PF=${P}
SLOT=0
addwrite() { :; }

200
eclass/tests/toolchain-funcs.sh Executable file
View File

@ -0,0 +1,200 @@
#!/bin/bash
# Copyright 1999-2019 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
source tests-common.sh
inherit toolchain-funcs
#
# TEST: tc-arch-kernel
#
test-tc-arch-kernel() {
local ret=0
KV=$1 ; shift
for CHOST in "$@" ; do
exp=${CHOST##*:}
CHOST=${CHOST%%:*}
actual=$(tc-arch-kernel)
if [[ ${actual} != ${exp:-${CHOST}} ]] ; then
eerror "Failure for CHOST: ${CHOST} Expected: ${exp} != Actual: ${actual}"
((++ret))
fi
done
return ${ret}
}
tbegin "tc-arch-kernel() (KV=2.6.30)"
test-tc-arch-kernel 2.6.30 \
i{3..6}86:x86 x86_64:x86 \
powerpc{,64}:powerpc i{3..6}86-gentoo-freebsd:i386 \
or1k:openrisc or1k-linux-musl:openrisc
tend $?
#
# TEST: tc-arch
#
tbegin "tc-arch"
ret=0
for CHOST in \
alpha arm{,eb}:arm avr32:avr bfin cris hppa i{3..6}86:x86 ia64 m68k \
mips{,eb}:mips nios2 powerpc:ppc powerpc64:ppc64 s390{,x}:s390 \
sh{1..4}{,eb}:sh sparc{,64}:sparc vax x86_64:amd64
do
exp=${CHOST##*:}
CHOST=${CHOST%%:*}
actual=$(tc-arch)
if [[ ${actual} != ${exp:-${CHOST}} ]] ; then
eerror "Failure for CHOST: ${CHOST} Expected: ${exp} != Actual: ${actual}"
: $((++ret))
fi
done
tend ${ret}
#
# TEST: tc-ld-is-gold
#
tbegin "tc-ld-is-gold (ld=bfd cc=bfd)"
LD=ld.bfd LDFLAGS=-fuse-ld=bfd tc-ld-is-gold && ret=1 || ret=0
tend ${ret}
tbegin "tc-ld-is-gold (ld=gold cc=default)"
LD=ld.gold tc-ld-is-gold
ret=$?
tend ${ret}
tbegin "tc-ld-is-gold (ld=gold cc=bfd)"
LD=ld.gold LDFLAGS=-fuse-ld=bfd tc-ld-is-gold
ret=$?
tend ${ret}
tbegin "tc-ld-is-gold (ld=bfd cc=gold)"
LD=ld.bfd LDFLAGS=-fuse-ld=gold tc-ld-is-gold
ret=$?
tend ${ret}
#
# TEST: tc-ld-disable-gold
#
tbegin "tc-ld-disable-gold (bfd selected)"
(
export LD=ld.bfd LDFLAGS=-fuse-ld=bfd
ewarn() { :; }
tc-ld-disable-gold
[[ ${LD} == "ld.bfd" && ${LDFLAGS} == "-fuse-ld=bfd" ]]
)
tend $?
tbegin "tc-ld-disable-gold (ld=gold)"
(
export LD=ld.gold LDFLAGS=
ewarn() { :; }
tc-ld-disable-gold
[[ ${LD} == "ld.bfd" || ${LDFLAGS} == *"-fuse-ld=bfd"* ]]
)
tend $?
tbegin "tc-ld-disable-gold (cc=gold)"
(
export LD= LDFLAGS="-fuse-ld=gold"
ewarn() { :; }
tc-ld-disable-gold
[[ ${LD} == *"/ld.bfd" || ${LDFLAGS} == "-fuse-ld=gold -fuse-ld=bfd" ]]
)
tend $?
unset CPP
tbegin "tc-get-compiler-type (gcc)"
(
export CC=gcc
[[ $(tc-get-compiler-type) == gcc ]]
)
tend $?
tbegin "tc-is-gcc (gcc)"
(
export CC=gcc
tc-is-gcc
)
tend $?
tbegin "! tc-is-clang (gcc)"
(
export CC=gcc
! tc-is-clang
)
tend $?
if type -P clang &>/dev/null; then
tbegin "tc-get-compiler-type (clang)"
(
export CC=clang
[[ $(tc-get-compiler-type) == clang ]]
)
tend $?
tbegin "! tc-is-gcc (clang)"
(
export CC=clang
! tc-is-gcc
)
tend $?
tbegin "tc-is-clang (clang)"
(
export CC=clang
tc-is-clang
)
tend $?
fi
if type -P pathcc &>/dev/null; then
tbegin "tc-get-compiler-type (pathcc)"
(
export CC=pathcc
[[ $(tc-get-compiler-type) == pathcc ]]
)
tend $?
tbegin "! tc-is-gcc (pathcc)"
(
export CC=pathcc
! tc-is-gcc
)
tend $?
tbegin "! tc-is-clang (pathcc)"
(
export CC=pathcc
! tc-is-clang
)
tend $?
fi
for compiler in gcc clang not-really-a-compiler; do
if type -P ${compiler} &>/dev/null; then
tbegin "tc-cpp-is-true ($compiler, defined)"
(
export CC=${compiler}
tc-cpp-is-true "defined(SOME_DEFINED_SYMBOL)" -DSOME_DEFINED_SYMBOL
)
tend $?
tbegin "tc-cpp-is-true ($compiler, not defined)"
(
export CC=${compiler}
! tc-cpp-is-true "defined(SOME_UNDEFINED_SYMBOL)"
)
tend $?
tbegin "tc-cpp-is-true ($compiler, defined on -ggdb3)"
(
export CC=${compiler}
tc-cpp-is-true "defined(SOME_DEFINED_SYMBOL)" -DSOME_DEFINED_SYMBOL -ggdb3
)
tend $?
fi
done
texit

185
eclass/tests/toolchain.sh Executable file
View File

@ -0,0 +1,185 @@
#!/bin/bash
# Copyright 1999-2019 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=5
# apply exlass globals to test version parsing
TOOLCHAIN_GCC_PV=7.3.0
PR=r0
source tests-common.sh
inherit toolchain
# Ignore actually running version of gcc and fake new version
# to force downgrade test on all conditions below.
gcc-version() {
echo "99.99"
}
test_downgrade_arch_flags() {
local exp msg ret=0 ver
ver=${1}
exp=${2}
shift 2
CFLAGS=${@}
tbegin "downgrade_arch_flags: ${ver} ${CFLAGS} => ${exp}"
CHOST=x86_64 # needed for tc-arch
downgrade_arch_flags ${ver}
if [[ ${CFLAGS} != ${exp} ]]; then
msg="Failure - Expected: \"${exp}\" Got: \"${CFLAGS}\" Ver: ${ver}"
ret=1
fi
tend ${ret} ${msg}
}
# ver expected given
test_downgrade_arch_flags 10 "-march=haswell" "-march=haswell"
test_downgrade_arch_flags 4.9 "-march=haswell" "-march=haswell"
test_downgrade_arch_flags 4.8 "-march=core-avx2" "-march=haswell"
test_downgrade_arch_flags 4.7 "-march=core-avx2" "-march=haswell"
test_downgrade_arch_flags 4.6 "-march=core-avx-i" "-march=haswell"
test_downgrade_arch_flags 4.5 "-march=core2" "-march=haswell"
test_downgrade_arch_flags 4.4 "-march=core2" "-march=haswell"
test_downgrade_arch_flags 4.3 "-march=core2" "-march=haswell"
test_downgrade_arch_flags 4.2 "-march=nocona" "-march=haswell"
test_downgrade_arch_flags 4.1 "-march=nocona" "-march=haswell"
test_downgrade_arch_flags 4.0 "-march=nocona" "-march=haswell"
test_downgrade_arch_flags 3.4 "-march=nocona" "-march=haswell"
test_downgrade_arch_flags 3.3 "-march=nocona" "-march=haswell"
test_downgrade_arch_flags 4.9 "-march=bdver4" "-march=bdver4"
test_downgrade_arch_flags 4.8 "-march=bdver3" "-march=bdver4"
test_downgrade_arch_flags 4.7 "-march=bdver2" "-march=bdver4"
test_downgrade_arch_flags 4.6 "-march=bdver1" "-march=bdver4"
test_downgrade_arch_flags 4.5 "-march=amdfam10" "-march=bdver4"
test_downgrade_arch_flags 4.4 "-march=amdfam10" "-march=bdver4"
test_downgrade_arch_flags 4.3 "-march=amdfam10" "-march=bdver4"
test_downgrade_arch_flags 4.2 "-march=k8" "-march=bdver4"
test_downgrade_arch_flags 4.1 "-march=k8" "-march=bdver4"
test_downgrade_arch_flags 4.0 "-march=k8" "-march=bdver4"
test_downgrade_arch_flags 3.4 "-march=k8" "-march=bdver4"
test_downgrade_arch_flags 3.3 "-march=x86-64" "-march=bdver4"
test_downgrade_arch_flags 3.4 "-march=c3-2" "-march=c3-2"
test_downgrade_arch_flags 3.3 "-march=c3" "-march=c3-2"
test_downgrade_arch_flags 4.5 "-march=garbage" "-march=garbage"
test_downgrade_arch_flags 10 "-mtune=intel" "-mtune=intel"
test_downgrade_arch_flags 4.9 "-mtune=intel" "-mtune=intel"
test_downgrade_arch_flags 4.8 "-mtune=generic" "-mtune=intel"
test_downgrade_arch_flags 3.4 "" "-mtune=generic"
test_downgrade_arch_flags 3.4 "" "-mtune=x86-64"
test_downgrade_arch_flags 3.3 "" "-mtune=anything"
test_downgrade_arch_flags 4.5 "-march=amdfam10 -mtune=generic" "-march=btver2 -mtune=generic"
test_downgrade_arch_flags 3.3 "-march=k6-2" "-march=geode -mtune=barcelona"
test_downgrade_arch_flags 3.4 "-march=k8" "-march=btver2 -mtune=generic"
test_downgrade_arch_flags 10 "-march=native" "-march=native"
test_downgrade_arch_flags 8 "-march=znver1" "-march=znver2"
test_downgrade_arch_flags 4.2 "-march=native" "-march=native"
test_downgrade_arch_flags 4.1 "-march=nocona" "-march=native"
test_downgrade_arch_flags 10 "-march=foo -mno-sha -mno-rtm -mno-avx2 -mno-avx -mno-sse4.1" "-march=foo -mno-sha -mno-rtm -mno-avx2 -mno-avx -mno-sse4.1"
test_downgrade_arch_flags 4.9 "-march=foo -mno-sha -mno-rtm -mno-avx2 -mno-avx -mno-sse4.1" "-march=foo -mno-sha -mno-rtm -mno-avx2 -mno-avx -mno-sse4.1"
test_downgrade_arch_flags 4.8 "-march=foo -mno-rtm -mno-avx2 -mno-avx -mno-sse4.1" "-march=foo -mno-sha -mno-rtm -mno-avx2 -mno-avx -mno-sse4.1"
test_downgrade_arch_flags 4.7 "-march=foo -mno-avx2 -mno-avx -mno-sse4.1" "-march=foo -mno-sha -mno-rtm -mno-avx2 -mno-avx -mno-sse4.1"
test_downgrade_arch_flags 4.6 "-march=foo -mno-avx -mno-sse4.1" "-march=foo -mno-sha -mno-rtm -mno-avx2 -mno-avx -mno-sse4.1"
test_downgrade_arch_flags 4.3 "-march=foo -mno-sse4.1" "-march=foo -mno-sha -mno-rtm -mno-avx2 -mno-avx -mno-sse4.1"
test_downgrade_arch_flags 4.2 "-march=foo" "-march=foo -mno-sha -mno-rtm -mno-avx2 -mno-avx -mno-sse4.1"
test_downgrade_arch_flags 4.4 "-O2 -march=core2 -ffoo -fblah" "-O2 -march=atom -mno-sha -ffoo -mno-rtm -fblah"
# basic version parsing tests in preparation to eapi7-ver switch
test_tc_version_is_at_least() {
local exp msg ret=0 want mine res
want=${1}
mine=${2}
exp=${3}
tbegin "tc_version_is_at_least: ${want} ${mine} => ${exp}"
tc_version_is_at_least ${want} ${mine}
res=$?
if [[ ${res} -ne ${exp} ]]; then
msg="Failure - Expected: \"${exp}\" Got: \"${res}\""
ret=1
fi
tend ${ret} ${msg}
}
# want mine expect
test_tc_version_is_at_least 8 '' 1
test_tc_version_is_at_least 8.0 '' 1
test_tc_version_is_at_least 7 '' 0
test_tc_version_is_at_least 7.0 '' 0
test_tc_version_is_at_least ${TOOLCHAIN_GCC_PV} '' 0
test_tc_version_is_at_least 5.0 6.0 0
test_tc_version_is_between() {
local exp msg ret=0 lo hi res
lo=${1}
hi=${2}
exp=${3}
tbegin "tc_version_is_between: ${lo} ${hi} => ${exp}"
tc_version_is_between ${lo} ${hi}
res=$?
if [[ ${res} -ne ${exp} ]]; then
msg="Failure - Expected: \"${exp}\" Got: \"${res}\""
ret=1
fi
tend ${ret} ${msg}
}
# lo hi expect
test_tc_version_is_between 1 0 1
test_tc_version_is_between 1 2 1
test_tc_version_is_between 7 8 0
test_tc_version_is_between ${TOOLCHAIN_GCC_PV} 8 0
test_tc_version_is_between ${TOOLCHAIN_GCC_PV} ${TOOLCHAIN_GCC_PV} 1
test_tc_version_is_between 7 ${TOOLCHAIN_GCC_PV} 1
test_tc_version_is_between 8 9 1
# eclass has a few critical global variables worth not breaking
test_var_assert() {
local var_name exp
var_name=${1}
exp=${2}
tbegin "assert variable value: ${var_name} => ${exp}"
if [[ ${!var_name} != ${exp} ]]; then
msg="Failure - Expected: \"${exp}\" Got: \"${!var_name}\""
ret=1
fi
tend ${ret} ${msg}
}
# TODO: convert these globals to helpers to ease testing against multiple
# ${TOOLCHAIN_GCC_PV} vaues.
test_var_assert GCC_PV 7.3.0
test_var_assert GCC_PVR 7.3.0
test_var_assert GCC_RELEASE_VER 7.3.0
test_var_assert GCC_BRANCH_VER 7.3
test_var_assert GCCMAJOR 7
test_var_assert GCCMINOR 3
test_var_assert GCCMICRO 0
test_var_assert GCC_CONFIG_VER 7.3.0
test_var_assert PREFIX /usr
texit

View File

@ -0,0 +1,199 @@
#!/bin/bash
# Copyright 1999-2015 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
source tests-common.sh
inherit versionator
eshopts_push -s extglob
ver=( "" "lt" "eq" "gt" )
lt=1 eq=2 gt=3
test_version_compare() {
tbegin "version_compare ${1} -${ver[${2}]} ${3}"
version_compare "${1}" "${3}"
local r=$?
[[ ${r} -eq ${2} ]]
tend $? "FAIL: ${@} (got ${r} exp ${2})"
}
echo "
0 $lt 1
1 $lt 2
2 $gt 1
2 $eq 2
0 $eq 0
10 $lt 20
68 $eq 068
068 $gt 67
068 $lt 69
1.0 $lt 2.0
2.0 $eq 2.0
2.0 $gt 1.0
1.0 $gt 0.0
0.0 $eq 0.0
0.0 $lt 1.0
0.1 $lt 0.2
0.2 $eq 0.2
0.3 $gt 0.2
1.2 $lt 2.1
2.1 $gt 1.2
1.2.3 $lt 1.2.4
1.2.4 $gt 1.2.3
1.2.0 $gt 1.2
1.2.1 $gt 1.2
1.2 $lt 1.2.1
1.2b $eq 1.2b
1.2b $lt 1.2c
1.2b $gt 1.2a
1.2b $gt 1.2
1.2 $lt 1.2a
1.3 $gt 1.2a
1.3 $lt 1.3a
1.0_alpha7 $lt 1.0_beta7
1.0_beta $lt 1.0_pre
1.0_pre5 $lt 1.0_rc2
1.0_rc2 $lt 1.0
1.0_p1 $gt 1.0
1.0_p1-r1 $gt 1.0_p1
1.0_alpha6-r1 $gt 1.0_alpha6
1.0_beta6-r1 $gt 1.0_alpha6-r2
1.0_pre1 $lt 1.0_p1
1.0p $gt 1.0_p1
1.0r $gt 1.0-r1
1.6.15 $gt 1.6.10-r2
1.6.10-r2 $lt 1.6.15
" | while read a b c ; do
[[ -z "${a}${b}${c}" ]] && continue
test_version_compare "${a}" "${b}" "${c}"
done
for q in "alpha beta pre rc=${lt};${gt}" "p=${gt};${lt}" ; do
for p in ${q%%=*} ; do
c=${q##*=}
alt=${c%%;*} agt=${c##*;}
test_version_compare "1.0" $agt "1.0_${p}"
test_version_compare "1.0" $agt "1.0_${p}1"
test_version_compare "1.0" $agt "1.0_${p}068"
test_version_compare "2.0_${p}" $alt "2.0"
test_version_compare "2.0_${p}1" $alt "2.0"
test_version_compare "2.0_${p}068" $alt "2.0"
test_version_compare "1.0_${p}" $eq "1.0_${p}"
test_version_compare "0.0_${p}" $lt "0.0_${p}1"
test_version_compare "666_${p}3" $gt "666_${p}"
test_version_compare "1_${p}7" $lt "1_${p}8"
test_version_compare "1_${p}7" $eq "1_${p}7"
test_version_compare "1_${p}7" $gt "1_${p}6"
test_version_compare "1_${p}09" $eq "1_${p}9"
test_version_compare "1_${p}7-r0" $eq "1_${p}7"
test_version_compare "1_${p}7-r0" $lt "1_${p}7-r1"
test_version_compare "1_${p}7-r0" $lt "1_${p}7-r01"
test_version_compare "1_${p}7-r01" $eq "1_${p}7-r1"
test_version_compare "1_${p}8-r1" $gt "1_${p}7-r100"
test_version_compare "1_${p}_alpha" $lt "1_${p}_beta"
done
done
for p in "-r" "_p" ; do
test_version_compare "7.2${p}1" $lt "7.2${p}2"
test_version_compare "7.2${p}2" $gt "7.2${p}1"
test_version_compare "7.2${p}3" $gt "7.2${p}2"
test_version_compare "7.2${p}2" $lt "7.2${p}3"
done
# The following tests all come from portage's test cases:
test_version_compare "6.0" $gt "5.0"
test_version_compare "5.0" $gt "5"
test_version_compare "1.0-r1" $gt "1.0-r0"
test_version_compare "1.0-r1" $gt "1.0"
test_version_compare "999999999999999999999999999999" $gt "999999999999999999999999999998"
test_version_compare "1.0.0" $gt "1.0"
test_version_compare "1.0.0" $gt "1.0b"
test_version_compare "1b" $gt "1"
test_version_compare "1b_p1" $gt "1_p1"
test_version_compare "1.1b" $gt "1.1"
test_version_compare "12.2.5" $gt "12.2b"
test_version_compare "4.0" $lt "5.0"
test_version_compare "5" $lt "5.0"
test_version_compare "1.0_pre2" $lt "1.0_p2"
test_version_compare "1.0_alpha2" $lt "1.0_p2"
test_version_compare "1.0_alpha1" $lt "1.0_beta1"
test_version_compare "1.0_beta3" $lt "1.0_rc3"
test_version_compare "1.001000000000000000001" $lt "1.001000000000000000002"
test_version_compare "1.00100000000" $lt "1.0010000000000000001"
test_version_compare "999999999999999999999999999998" $lt "999999999999999999999999999999"
test_version_compare "1.01" $lt "1.1"
test_version_compare "1.0-r0" $lt "1.0-r1"
test_version_compare "1.0" $lt "1.0-r1"
test_version_compare "1.0" $lt "1.0.0"
test_version_compare "1.0b" $lt "1.0.0"
test_version_compare "1_p1" $lt "1b_p1"
test_version_compare "1" $lt "1b"
test_version_compare "1.1" $lt "1.1b"
test_version_compare "12.2b" $lt "12.2.5"
test_version_compare "4.0" $eq "4.0"
test_version_compare "1.0" $eq "1.0"
test_version_compare "1.0-r0" $eq "1.0"
test_version_compare "1.0" $eq "1.0-r0"
test_version_compare "1.0-r0" $eq "1.0-r0"
test_version_compare "1.0-r1" $eq "1.0-r1"
# The following were just tests for != in portage, we need something a bit
# more precise
test_version_compare "1" $lt "2"
test_version_compare "1.0_alpha" $lt "1.0_pre"
test_version_compare "1.0_beta" $gt "1.0_alpha"
test_version_compare "0" $lt "0.0"
test_version_compare "1.0-r0" $lt "1.0-r1"
test_version_compare "1.0-r1" $gt "1.0-r0"
test_version_compare "1.0" $lt "1.0-r1"
test_version_compare "1.0-r1" $gt "1.0"
test_version_compare "1_p1" $lt "1b_p1"
test_version_compare "1b" $gt "1"
test_version_compare "1.1b" $gt "1.1"
test_version_compare "12.2b" $gt "12.2"
# The following tests all come from paludis's test cases:
test_version_compare "1.0" $gt "1"
test_version_compare "1" $lt "1.0"
test_version_compare "1.0_alpha" $gt "1_alpha"
test_version_compare "1.0_alpha" $gt "1"
test_version_compare "1.0_alpha" $lt "1.0"
test_version_compare "1.2.0.0_alpha7-r4" $gt "1.2_alpha7-r4"
test_version_compare "0001" $eq "1"
test_version_compare "01" $eq "001"
test_version_compare "0001.1" $eq "1.1"
test_version_compare "01.01" $eq "1.01"
test_version_compare "1.010" $eq "1.01"
test_version_compare "1.00" $eq "1.0"
test_version_compare "1.0100" $eq "1.010"
test_version_compare "1" $eq "1-r0"
test_version_compare "1-r00" $eq "1-r0"
eshopts_pop
texit