[tests] remove double-substitution in assert_ok and assert_not_ok

Co-authored-by: Андрій Шовкошитний <198119344+enlightened88@users.noreply.github.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
This commit is contained in:
Андрій Шовкошитний
2026-04-23 17:16:32 +03:00
committed by Jordan Harband
parent d200a21559
commit 20d52b6419
4 changed files with 59 additions and 3 deletions

View File

@@ -0,0 +1,17 @@
#!/bin/sh
die () { echo "$@" ; exit 1; }
\. ../../common.sh
_returns_zero() { return 0; }
_returns_nonzero() { return 1; }
# assert_not_ok should pass for a non-zero-exit function
assert_not_ok _returns_nonzero \
|| die 'assert_not_ok failed on a function that returns 1'
# assert_not_ok should fail for a zero-exit function
if (assert_not_ok _returns_zero 2>/dev/null); then
die 'assert_not_ok incorrectly passed for a function that returns 0'
fi

17
test/fast/Unit tests/assert_ok Executable file
View File

@@ -0,0 +1,17 @@
#!/bin/sh
die () { echo "$@" ; exit 1; }
\. ../../common.sh
_returns_zero() { return 0; }
_returns_nonzero() { return 1; }
# assert_ok should pass for a zero-exit function
assert_ok _returns_zero \
|| die 'assert_ok failed on a function that returns 0'
# assert_ok should fail for a non-zero-exit function
if (assert_ok _returns_nonzero 2>/dev/null); then
die 'assert_ok incorrectly passed for a function that returns 1'
fi

22
test/fast/Unit tests/make_echo Executable file
View File

@@ -0,0 +1,22 @@
#!/bin/sh
die () { echo "$@" ; exit 1; }
\. ../../common.sh
TMPFILE="$(mktemp)"
trap 'rm -f "${TMPFILE}"' EXIT
make_echo "${TMPFILE}" "hello_nvm" || die 'make_echo returned non-zero'
# shebang must still be on line 1
[ "$(head -n 1 "${TMPFILE}")" = '#!/bin/sh' ] \
|| die 'make_echo overwrote the shebang'
# script body must be present
grep -q 'hello_nvm' "${TMPFILE}" \
|| die 'make_echo did not write the echo body'
# file must be executable
[ -x "${TMPFILE}" ] \
|| die 'make_echo did not chmod the file'