[meta] Makefile: default NVM_DIR to the checkout when it is not set

The test suites source `nvm.sh` without setting `NVM_DIR` unless the caller exports it, which locally
(where `NVM_*` variables are unset first)
and in the `urchin tests` workflow it is not.
bash and zsh then detect the checkout from the sourced file,
but sh and dash have no way to locate a sourced file,
so they fell back to `dirname "$0"`,
which happened to be the test's own directory.

The `test-<shell>` targets now export `NVM_DIR` as the checkout when it is still unset,
so every shell runs the suites against the same `NVM_DIR`,
and an explicitly provided `NVM_DIR` is kept

Discovered by Anthropic's OSS Scanner, as ANT-2026-8RIT0MGO; the scanner reported it as a vulnerability, but it is not one.
This commit is contained in:
Jordan Harband committed 2026-10-23 08:53:59 -07:00
1 parent 8610e1578d
commit 3649f2b9a7
1 file changed
+2
+2
View File
@@ -38,12 +38,14 @@ list:
# Set of test-<shell> targets; each runs the specified test suites for a single shell.
# Note that preexisting NVM_* variables are unset to avoid interfering with tests, except when running the Travis tests (where NVM_DIR must be passed in and the env. is assumed to be pristine).
# NVM_DIR then defaults to this checkout when it is not set, since not every shell can locate a sourced nvm.sh.
.PHONY: $(SHELL_TARGETS)
$(SHELL_TARGETS):
@shell='$@'; shell=$${shell##*-}; \
which "$$shell" >/dev/null || { printf '\033[0;31m%s\033[0m\n' "WARNING: Cannot test with shell '$$shell': not found." >&2; exit 0; } && \
printf '\n\033[0;34m%s\033[0m\n' "Running tests in $$shell"; \
[ -z "$$TRAVIS_BUILD_DIR" ] && [ -z "$$GITHUB_ACTIONS" ] && for v in $$(set | awk -F'=' '$$1 ~ "^NVM_" { print $$1 }'); do unset $$v; done && unset v; \
[ -n "$${NVM_DIR-}" ] || export NVM_DIR="$$PWD"; \
for suite in $(TEST_SUITE); do \
echo "Running test suite: $$suite"; \
$(URCHIN) -f -s $$shell test/$$suite || exit; \