Skip to content
Myr

[tests] remove double-substitution in assert_ok and assert_not_ok

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Андрій Шовкошитний · committed by Jordan Harband · parent d200a21 · Browse files · 4 files+59 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: Андрій Шовкошитний <198119344+enlightened88@users.noreply.github.com>
  • Co-authored-by: Jordan Harband <ljharb@gmail.com>

Diff stats

4 files+59 added−3 removed

  • tests:+59 added−3 removed

4 files+59 added−3 removed

added:test/fast/Unit tests/assert_not_ok+17 added
1#!/bin/sh23die () { echo "$@" ; exit 1; }45\. ../../common.sh67_returns_zero() { return 0; }8_returns_nonzero() { return 1; }910# assert_not_ok should pass for a non-zero-exit function11assert_not_ok _returns_nonzero \12 || die 'assert_not_ok failed on a function that returns 1'1314# assert_not_ok should fail for a zero-exit function15if (assert_not_ok _returns_zero 2>/dev/null); then16 die 'assert_not_ok incorrectly passed for a function that returns 0'17fi
added:test/fast/Unit tests/assert_ok+17 added
1#!/bin/sh23die () { echo "$@" ; exit 1; }45\. ../../common.sh67_returns_zero() { return 0; }8_returns_nonzero() { return 1; }910# assert_ok should pass for a zero-exit function11assert_ok _returns_zero \12 || die 'assert_ok failed on a function that returns 0'1314# assert_ok should fail for a non-zero-exit function15if (assert_ok _returns_nonzero 2>/dev/null); then16 die 'assert_ok incorrectly passed for a function that returns 1'17fi
added:test/fast/Unit tests/make_echo+22 added
1#!/bin/sh23die () { echo "$@" ; exit 1; }45\. ../../common.sh67TMPFILE="$(mktemp)"8trap 'rm -f "${TMPFILE}"' EXIT910make_echo "${TMPFILE}" "hello_nvm" || die 'make_echo returned non-zero'1112# shebang must still be on line 113[ "$(head -n 1 "${TMPFILE}")" = '#!/bin/sh' ] \14 || die 'make_echo overwrote the shebang'1516# script body must be present17grep -q 'hello_nvm' "${TMPFILE}" \18 || die 'make_echo did not write the echo body'1920# file must be executable21[ -x "${TMPFILE}" ] \22 || die 'make_echo did not chmod the file'
modified:test/common.sh+3 added-3 removed
26 unmodified lines
27assert_ok() {28 local FUNCTION=$129 shift3031 $($FUNCTION $@) || die '"'"$FUNCTION $@"'" should have succeeded, but failed'31 "$FUNCTION" "$@" || die '"'"$FUNCTION $@"'" should have succeeded, but failed'32}3334assert_not_ok() {35 local FUNCTION=$136 shift3738 ! $($FUNCTION $@) || die '"'"$FUNCTION $@"'" should have failed, but succeeded'38 ! "$FUNCTION" "$@" || die '"'"$FUNCTION $@"'" should have failed, but succeeded'39}4041strip_colors() {42 while read -r line; do
2 unmodified lines
45}4647make_echo() {48 echo "#!/bin/sh" > "$1"49 echo "echo \"${2}\"" > "$1"49 echo "echo \"${2}\"" >> "$1"50 chmod a+x "$1"51}5253make_fake_node() {
220 unmodified lines