Tests: Run detect/compile/release in a clean environment (#1016)

To prevent external environment variables from leaking into the tests,
which otherwise causes problems trying to write tests for #1011.

Several tests which were relying on this leak had to be fixed, so that
the env vars they were using are set using `ENV_DIR`, as happens in
production.

Fixes #1014.
Fixes #1015.
This commit is contained in:
Ed Morley
2020-07-24 18:10:11 +01:00
committed by GitHub
parent d9b1c73f63
commit a97da6382f
2 changed files with 20 additions and 11 deletions
+8 -3
View File
@@ -234,13 +234,18 @@ default_process_types_cleanup() {
fi
}
run_in_clean_env() {
# Prevent stray environment variables from outside the test runner being exposed to tests.
env -i HOME="${HOME}" LANG="${LANG}" PATH="${PATH}" STACK="${STACK}" "$@"
}
compile() {
default_process_types_cleanup
bp_dir=$(mktmpdir)
compile_dir=$(mktmpdir)
cp -a $(pwd)/* ${bp_dir}
cp -a ${bp_dir}/test/fixtures/$1/. ${compile_dir}
capture ${bp_dir}/bin/compile ${compile_dir} ${2:-$(mktmpdir)} $3
capture run_in_clean_env ${bp_dir}/bin/compile ${compile_dir} ${2:-$(mktmpdir)} $3
}
compileDir() {
@@ -252,13 +257,13 @@ compileDir() {
local env_dir=$3
cp -a $(pwd)/* ${bp_dir}
capture ${bp_dir}/bin/compile ${compile_dir} ${cache_dir} ${env_dir}
capture run_in_clean_env ${bp_dir}/bin/compile ${compile_dir} ${cache_dir} ${env_dir}
}
release() {
bp_dir=$(mktmpdir)
cp -a $(pwd)/* ${bp_dir}
capture ${bp_dir}/bin/release ${bp_dir}/test/fixtures/$1
capture run_in_clean_env ${bp_dir}/bin/release ${bp_dir}/test/fixtures/$1
}
assertFile() {