diff options
Diffstat (limited to 'eclass/tests')
-rw-r--r-- | eclass/tests/Makefile | 8 | ||||
-rwxr-xr-x | eclass/tests/cargo-bench.sh | 4 | ||||
-rwxr-xr-x | eclass/tests/dist-kernel-utils.sh | 65 | ||||
-rwxr-xr-x | eclass/tests/eapi7-ver.sh | 177 | ||||
-rwxr-xr-x | eclass/tests/eapi7-ver_benchmark.sh | 147 | ||||
-rwxr-xr-x | eclass/tests/git-r3.sh | 208 | ||||
-rwxr-xr-x | eclass/tests/linux-info_get_running_version.sh | 12 | ||||
-rwxr-xr-x | eclass/tests/llvm-r1.sh | 26 | ||||
-rwxr-xr-x | eclass/tests/pypi-bench.sh | 4 | ||||
-rwxr-xr-x | eclass/tests/python-utils-bench.sh | 4 | ||||
-rwxr-xr-x | eclass/tests/python-utils-r1.sh | 14 | ||||
-rwxr-xr-x | eclass/tests/rebar_fix_include_path.sh | 8 | ||||
-rwxr-xr-x | eclass/tests/rebar_remove_deps.sh | 4 | ||||
-rwxr-xr-x | eclass/tests/rebar_set_vsn.sh | 4 | ||||
-rwxr-xr-x | eclass/tests/savedconfig.sh | 22 | ||||
-rw-r--r-- | eclass/tests/tests-common.sh | 2 | ||||
-rwxr-xr-x | eclass/tests/toolchain-funcs.sh | 44 | ||||
-rwxr-xr-x | eclass/tests/toolchain.sh | 21 | ||||
-rwxr-xr-x | eclass/tests/version-funcs.sh | 476 | ||||
-rwxr-xr-x | eclass/tests/versionator_version_compare.sh | 199 |
20 files changed, 653 insertions, 796 deletions
diff --git a/eclass/tests/Makefile b/eclass/tests/Makefile index ee4a454912c3..23027aed6b66 100644 --- a/eclass/tests/Makefile +++ b/eclass/tests/Makefile @@ -2,18 +2,20 @@ SH_FILES := $(wildcard *.sh) TEST_FILES := $(filter-out tests-common.sh, $(SH_FILES)) TEST_OK_FILES := $(patsubst %.sh, .%.sh.ok,$ $(TEST_FILES)) +# !!! _All_ recipe lines for each target will be provided to a single +# !!! invocation of the shell. +.ONESHELL: + # We cache a successful test result if the testfile itself did not # change (%.sh) and the contents of the eclass/ directory did not # change (.eclasssum). .%.sh.ok: %.sh .eclasssum - ./$< - touch $@ + ./$< && touch $@ .PHONY: test test: $(TEST_OK_FILES) .PHONY: force -.ONESHELL: .eclasssum: SHELL = /bin/bash .eclasssum: force set -euo pipefail diff --git a/eclass/tests/cargo-bench.sh b/eclass/tests/cargo-bench.sh index d30b04569905..9347fe339c12 100755 --- a/eclass/tests/cargo-bench.sh +++ b/eclass/tests/cargo-bench.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright 2023 Gentoo Authors +# Copyright 2023-2024 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 EAPI=8 @@ -39,7 +39,7 @@ timeit() { local xr avg for x in real user; do xr="${x}[*]" - avg=$(dc -S 3 -e "${ITERATIONS} ${RUNS} * ${!xr} + + / p") + avg=$(dc -e "3 k ${ITERATIONS} ${RUNS} * ${!xr} + + / p") printf '%s %4.0f it/s\n' "${x}" "${avg}" done diff --git a/eclass/tests/dist-kernel-utils.sh b/eclass/tests/dist-kernel-utils.sh index 7f04f55ce302..28c8f7213a53 100755 --- a/eclass/tests/dist-kernel-utils.sh +++ b/eclass/tests/dist-kernel-utils.sh @@ -1,14 +1,14 @@ #!/usr/bin/env bash -# Copyright 2022 Gentoo Authors +# Copyright 2022-2024 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 EAPI=8 source tests-common.sh || exit +# TODO: hack because tests-common don't implement ver_cut +source version-funcs.sh || exit inherit dist-kernel-utils -# TODO: hack because tests-common don't implement ver_cut -EAPI=6 inherit eapi7-ver test_PV_to_KV() { local kv=${1} @@ -20,9 +20,68 @@ test_PV_to_KV() { tend $? } +test_compressed_module_cleanup() { + mkdir -p "${tmpdir}/source" || die + pushd "${tmpdir}" >/dev/null || die + + local module option fail=0 + for option in NONE GZIP XZ ZSTD; do + tbegin "CONFIG_MODULE_COMPRESS_${option}" + echo "CONFIG_MODULE_COMPRESS_${option}=y" > source/.config + + touch a.ko b.ko.gz c.ko.xz d.ko.gz e.ko f.ko.xz || die + # ensure some files are older + touch -d "2 hours ago" d.ko e.ko.xz f.ko.gz || die + + IUSE=modules-compress dist-kernel_compressed_module_cleanup . + + local to_keep=( a.ko b.ko.gz c.ko.xz ) + local to_remove=() + + case ${option} in + NONE) + to_keep+=( d.ko e.ko f.ko.xz ) + to_remove+=( d.ko.gz e.ko.xz f.ko.gz ) + ;; + GZIP) + to_keep+=( d.ko.gz e.ko f.ko.gz ) + to_remove+=( d.ko e.ko.xz f.ko.xz ) + ;; + XZ) + to_keep+=( d.ko.gz e.ko.xz f.ko.xz ) + to_remove+=( d.ko e.ko f.ko.gz ) + ;; + ZSTD) + to_keep+=( d.ko.gz e.ko f.ko.xz ) + to_remove+=( d.ko e.ko.xz f.ko.gz ) + ;; + esac + + for module in "${to_keep[@]}"; do + if [[ ! -f ${module} ]]; then + eerror "Module ${module} was removed" + fail=1 + fi + done + + for module in "${to_remove[@]}"; do + if [[ -f ${module} ]]; then + eerror "Module ${module} was not removed" + fail=1 + fi + done + tend ${fail} + done + + popd >/dev/null || die +} + + test_PV_to_KV 6.0_rc1 6.0.0-rc1 test_PV_to_KV 6.0 6.0.0 test_PV_to_KV 6.0.1_rc1 6.0.1-rc1 test_PV_to_KV 6.0.1 6.0.1 +test_compressed_module_cleanup + texit diff --git a/eclass/tests/eapi7-ver.sh b/eclass/tests/eapi7-ver.sh deleted file mode 100755 index 13cd671e7158..000000000000 --- a/eclass/tests/eapi7-ver.sh +++ /dev/null @@ -1,177 +0,0 @@ -#!/bin/bash -# Copyright 1999-2017 Gentoo Foundation -# Distributed under the terms of the GNU General Public License v2 - -EAPI=6 - -source tests-common.sh || exit - -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 deleted file mode 100755 index ab324edb95c9..000000000000 --- a/eclass/tests/eapi7-ver_benchmark.sh +++ /dev/null @@ -1,147 +0,0 @@ -#!/bin/bash -# Copyright 1999-2017 Gentoo Foundation -# Distributed under the terms of the GNU General Public License v2 - -EAPI=6 - -source tests-common.sh || exit - -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/git-r3.sh b/eclass/tests/git-r3.sh deleted file mode 100755 index 02cbcbc59125..000000000000 --- a/eclass/tests/git-r3.sh +++ /dev/null @@ -1,208 +0,0 @@ -#!/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 || exit - -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/linux-info_get_running_version.sh b/eclass/tests/linux-info_get_running_version.sh index 57aaf2fedcd4..b8ae8c4b85ae 100755 --- a/eclass/tests/linux-info_get_running_version.sh +++ b/eclass/tests/linux-info_get_running_version.sh @@ -1,12 +1,20 @@ #!/bin/bash -# Copyright 1999-2021 Gentoo Authors +# Copyright 1999-2024 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 -EAPI=6 +EAPI=8 source tests-common.sh || exit +source version-funcs.sh || exit inherit linux-info +use() { + case $1 in + kernel_linux) return 0 ;; + esac + die "${FUNCNAME[0]}: unknown flag" +} + test_get_running_version() { local test_kv=$1 major=$2 minor=$3 patch=$4 extra=$5 tbegin "get_running_version ${test_kv}" diff --git a/eclass/tests/llvm-r1.sh b/eclass/tests/llvm-r1.sh index 9958f5bba420..8583fd6c799b 100755 --- a/eclass/tests/llvm-r1.sh +++ b/eclass/tests/llvm-r1.sh @@ -121,22 +121,30 @@ test_fix_tool_path() { tend ${?} } +# full range +test_globals '14 15 16 17 18 19' \ + "+llvm_slot_18 llvm_slot_15 llvm_slot_16 llvm_slot_17 llvm_slot_19" \ + "^^ ( llvm_slot_15 llvm_slot_16 llvm_slot_17 llvm_slot_18 llvm_slot_19 )" \ + "llvm_slot_15(-)?,llvm_slot_16(-)?,llvm_slot_17(-)?,llvm_slot_18(-)?,llvm_slot_19(-)?" test_globals '14 15 16 17 18' \ - "+llvm_slot_17 llvm_slot_15 llvm_slot_16 llvm_slot_18" \ + "+llvm_slot_18 llvm_slot_15 llvm_slot_16 llvm_slot_17" \ "^^ ( llvm_slot_15 llvm_slot_16 llvm_slot_17 llvm_slot_18 )" \ "llvm_slot_15(-)?,llvm_slot_16(-)?,llvm_slot_17(-)?,llvm_slot_18(-)?" +# older than stable test_globals '14 15 16' \ "+llvm_slot_16 llvm_slot_15" \ "^^ ( llvm_slot_15 llvm_slot_16 )" \ "llvm_slot_15(-)?,llvm_slot_16(-)?" -test_globals '15 18' \ - "+llvm_slot_15 llvm_slot_18" \ - "^^ ( llvm_slot_15 llvm_slot_18 )" \ - "llvm_slot_15(-)?,llvm_slot_18(-)?" -test_globals '18' \ - "+llvm_slot_18" \ - "^^ ( llvm_slot_18 )" \ - "llvm_slot_18(-)?" +# old + newer than current stable +test_globals '15 19' \ + "+llvm_slot_15 llvm_slot_19" \ + "^^ ( llvm_slot_15 llvm_slot_19 )" \ + "llvm_slot_15(-)?,llvm_slot_19(-)?" +# newer than current stable +test_globals '19' \ + "+llvm_slot_19" \ + "^^ ( llvm_slot_19 )" \ + "llvm_slot_19(-)?" LLVM_COMPAT=( {14..18} ) inherit llvm-r1 diff --git a/eclass/tests/pypi-bench.sh b/eclass/tests/pypi-bench.sh index cce93527b729..02855563db3f 100755 --- a/eclass/tests/pypi-bench.sh +++ b/eclass/tests/pypi-bench.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright 2023 Gentoo Authors +# Copyright 2023-2024 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 EAPI=8 @@ -39,7 +39,7 @@ timeit() { local xr avg for x in real user; do xr="${x}[*]" - avg=$(dc -S 3 -e "${ITERATIONS} ${RUNS} * ${!xr} + + / p") + avg=$(dc -e "3 k ${ITERATIONS} ${RUNS} * ${!xr} + + / p") printf '%s %4.0f it/s\n' "${x}" "${avg}" done diff --git a/eclass/tests/python-utils-bench.sh b/eclass/tests/python-utils-bench.sh index 7f27adef5509..f718b9f125cb 100755 --- a/eclass/tests/python-utils-bench.sh +++ b/eclass/tests/python-utils-bench.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright 2023 Gentoo Authors +# Copyright 2023-2024 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 EAPI=8 @@ -38,7 +38,7 @@ timeit() { local xr avg for x in real user; do xr="${x}[*]" - avg=$(dc -S 3 -e "${ITERATIONS} ${RUNS} * ${!xr} + + / p") + avg=$(dc -e "3 k ${ITERATIONS} ${RUNS} * ${!xr} + + / p") printf '%s %4.0f it/s\n' "${x}" "${avg}" done diff --git a/eclass/tests/python-utils-r1.sh b/eclass/tests/python-utils-r1.sh index 93cea324a3df..732f53381b22 100755 --- a/eclass/tests/python-utils-r1.sh +++ b/eclass/tests/python-utils-r1.sh @@ -64,7 +64,7 @@ tmpfile=$(mktemp) inherit python-utils-r1 -for minor in {10..13}; do +for minor in {10..13} 13t; do ebegin "Testing python3.${minor}" eindent test_var EPYTHON "python3_${minor}" "python3.${minor}" @@ -72,9 +72,9 @@ for minor in {10..13}; do if [[ -x /usr/bin/python3.${minor} ]]; then abiflags=$(/usr/bin/python3.${minor} -c 'import sysconfig; print(sysconfig.get_config_var("ABIFLAGS"))') test_var PYTHON_SITEDIR "python3_${minor}" "/usr/lib*/python3.${minor}/site-packages" - test_var PYTHON_INCLUDEDIR "python3_${minor}" "/usr/include/python3.${minor}${abiflags}" - test_var PYTHON_LIBPATH "python3_${minor}" "/usr/lib*/libpython3.${minor}${abiflags}$(get_libname)" - test_var PYTHON_CONFIG "python3_${minor}" "/usr/bin/python3.${minor}${abiflags}-config" + test_var PYTHON_INCLUDEDIR "python3_${minor}" "/usr/include/python3.${minor%t}${abiflags}" + test_var PYTHON_LIBPATH "python3_${minor}" "/usr/lib*/libpython3.${minor%t}${abiflags}$(get_libname)" + test_var PYTHON_CONFIG "python3_${minor}" "/usr/bin/python3.${minor%t}${abiflags}-config" test_var PYTHON_CFLAGS "python3_${minor}" "*-I/usr/include/python3.${minor}*" test_var PYTHON_LIBS "python3_${minor}" "*-lpython3.${minor}*" fi @@ -105,13 +105,13 @@ for minor in {10..13}; do tend ${?} # these tests apply to py3.8+ only - if [[ ${minor} -ge 8 ]]; then + if [[ ${minor%t} -ge 8 ]]; then tbegin "Testing that _python_verify_patterns accepts stdlib version" - ( _python_verify_patterns "3.${minor}" ) + ( _python_verify_patterns "3.${minor%t}" ) tend ${?} tbegin "Testing _python_impl_matches on stdlib version" - _python_impl_matches "python3_${minor}" "3.${minor}" + _python_impl_matches "python3_${minor}" "3.${minor%t}" tend ${?} fi diff --git a/eclass/tests/rebar_fix_include_path.sh b/eclass/tests/rebar_fix_include_path.sh index 339633e91e3a..46c5712104b1 100755 --- a/eclass/tests/rebar_fix_include_path.sh +++ b/eclass/tests/rebar_fix_include_path.sh @@ -1,16 +1,20 @@ #!/bin/bash -# Copyright 1999-2016 Gentoo Foundation +# Copyright 1999-2024 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 source tests-common.sh || exit -EAPI=6 +EAPI=8 inherit rebar EPREFIX="${tmpdir}/fakeroot" S="${WORKDIR}/${P}" +get_libdir() { + echo lib +} + setup() { mkdir -p "${S}" || die diff --git a/eclass/tests/rebar_remove_deps.sh b/eclass/tests/rebar_remove_deps.sh index b544a3078dbb..e2717b59eaf9 100755 --- a/eclass/tests/rebar_remove_deps.sh +++ b/eclass/tests/rebar_remove_deps.sh @@ -1,10 +1,10 @@ #!/bin/bash -# Copyright 1999-2016 Gentoo Foundation +# Copyright 1999-2024 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 source tests-common.sh || exit -EAPI=6 +EAPI=8 inherit rebar diff --git a/eclass/tests/rebar_set_vsn.sh b/eclass/tests/rebar_set_vsn.sh index c828732b0079..6cc4600695a6 100755 --- a/eclass/tests/rebar_set_vsn.sh +++ b/eclass/tests/rebar_set_vsn.sh @@ -1,10 +1,10 @@ #!/bin/bash -# Copyright 1999-2016 Gentoo Foundation +# Copyright 1999-2024 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 source tests-common.sh || exit -EAPI=6 +EAPI=8 inherit rebar diff --git a/eclass/tests/savedconfig.sh b/eclass/tests/savedconfig.sh index 16645fc05854..ad03ce2d2d94 100755 --- a/eclass/tests/savedconfig.sh +++ b/eclass/tests/savedconfig.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright 1999-2019 Gentoo Authors +# Copyright 1999-2024 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 EAPI=7 @@ -18,7 +18,13 @@ quiet() { sc() { EBUILD_PHASE=install quiet save_config "$@" ; } rc() { EBUILD_PHASE=prepare quiet restore_config "$@" ; } -cleanup() { rm -rf "${ED}"/* "${T}"/* "${WORKDIR}"/* ; } +cleanup() { + # make sure that these variables exist + [[ -n ${ED} && -n ${T} && -n ${WORKDIR} ]] \ + || { die "${FUNCNAME[0]}: undefined variable"; exit 1; } + rm -rf "${ED}"/* "${T}"/* "${WORKDIR}"/* +} + test-it() { local ret=0 tbegin "$@" @@ -26,7 +32,7 @@ test-it() { : $(( ret |= $? )) pushd "${WORKDIR}" >/dev/null : $(( ret |= $? )) - test + test_sc : $(( ret |= $? )) popd >/dev/null : $(( ret |= $? )) @@ -34,21 +40,21 @@ test-it() { cleanup } -test() { +test_sc() { touch f || return 1 sc f || return 1 [[ -f ${ED}/etc/portage/savedconfig/${CATEGORY}/${PF} ]] } test-it "simple save_config" -test() { +test_sc() { 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() { +test_sc() { mkdir dir || return 1 touch dir/{a,b,c} || return 1 sc dir || return 1 @@ -58,14 +64,14 @@ test-it "dir save_config" PORTAGE_CONFIGROOT=${D} -test() { +test_sc() { echo "ggg" > f || return 1 rc f || return 1 [[ $(<f) == "ggg" ]] } test-it "simple restore_config" -test() { +test_sc() { echo "ggg" > f || return 1 rc f || return 1 [[ $(<f) == "ggg" ]] || return 1 diff --git a/eclass/tests/tests-common.sh b/eclass/tests/tests-common.sh index 45b1e20b933a..f4e18f38fee9 100644 --- a/eclass/tests/tests-common.sh +++ b/eclass/tests/tests-common.sh @@ -55,6 +55,8 @@ has() { } use() { has "$1" ${IUSE} ; } +in_iuse() { use "$@" ; } + die() { echo "die: $*" 1>&2 exit 1 diff --git a/eclass/tests/toolchain-funcs.sh b/eclass/tests/toolchain-funcs.sh index 08cfd74611aa..0d6745862148 100755 --- a/eclass/tests/toolchain-funcs.sh +++ b/eclass/tests/toolchain-funcs.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright 1999-2021 Gentoo Authors +# Copyright 1999-2024 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 EAPI=7 @@ -28,7 +28,7 @@ test-tc-arch-kernel() { 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 \ + powerpc{,64}:powerpc \ or1k:openrisc or1k-linux-musl:openrisc tend $? @@ -210,6 +210,36 @@ if type -P gcc &>/dev/null; then tbegin "tc-get-c-rtlib (gcc)" [[ $(CC=gcc tc-get-c-rtlib) == libgcc ]] tend $? + + tbegin "tc-is-lto (gcc, -fno-lto)" + CC=gcc CFLAGS=-fno-lto tc-is-lto + [[ $? -eq 1 ]] + tend $? + + tbegin "tc-is-lto (gcc, -flto)" + CC=gcc CFLAGS=-flto tc-is-lto + [[ $? -eq 0 ]] + tend $? + + case $(gcc -dumpmachine) in + i*86*-gnu*|arm*-gnu*|powerpc-*-gnu) + tbegin "tc-has-64bit-time_t (_TIME_BITS=32)" + CC=gcc CFLAGS="-U_TIME_BITS -D_TIME_BITS=32" tc-has-64bit-time_t + [[ $? -eq 1 ]] + tend $? + + tbegin "tc-has-64bit-time_t (_TIME_BITS=64)" + CC=gcc CFLAGS="-U_FILE_OFFSET_BITS -U_TIME_BITS -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64" tc-has-64bit-time_t + [[ $? -eq 0 ]] + tend $? + ;; + *) + tbegin "tc-has-64bit-time_t" + CC=gcc tc-has-64bit-time_t + [[ $? -eq 0 ]] + tend $? + ;; + esac fi if type -P clang &>/dev/null; then @@ -232,6 +262,16 @@ if type -P clang &>/dev/null; then [[ $(CC=clang CFLAGS="--rtlib=${rtlib}" tc-get-c-rtlib) == ${rtlib} ]] tend $? done + + tbegin "tc-is-lto (clang, -fno-lto)" + CC=clang CFLAGS=-fno-lto tc-is-lto + [[ $? -eq 1 ]] + tend $? + + tbegin "tc-is-lto (clang, -flto)" + CC=clang CFLAGS=-flto tc-is-lto + [[ $? -eq 0 ]] + tend $? fi texit diff --git a/eclass/tests/toolchain.sh b/eclass/tests/toolchain.sh index 1f21e7d842b1..1ba2e6b1f29d 100755 --- a/eclass/tests/toolchain.sh +++ b/eclass/tests/toolchain.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright 1999-2023 Gentoo Authors +# Copyright 1999-2024 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 EAPI=8 @@ -9,8 +9,8 @@ TOOLCHAIN_GCC_PV=11.3.0 PR=r0 source tests-common.sh || exit +source version-funcs.sh || exit -EAPI=6 inherit eapi7-ver EAPI=7 inherit toolchain # Ignore actually running version of gcc and fake new version @@ -49,10 +49,6 @@ 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" @@ -62,31 +58,18 @@ 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 9 "-march=znver2" "-march=znver3" 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" diff --git a/eclass/tests/version-funcs.sh b/eclass/tests/version-funcs.sh new file mode 100755 index 000000000000..cb2a92342c65 --- /dev/null +++ b/eclass/tests/version-funcs.sh @@ -0,0 +1,476 @@ +#!/bin/bash +# Copyright 1999-2024 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +# @ECLASS: eapi7-ver.eclass +# @MAINTAINER: +# PMS team <pms@gentoo.org> +# @AUTHOR: +# Ulrich Müller <ulm@gentoo.org> +# Michał Górny <mgorny@gentoo.org> +# @BLURB: Testing implementation of EAPI 7 version manipulators +# @DESCRIPTION: +# A stand-alone implementation of the version manipulation functions +# aimed for EAPI 7. Intended to be used for wider testing of +# the proposed functions and to allow ebuilds to switch to the new +# model early, with minimal change needed for actual EAPI 7. +# +# https://bugs.gentoo.org/482170 +# +# @SUBSECTION Version strings +# +# The functions support arbitrary version strings consisting of version +# components interspersed with (possibly empty) version separators. +# +# A version component can either consist purely of digits ([0-9]+) +# or purely of uppercase and lowercase letters ([A-Za-z]+). A version +# separator is either a string of any other characters ([^A-Za-z0-9]+), +# or it occurs at the transition between a sequence of letters +# and a sequence of digits, or vice versa. In the latter case, +# the version separator is an empty string. +# +# The version is processed left-to-right, and each successive component +# is assigned numbers starting with 1. The components are either split +# on version separators or on boundaries between digits and letters +# (in which case the separator between the components is empty). +# Version separators are assigned numbers starting with 1 for +# the separator between 1st and 2nd components. As a special case, +# if the version string starts with a separator, it is assigned index 0. +# +# Examples: +# +# @CODE +# 1.2b-alpha4 -> 1 . 2 '' b - alpha '' 4 +# c s c s c s c s c +# 1 1 2 2 3 3 4 4 5 +# +# .11. -> . 11 . +# s c s +# 0 1 1 +# @CODE +# +# @SUBSECTION Ranges +# +# A range can be specified as 'm' for m-th version component, 'm-' +# for all components starting with m-th or 'm-n' for components starting +# at m-th and ending at n-th (inclusive). If the range spans outside +# the version string, it is truncated silently. + +# @FUNCTION: _ver_parse_range +# @USAGE: <range> <max> +# @INTERNAL +# @DESCRIPTION: +# Parse the range string <range>, setting 'start' and 'end' variables +# to the appropriate bounds. <max> specifies the appropriate upper +# bound for the range; the user-specified value is truncated to this. +_ver_parse_range() { + local range=${1} + local max=${2} + + [[ ${range} == [0-9]* ]] \ + || die "${FUNCNAME}: range must start with a number" + start=${range%-*} + [[ ${range} == *-* ]] && end=${range#*-} || end=${start} + if [[ ${end} ]]; then + [[ ${start} -le ${end} ]] \ + || die "${FUNCNAME}: end of range must be >= start" + [[ ${end} -le ${max} ]] || end=${max} + else + end=${max} + fi +} + +# @FUNCTION: _ver_split +# @USAGE: <version> +# @INTERNAL +# @DESCRIPTION: +# Split the version string <version> into separator-component array. +# Sets 'comp' to an array of the form: ( s_0 c_1 s_1 c_2 s_2 c_3... ) +# where s_i are separators and c_i are components. +_ver_split() { + local v=${1} LC_ALL=C + + comp=() + + # get separators and components + local s c + while [[ ${v} ]]; do + # cut the separator + s=${v%%[a-zA-Z0-9]*} + v=${v:${#s}} + # cut the next component; it can be either digits or letters + [[ ${v} == [0-9]* ]] && c=${v%%[^0-9]*} || c=${v%%[^a-zA-Z]*} + v=${v:${#c}} + + comp+=( "${s}" "${c}" ) + done +} + +# @FUNCTION: ver_cut +# @USAGE: <range> [<version>] +# @DESCRIPTION: +# Print the substring of the version string containing components +# defined by the <range> and the version separators between them. +# Processes <version> if specified, ${PV} otherwise. +# +# For the syntax of versions and ranges, please see the eclass +# description. +ver_cut() { + local range=${1} + local v=${2:-${PV}} + local start end + local -a comp + + _ver_split "${v}" + local max=$((${#comp[@]}/2)) + _ver_parse_range "${range}" "${max}" + + if [[ ${start} -gt 0 ]]; then + start=$(( start*2 - 1 )) + fi + # Work around a bug in bash-3.2, where "${comp[*]:start:end*2-start}" + # inserts stray 0x7f characters for empty array elements + printf "%s" "${comp[@]:start:end*2-start}" $'\n' +} + +# @FUNCTION: ver_rs +# @USAGE: <range> <repl> [<range> <repl>...] [<version>] +# @DESCRIPTION: +# Print the version string after substituting the specified version +# separators at <range> with <repl> (string). Multiple '<range> <repl>' +# pairs can be specified. Processes <version> if specified, +# ${PV} otherwise. +# +# For the syntax of versions and ranges, please see the eclass +# description. +ver_rs() { + local v + (( ${#} & 1 )) && v=${@: -1} || v=${PV} + local start end i + local -a comp + + _ver_split "${v}" + local max=$((${#comp[@]}/2 - 1)) + + while [[ ${#} -ge 2 ]]; do + _ver_parse_range "${1}" "${max}" + for (( i = start*2; i <= end*2; i+=2 )); do + [[ ${i} -eq 0 && -z ${comp[i]} ]] && continue + comp[i]=${2} + done + shift 2 + done + + local IFS= + echo "${comp[*]}" +} + +# @FUNCTION: _ver_compare_int +# @USAGE: <a> <b> +# @RETURN: 0 if <a> -eq <b>, 1 if <a> -lt <b>, 3 if <a> -gt <b> +# @INTERNAL +# @DESCRIPTION: +# Compare two non-negative integers <a> and <b>, of arbitrary length. +# If <a> is equal to, less than, or greater than <b>, return 0, 1, or 3 +# as exit status, respectively. +_ver_compare_int() { + local a=$1 b=$2 d=$(( ${#1}-${#2} )) + + # Zero-pad to equal length if necessary. + if [[ ${d} -gt 0 ]]; then + printf -v b "%0${d}d%s" 0 "${b}" + elif [[ ${d} -lt 0 ]]; then + printf -v a "%0$(( -d ))d%s" 0 "${a}" + fi + + [[ ${a} > ${b} ]] && return 3 + [[ ${a} == "${b}" ]] +} + +# @FUNCTION: _ver_compare +# @USAGE: <va> <vb> +# @RETURN: 1 if <va> < <vb>, 2 if <va> = <vb>, 3 if <va> > <vb> +# @INTERNAL +# @DESCRIPTION: +# Compare two versions <va> and <vb>. If <va> is less than, equal to, +# or greater than <vb>, return 1, 2, or 3 as exit status, respectively. +_ver_compare() { + local va=${1} vb=${2} a an al as ar b bn bl bs br re LC_ALL=C + + re="^([0-9]+(\.[0-9]+)*)([a-z]?)((_(alpha|beta|pre|rc|p)[0-9]*)*)(-r[0-9]+)?$" + + [[ ${va} =~ ${re} ]] || die "${FUNCNAME}: invalid version: ${va}" + an=${BASH_REMATCH[1]} + al=${BASH_REMATCH[3]} + as=${BASH_REMATCH[4]} + ar=${BASH_REMATCH[7]} + + [[ ${vb} =~ ${re} ]] || die "${FUNCNAME}: invalid version: ${vb}" + bn=${BASH_REMATCH[1]} + bl=${BASH_REMATCH[3]} + bs=${BASH_REMATCH[4]} + br=${BASH_REMATCH[7]} + + # Compare numeric components (PMS algorithm 3.2) + # First component + _ver_compare_int "${an%%.*}" "${bn%%.*}" || return + + while [[ ${an} == *.* && ${bn} == *.* ]]; do + # Other components (PMS algorithm 3.3) + an=${an#*.} + bn=${bn#*.} + a=${an%%.*} + b=${bn%%.*} + if [[ ${a} == 0* || ${b} == 0* ]]; then + # Remove any trailing zeros + [[ ${a} =~ 0+$ ]] && a=${a%"${BASH_REMATCH[0]}"} + [[ ${b} =~ 0+$ ]] && b=${b%"${BASH_REMATCH[0]}"} + [[ ${a} > ${b} ]] && return 3 + [[ ${a} < ${b} ]] && return 1 + else + _ver_compare_int "${a}" "${b}" || return + fi + done + [[ ${an} == *.* ]] && return 3 + [[ ${bn} == *.* ]] && return 1 + + # Compare letter components (PMS algorithm 3.4) + [[ ${al} > ${bl} ]] && return 3 + [[ ${al} < ${bl} ]] && return 1 + + # Compare suffixes (PMS algorithm 3.5) + as=${as#_}${as:+_} + bs=${bs#_}${bs:+_} + while [[ -n ${as} && -n ${bs} ]]; do + # Compare each suffix (PMS algorithm 3.6) + a=${as%%_*} + b=${bs%%_*} + if [[ ${a%%[0-9]*} == "${b%%[0-9]*}" ]]; then + _ver_compare_int "${a##*[a-z]}" "${b##*[a-z]}" || return + else + # Check for p first + [[ ${a%%[0-9]*} == p ]] && return 3 + [[ ${b%%[0-9]*} == p ]] && return 1 + # Hack: Use that alpha < beta < pre < rc alphabetically + [[ ${a} > ${b} ]] && return 3 || return 1 + fi + as=${as#*_} + bs=${bs#*_} + done + if [[ -n ${as} ]]; then + [[ ${as} == p[_0-9]* ]] && return 3 || return 1 + elif [[ -n ${bs} ]]; then + [[ ${bs} == p[_0-9]* ]] && return 1 || return 3 + fi + + # Compare revision components (PMS algorithm 3.7) + _ver_compare_int "${ar#-r}" "${br#-r}" || return + + return 2 +} + +# @FUNCTION: ver_test +# @USAGE: [<v1>] <op> <v2> +# @DESCRIPTION: +# Check if the relation <v1> <op> <v2> is true. If <v1> is not specified, +# default to ${PVR}. <op> can be -gt, -ge, -eq, -ne, -le, -lt. +# Both versions must conform to the PMS version syntax (with optional +# revision parts), and the comparison is performed according to +# the algorithm specified in the PMS. +ver_test() { + local va op vb + + if [[ $# -eq 3 ]]; then + va=${1} + shift + else + va=${PVR} + fi + + [[ $# -eq 2 ]] || die "${FUNCNAME}: bad number of arguments" + + op=${1} + vb=${2} + + case ${op} in + -eq|-ne|-lt|-le|-gt|-ge) ;; + *) die "${FUNCNAME}: invalid operator: ${op}" ;; + esac + + _ver_compare "${va}" "${vb}" + test $? "${op}" 2 +} + +# Return if we are being sourced +return 2>/dev/null + + +source tests-common.sh || exit + +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/versionator_version_compare.sh b/eclass/tests/versionator_version_compare.sh deleted file mode 100755 index 2875c0f693da..000000000000 --- a/eclass/tests/versionator_version_compare.sh +++ /dev/null @@ -1,199 +0,0 @@ -#!/bin/bash -# Copyright 1999-2015 Gentoo Foundation -# Distributed under the terms of the GNU General Public License v2 - -source tests-common.sh || exit - -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 |