summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKerin Millar <kfm@plushkava.net>2024-08-07 23:00:36 +0100
committerSam James <sam@gentoo.org>2024-08-11 11:10:57 +0100
commit1c8a0a340de9b4e9b69e3e373bb8f55e2a1f030b (patch)
treeac151f74a7cee413af520e963d62d1a10c1bac12
parenttest-functions: avoid unspecified behaviour in test_quote_args() (diff)
downloadgentoo-functions-1c8a0a340de9b4e9b69e3e373bb8f55e2a1f030b.tar.gz
gentoo-functions-1c8a0a340de9b4e9b69e3e373bb8f55e2a1f030b.tar.bz2
gentoo-functions-1c8a0a340de9b4e9b69e3e373bb8f55e2a1f030b.zip
test-functions: test for simple commands persisting environmental changes
Some implementations allow for alterations made to the execution environment to persist beyond the scope of a simple command. Consider loksh as a case in point. $ f() { :; } $ unset LEAKED $ LEAKED=1 /bin/true; echo "LEAKED = $LEAKED" LEAKED = $ LEAKED=1 cmd2; echo "LEAKED = $LEAKED" LEAKED = 1 Strictly speaking, such behaviour is permitted. The Shell Command Language specification states: """ If the command name is a function that is not a standard utility implemented as a function, variable assignments shall affect the current execution environment during the execution of the function. It is unspecified: - Whether or not the variable assignments persist after the completion of the function - Whether or not the variables gain the export attribute during the execution of the function - Whether or not export attributes gained as a result of the variable assignments persist after the completion of the function (if variable assignments persist after the completion of the function) """ Unfortunately, loksh elects not to be aligned with the practices of the overwhelming majority of implementations in this regard. For now, have test-functions detect and abort for shells that go against the grain. I shall consider reviewing and adapting gentoo-functions to account for such unspecified behaviour but it is not an immediate priority. Signed-off-by: Kerin Millar <kfm@plushkava.net> Signed-off-by: Sam James <sam@gentoo.org>
-rwxr-xr-xtest-functions15
1 files changed, 14 insertions, 1 deletions
diff --git a/test-functions b/test-functions
index 487caa9..afc56eb 100755
--- a/test-functions
+++ b/test-functions
@@ -46,6 +46,19 @@ test_local() {
return "${retval}"
}
+test_simple_command() {
+ f() { :; }
+ LEAKED=
+ LEAKED=1 f
+ retval=0
+ if [ "${LEAKED}" ]; then
+ printf 'not '
+ retval=1
+ fi
+ printf "ok %d - /bin/sh refrains from leaking environmental changes for simple commands\\n" "$((testnum += 1))"
+ return "${retval}"
+}
+
test_chdir() {
set -- \
ge 1 '' \
@@ -1071,7 +1084,7 @@ if [ "${PORTAGE_BIN_PATH}" ] && [ "${S}" ]; then
genfun_basedir=${S}
fi
-if ! test_local; then
+if ! test_local || ! test_simple_command; then
rc=1
elif ! GENFUN_MODULES="portage rc" . ./functions.sh; then
bailout "Couldn't source ./functions.sh"