diff options
Diffstat (limited to 'eclass/tests')
26 files changed, 2573 insertions, 0 deletions
diff --git a/eclass/tests/autotools_eaclocal_amflags.sh b/eclass/tests/autotools_eaclocal_amflags.sh new file mode 100755 index 000000000000..b39f5420c31c --- /dev/null +++ b/eclass/tests/autotools_eaclocal_amflags.sh @@ -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 diff --git a/eclass/tests/distutils-r1.sh b/eclass/tests/distutils-r1.sh new file mode 100755 index 000000000000..d557f6cad534 --- /dev/null +++ b/eclass/tests/distutils-r1.sh @@ -0,0 +1,32 @@ +#!/bin/bash +# Copyright 1999-2015 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +EAPI=5 +PYTHON_COMPAT=( python2_7 ) +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 +} + +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 ${failed} + +texit diff --git a/eclass/tests/eapi7-ver.sh b/eclass/tests/eapi7-ver.sh new file mode 100755 index 000000000000..d4aa4fdbd289 --- /dev/null +++ b/eclass/tests/eapi7-ver.sh @@ -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 diff --git a/eclass/tests/eapi7-ver_benchmark.sh b/eclass/tests/eapi7-ver_benchmark.sh new file mode 100755 index 000000000000..c46713713368 --- /dev/null +++ b/eclass/tests/eapi7-ver_benchmark.sh @@ -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 diff --git a/eclass/tests/estack_eshopts.sh b/eclass/tests/estack_eshopts.sh new file mode 100755 index 000000000000..28346c65ec13 --- /dev/null +++ b/eclass/tests/estack_eshopts.sh @@ -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 diff --git a/eclass/tests/estack_estack.sh b/eclass/tests/estack_estack.sh new file mode 100755 index 000000000000..4845243d3ae4 --- /dev/null +++ b/eclass/tests/estack_estack.sh @@ -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 diff --git a/eclass/tests/estack_evar.sh b/eclass/tests/estack_evar.sh new file mode 100755 index 000000000000..29badba0079e --- /dev/null +++ b/eclass/tests/estack_evar.sh @@ -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 diff --git a/eclass/tests/eutils_path_exists.sh b/eclass/tests/eutils_path_exists.sh new file mode 100755 index 000000000000..00a89c7e446d --- /dev/null +++ b/eclass/tests/eutils_path_exists.sh @@ -0,0 +1,35 @@ +#!/bin/bash +# Copyright 1999-2015 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +source tests-common.sh + +inherit eutils + +test-path_exists() { + local exp=$1; shift + tbegin "path_exists($*) == ${exp}" + path_exists "$@" + [[ ${exp} -eq $? ]] + tend $? +} + +test-path_exists 1 +test-path_exists 1 -a +test-path_exists 1 -o + +good="/ . tests-common.sh /bin/bash" +test-path_exists 0 ${good} +test-path_exists 0 -a ${good} +test-path_exists 0 -o ${good} + +bad="/asjdkfljasdlfkja jlakjdsflkasjdflkasdjflkasdjflaskdjf" +test-path_exists 1 ${bad} +test-path_exists 1 -a ${bad} +test-path_exists 1 -o ${bad} + +test-path_exists 1 ${good} ${bad} +test-path_exists 1 -a ${good} ${bad} +test-path_exists 0 -o ${good} ${bad} + +texit diff --git a/eclass/tests/flag-o-matic.sh b/eclass/tests/flag-o-matic.sh new file mode 100755 index 000000000000..53af9f862c41 --- /dev/null +++ b/eclass/tests/flag-o-matic.sh @@ -0,0 +1,153 @@ +#!/bin/bash +# Copyright 1999-2015 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +source tests-common.sh + +inherit flag-o-matic + +CFLAGS="-a -b -c=1" +CXXFLAGS="-x -y -z=2" +LDFLAGS="-l -m -n=3" +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" +strip-unsupported-flags +[[ ${CFLAGS} == "" ]] && [[ ${CXXFLAGS} == "-z=2" ]] && [[ ${LDFLAGS} == "" ]] +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 (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 diff --git a/eclass/tests/git-r3.sh b/eclass/tests/git-r3.sh new file mode 100755 index 000000000000..6ff6226c0aa6 --- /dev/null +++ b/eclass/tests/git-r3.sh @@ -0,0 +1,203 @@ +#!/bin/bash +# Copyright 1999-2015 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +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 diff --git a/eclass/tests/git-r3_GIT_DIR.sh b/eclass/tests/git-r3_GIT_DIR.sh new file mode 100755 index 000000000000..06c4094ceb9e --- /dev/null +++ b/eclass/tests/git-r3_GIT_DIR.sh @@ -0,0 +1,60 @@ +#!/bin/bash +# Copyright 1999-2015 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +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 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 diff --git a/eclass/tests/git-r3_subrepos.sh b/eclass/tests/git-r3_subrepos.sh new file mode 100755 index 000000000000..5b814328a49e --- /dev/null +++ b/eclass/tests/git-r3_subrepos.sh @@ -0,0 +1,37 @@ +#!/bin/bash +# Copyright 1999-2015 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +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 diff --git a/eclass/tests/linux-info_get_running_version.sh b/eclass/tests/linux-info_get_running_version.sh new file mode 100755 index 000000000000..fbb5c827a452 --- /dev/null +++ b/eclass/tests/linux-info_get_running_version.sh @@ -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 diff --git a/eclass/tests/multiprocessing.sh b/eclass/tests/multiprocessing.sh new file mode 100755 index 000000000000..1ceb7f7fa7b2 --- /dev/null +++ b/eclass/tests/multiprocessing.sh @@ -0,0 +1,42 @@ +#!/bin/bash +# Copyright 1999-2015 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +source tests-common.sh + +inherit multiprocessing + +tbegin "simple" +MAKEOPTS="-j1" multijob_init +multijob_child_init ls -d / >/dev/null || die "fail!" +multijob_finish +tend $? + +tbegin "less simple" +multijob_init -j3 +multijob_child_init true || die "fail!" +multijob_child_init false || die "fail!" +multijob_child_init true || die "fail!" +multijob_finish +tend $(( $? == 1 ? 0 : 1 )) + +tbegin "less less simple" +multijob_init -j1 +multijob_child_init true || die "fail!" +multijob_child_init false || die "fail!" +multijob_child_init true && die "fail!" +multijob_finish +tend $? + +tbegin "less less less simple" +multijob_init -j10 +multijob_child_init true || die "fail!" +multijob_finish_one || die "fail!" +multijob_child_init false || die "fail!" +multijob_finish_one && die "fail!" +multijob_child_init true || die "fail!" +multijob_finish_one || die "fail!" +multijob_finish +tend $? + +texit diff --git a/eclass/tests/multiprocessing_makeopts_jobs.sh b/eclass/tests/multiprocessing_makeopts_jobs.sh new file mode 100755 index 000000000000..689313a397ba --- /dev/null +++ b/eclass/tests/multiprocessing_makeopts_jobs.sh @@ -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 diff --git a/eclass/tests/multiprocessing_makeopts_loadavg.sh b/eclass/tests/multiprocessing_makeopts_loadavg.sh new file mode 100755 index 000000000000..d17d7734b9f2 --- /dev/null +++ b/eclass/tests/multiprocessing_makeopts_loadavg.sh @@ -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 diff --git a/eclass/tests/python-utils-r1.sh b/eclass/tests/python-utils-r1.sh new file mode 100755 index 000000000000..414ad5c53d6b --- /dev/null +++ b/eclass/tests/python-utils-r1.sh @@ -0,0 +1,183 @@ +#!/bin/bash +# Copyright 1999-2015 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +EAPI=5 +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 +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_4 python3.4 +test_var PYTHON python3_4 /usr/bin/python3.4 +if [[ -x /usr/bin/python3.4 ]]; then + abiflags=$(/usr/bin/python3.4 -c 'import sysconfig; print(sysconfig.get_config_var("ABIFLAGS"))') + test_var PYTHON_SITEDIR python3_4 "/usr/lib*/python3.4/site-packages" + test_var PYTHON_INCLUDEDIR python3_4 "/usr/include/python3.4${abiflags}" + test_var PYTHON_LIBPATH python3_4 "/usr/lib*/libpython3.4${abiflags}$(get_libname)" + test_var PYTHON_CONFIG python3_4 "/usr/bin/python3.4${abiflags}-config" +fi +test_var PYTHON_PKG_DEP python3_4 '*dev-lang/python*:3.4' +test_var PYTHON_SCRIPTDIR python3_4 /usr/lib/python-exec/python3.4 + +test_var EPYTHON jython2_7 jython2.7 +test_var PYTHON jython2_7 /usr/bin/jython2.7 +if [[ -x /usr/bin/jython2.7 ]]; then + test_var PYTHON_SITEDIR jython2_7 /usr/share/jython-2.7/Lib/site-packages +fi +test_var PYTHON_PKG_DEP jython2_7 '*dev-java/jython*:2.7' +test_var PYTHON_SCRIPTDIR jython2_7 /usr/lib/python-exec/jython2.7 + +test_var EPYTHON pypy pypy +test_var PYTHON pypy /usr/bin/pypy +if [[ -x /usr/bin/pypy ]]; then + test_var PYTHON_SITEDIR pypy "/usr/lib*/pypy/site-packages" + test_var PYTHON_INCLUDEDIR pypy "/usr/lib*/pypy/include" +fi +test_var PYTHON_PKG_DEP pypy '*virtual/pypy*:0=' +test_var PYTHON_SCRIPTDIR pypy /usr/lib/python-exec/pypy + +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 '*virtual/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 jython2.7" 1 +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.4 '#!/usr/bin/python3.4' +test_fix_shebang '#!/usr/bin/python' pypy '#!/usr/bin/pypy' +test_fix_shebang '#!/usr/bin/python' pypy3 '#!/usr/bin/pypy3' +test_fix_shebang '#!/usr/bin/python' jython2.7 '#!/usr/bin/jython2.7' + +# 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.4 '#!/usr/bin/python3.4' +test_fix_shebang '#!/usr/bin/python2' python3.4 FAIL +test_fix_shebang '#!/usr/bin/python2' python3.4 '#!/usr/bin/python3.4' --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' pypy '#!/usr/bin/pypy' +test_fix_shebang '#!/usr/bin/pypy' python2.7 FAIL +test_fix_shebang '#!/usr/bin/pypy' python2.7 '#!/usr/bin/python2.7' --force +test_fix_shebang '#!/usr/bin/jython2.7' jython2.7 '#!/usr/bin/jython2.7' +test_fix_shebang '#!/usr/bin/jython2.7' jython3.2 FAIL +test_fix_shebang '#!/usr/bin/jython2.7' jython3.2 '#!/usr/bin/jython3.2' --force + +# fancy path handling +test_fix_shebang '#!/mnt/python2/usr/bin/python' python3.4 \ + '#!/mnt/python2/usr/bin/python3.4' +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 ' + +# make sure we don't break pattern matching +test_is "_python_impl_supported python2_5" 1 +test_is "_python_impl_supported python2_6" 1 +test_is "_python_impl_supported python2_7" 0 +test_is "_python_impl_supported python3_1" 1 +test_is "_python_impl_supported python3_2" 1 +test_is "_python_impl_supported python3_3" 1 +test_is "_python_impl_supported python3_4" 0 +test_is "_python_impl_supported python3_5" 0 +test_is "_python_impl_supported python3_6" 0 +test_is "_python_impl_supported pypy1_8" 1 +test_is "_python_impl_supported pypy1_9" 1 +test_is "_python_impl_supported pypy2_0" 1 +test_is "_python_impl_supported pypy" 0 +test_is "_python_impl_supported pypy3" 0 +test_is "_python_impl_supported jython2_7" 0 + +rm "${tmpfile}" + +texit diff --git a/eclass/tests/rebar_fix_include_path.sh b/eclass/tests/rebar_fix_include_path.sh new file mode 100755 index 000000000000..8164e39d7252 --- /dev/null +++ b/eclass/tests/rebar_fix_include_path.sh @@ -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 diff --git a/eclass/tests/rebar_remove_deps.sh b/eclass/tests/rebar_remove_deps.sh new file mode 100755 index 000000000000..1b877b33929b --- /dev/null +++ b/eclass/tests/rebar_remove_deps.sh @@ -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 diff --git a/eclass/tests/rebar_set_vsn.sh b/eclass/tests/rebar_set_vsn.sh new file mode 100755 index 000000000000..315d8a76ec4b --- /dev/null +++ b/eclass/tests/rebar_set_vsn.sh @@ -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 diff --git a/eclass/tests/savedconfig.sh b/eclass/tests/savedconfig.sh new file mode 100755 index 000000000000..19da181d8404 --- /dev/null +++ b/eclass/tests/savedconfig.sh @@ -0,0 +1,78 @@ +#!/bin/bash +# Copyright 1999-2015 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +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 diff --git a/eclass/tests/scons-utils.sh b/eclass/tests/scons-utils.sh new file mode 100755 index 000000000000..7a588863c6a9 --- /dev/null +++ b/eclass/tests/scons-utils.sh @@ -0,0 +1,62 @@ +#!/bin/bash +# Copyright 1999-2015 Gentoo Foundation +# 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=$(_scons_get_default_jobs) +# 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 diff --git a/eclass/tests/tests-common.sh b/eclass/tests/tests-common.sh new file mode 100644 index 000000000000..d52cf3a2687b --- /dev/null +++ b/eclass/tests/tests-common.sh @@ -0,0 +1,105 @@ +#!/bin/bash +# Copyright 1999-2015 Gentoo Foundation +# 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 diff --git a/eclass/tests/toolchain-funcs.sh b/eclass/tests/toolchain-funcs.sh new file mode 100755 index 000000000000..bcf57f78201a --- /dev/null +++ b/eclass/tests/toolchain-funcs.sh @@ -0,0 +1,175 @@ +#!/bin/bash +# Copyright 1999-2015 Gentoo Foundation +# 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 +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 (bfd selected)" +LD=ld.bfd tc-ld-is-gold && ret=1 || ret=0 +tend ${ret} + +tbegin "tc-ld-is-gold (gold selected)" +LD=ld.gold tc-ld-is-gold +ret=$? +tend ${ret} + +tbegin "tc-ld-is-gold (bfd selected via flags)" +LD=ld.gold LDFLAGS=-fuse-ld=bfd tc-ld-is-gold +ret=$? +tend ${ret} + +tbegin "tc-ld-is-gold (gold selected via flags)" +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= +ewarn() { :; } +tc-ld-disable-gold +[[ ${LD} == "ld.bfd" && -z ${LDFLAGS} ]] +) +tend $? + +tbegin "tc-ld-disable-gold (gold selected)" +( +export LD=ld.gold LDFLAGS= +ewarn() { :; } +tc-ld-disable-gold +[[ ${LD} == "ld.bfd" || ${LDFLAGS} == *"-fuse-ld=bfd"* ]] +) +tend $? + +tbegin "tc-ld-disable-gold (gold selected via flags)" +( +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 + +texit diff --git a/eclass/tests/toolchain.sh b/eclass/tests/toolchain.sh new file mode 100755 index 000000000000..47401e687520 --- /dev/null +++ b/eclass/tests/toolchain.sh @@ -0,0 +1,82 @@ +#!/bin/bash +# Copyright 1999-2015 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +source tests-common.sh + +inherit toolchain + +test_downgrade_arch_flags() { + local exp msg ret=0 ver + + ver=${1} + exp=${2} + shift 2 + CFLAGS=${@} + + tbegin "${ver} ${CFLAGS} => ${exp}" + + CHOST=x86_64 # needed for tc-arch + downgrade_arch_flags ${ver} + + if [[ ${CFLAGS} != ${exp} ]]; then + msg="Failure - Expected: \"${exp}\" Got: \"${CFLAGS}\"" + ret=1 + fi + tend ${ret} ${msg} +} + +# ver expected given +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 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 4.2 "-march=native" "-march=native" +test_downgrade_arch_flags 4.1 "-march=nocona" "-march=native" + +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" +texit diff --git a/eclass/tests/versionator_version_compare.sh b/eclass/tests/versionator_version_compare.sh new file mode 100755 index 000000000000..c7a238cf9d1e --- /dev/null +++ b/eclass/tests/versionator_version_compare.sh @@ -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 |