summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlrich Müller <ulm@gentoo.org>2024-06-13 20:29:44 +0200
committerUlrich Müller <ulm@gentoo.org>2024-06-13 20:35:30 +0200
commitba67b6e7fd84fff922569627003bb3ae326c7f41 (patch)
tree4c0fd91120579dad024fbb4209bd4a9f896bcb29 /eclass/tests
parentapp-shells/bash: Stabilize 5.1_p16-r10 amd64, #934174 (diff)
downloadgentoo-ba67b6e7fd84fff922569627003bb3ae326c7f41.tar.gz
gentoo-ba67b6e7fd84fff922569627003bb3ae326c7f41.tar.bz2
gentoo-ba67b6e7fd84fff922569627003bb3ae326c7f41.zip
eclass/tests: Rename test function in savedconfig.sh
Overriding a shell builtin command is generally a very bad idea, especially when that command is used in code that is sourced (in this case, /lib/gentoo/functions.sh). Therefore, rename test() to test_sc(). Also make sure that the directories that are used as targets for rm -rf in cleanup() are actually different from the root directory. Signed-off-by: Ulrich Müller <ulm@gentoo.org>
Diffstat (limited to 'eclass/tests')
-rwxr-xr-xeclass/tests/savedconfig.sh22
1 files changed, 14 insertions, 8 deletions
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