diff --git a/README.md b/README.md index c2d7ffc14..0598a7cfe 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ brew install node-build Upgrade with: ```sh -brew update && brew upgrade node-build +brew upgrade node-build ``` ### Clone as nodenv plugin using git diff --git a/bin/nodenv-install b/bin/nodenv-install index bf3dcf34d..32a952601 100755 --- a/bin/nodenv-install +++ b/bin/nodenv-install @@ -244,7 +244,7 @@ if [ "$STATUS" == "2" ]; then echo -n "If the version you need is missing, try upgrading node-build" if [ "$here" != "${here#$(brew --prefix 2>/dev/null)}" ]; then printf ":\\n\\n" - echo " brew update && brew upgrade node-build" + echo " brew upgrade node-build" elif [ -d "${here}/.git" ]; then printf ":\\n\\n" echo " git -C ${here} pull" diff --git a/test/build.bats b/test/build.bats index 780c4ff23..b62db2bd6 100755 --- a/test/build.bats +++ b/test/build.bats @@ -60,7 +60,6 @@ assert_build_log() { @test "apply node patch before building" { cached_tarball "node-v4.0.0" - stub brew false stub_make_install stub patch ' : echo patch "$@" | sed -E "s/\.[[:alnum:]]+$/.XXX/" >> build.log' @@ -85,7 +84,6 @@ OUT @test "striplevel node patch before building" { cached_tarball "node-v4.0.0" - stub brew false stub_make_install stub patch ' : echo patch "$@" | sed -E "s/\.[[:alnum:]]+$/.XXX/" >> build.log' @@ -110,7 +108,6 @@ OUT @test "apply node patch from git diff before building" { cached_tarball "node-v4.0.0" - stub brew false stub_make_install stub patch ' : echo patch "$@" | sed -E "s/\.[[:alnum:]]+$/.XXX/" >> build.log' @@ -136,7 +133,7 @@ OUT @test "number of CPU cores defaults to 2" { cached_tarball "node-v4.0.0" - stub uname '-s : echo Darwin' + stub_repeated uname '-s : echo Darwin' stub sysctl false stub_make_install @@ -159,7 +156,7 @@ OUT @test "number of CPU cores is detected on Mac" { cached_tarball "node-v4.0.0" - stub uname '-s : echo Darwin' + stub_repeated uname '-s : echo Darwin' stub sysctl '-n hw.ncpu : echo 4' stub_make_install @@ -183,7 +180,7 @@ OUT @test "number of CPU cores is detected on FreeBSD" { cached_tarball "node-v4.0.0" - stub uname '-s : echo FreeBSD' + stub_repeated uname '-s : echo FreeBSD' stub sysctl '-n hw.ncpu : echo 1' stub_make_install @@ -207,6 +204,7 @@ OUT @test "setting NODE_MAKE_INSTALL_OPTS to a multi-word string" { cached_tarball "node-v4.0.0" + stub_repeated uname '-s : echo Linux' stub_make_install export NODE_MAKE_INSTALL_OPTS="DOGE=\"such wow\"" @@ -227,6 +225,7 @@ OUT @test "setting MAKE_INSTALL_OPTS to a multi-word string" { cached_tarball "node-v4.0.0" + stub_repeated uname '-s : echo Linux' stub_make_install export MAKE_INSTALL_OPTS="DOGE=\"such wow\"" @@ -256,7 +255,7 @@ OUT @test "make on FreeBSD defaults to gmake" { cached_tarball "node-v4.0.0" - stub uname "-s : echo FreeBSD" + stub_repeated uname "-s : echo FreeBSD" MAKE=gmake stub_make_install MAKE= install_fixture definitions/vanilla-node @@ -275,6 +274,7 @@ apply -p1 -i /my/patch.diff exec ./configure "\$@" CONF + stub_repeated uname '-s : echo Linux' stub apply 'echo apply "$@" >> build.log' stub_make_install diff --git a/test/compiler.bats b/test/compiler.bats index 732105a5c..9bf287ca9 100755 --- a/test/compiler.bats +++ b/test/compiler.bats @@ -11,10 +11,8 @@ export -n NODE_CONFIGURE_OPTS mkdir -p "$INSTALL_ROOT" cd "$INSTALL_ROOT" - stub uname '-s : echo Darwin' '-s : echo Darwin' + stub_repeated uname '-s : echo Darwin' stub sw_vers '-productVersion : echo 10.10' - stub cc 'false' - stub brew 'false' stub make \ 'echo make $@' \ 'echo make $@' @@ -40,4 +38,8 @@ CFLAGS=no make -j 2 make install OUT + + unstub uname + unstub sw_vers + unstub make } diff --git a/test/nodenv.bats b/test/nodenv.bats index 84e102bef..e2dfd4401 100755 --- a/test/nodenv.bats +++ b/test/nodenv.bats @@ -82,7 +82,7 @@ OUT } @test "nonexistent version" { - stub brew false + stub_repeated brew false stub_node_build 'echo ERROR >&2 && exit 2' \ "--definitions : echo 0.8.7 0.10.4 0.10.6 1.0.0 4.1.2 | tr ' ' $'\\n'" @@ -102,6 +102,7 @@ If the version you need is missing, try upgrading node-build: git -C ${BATS_TEST_DIRNAME}/.. pull OUT + unstub brew unstub node-build } @@ -119,7 +120,7 @@ See all available versions with \`nodenv install --list'. If the version you need is missing, try upgrading node-build: - brew update && brew upgrade node-build + brew upgrade node-build OUT unstub brew diff --git a/test/stubs/stub b/test/stubs/stub deleted file mode 100755 index bd5c5d688..000000000 --- a/test/stubs/stub +++ /dev/null @@ -1,109 +0,0 @@ -#!/usr/bin/env bash -set -e - -status=0 -program="${0##*/}" -PROGRAM="$(echo "$program" | tr a-z- A-Z_)" -[ -n "$TMPDIR" ] || TMPDIR="/tmp" - -_STUB_PLAN="${PROGRAM}_STUB_PLAN" -_STUB_RUN="${PROGRAM}_STUB_RUN" -_STUB_INDEX="${PROGRAM}_STUB_INDEX" -_STUB_RESULT="${PROGRAM}_STUB_RESULT" -_STUB_END="${PROGRAM}_STUB_END" -_STUB_DEBUG="${PROGRAM}_STUB_DEBUG" - -if [ -n "${!_STUB_DEBUG}" ]; then - echo "$program" "$@" >&${!_STUB_DEBUG} -fi - -[ -e "${!_STUB_PLAN}" ] || exit 1 -[ -n "${!_STUB_RUN}" ] || eval "${_STUB_RUN}"="${TMPDIR}/${program}-stub-run" - - -# Initialize or load the stub run information. -eval "${_STUB_INDEX}"=1 -eval "${_STUB_RESULT}"=0 -[ ! -e "${!_STUB_RUN}" ] || source "${!_STUB_RUN}" - - -# Loop over each line in the plan. -index=0 -while IFS= read -r line; do - index=$(($index + 1)) - - if [ -z "${!_STUB_END}" ] && [ $index -eq "${!_STUB_INDEX}" ]; then - # We found the plan line we're interested in. - # Start off by assuming success. - result=0 - - # Split the line into an array of arguments to - # match and a command to run to produce output. - command=" $line" - if [ "$command" != "${command/ : }" ]; then - patterns="${command%% : *}" - command="${command#* : }" - fi - - # Naively split patterns by whitespace for now. - # In the future, use a sed script to split while - # respecting quoting. - set -f - patterns=($patterns) - set +f - arguments=("$@") - - # Match the expected argument patterns to actual - # arguments. - for (( i=0; i<${#patterns[@]}; i++ )); do - pattern="${patterns[$i]}" - argument="${arguments[$i]}" - - case "$argument" in - $pattern ) ;; - * ) result=1 ;; - esac - done - - # If the arguments matched, evaluate the command - # in a subshell. Otherwise, log the failure. - if [ $result -eq 0 ] ; then - set +e - ( eval "$command" ) - status="$?" - set -e - else - eval "${_STUB_RESULT}"=1 - fi - fi -done < "${!_STUB_PLAN}" - - -if [ -n "${!_STUB_END}" ]; then - # Clean up the run file. - rm -f "${!_STUB_RUN}" - - # If the number of lines in the plan is larger than - # the requested index, we failed. - if [ $index -ge "${!_STUB_INDEX}" ]; then - eval "${_STUB_RESULT}"=1 - fi - - # Return the result. - exit "${!_STUB_RESULT}" - -else - # If the requested index is larger than the number - # of lines in the plan file, we failed. - if [ "${!_STUB_INDEX}" -gt $index ]; then - eval "${_STUB_RESULT}"=1 - fi - - # Write out the run information. - { echo "${_STUB_INDEX}=$((${!_STUB_INDEX} + 1))" - echo "${_STUB_RESULT}=${!_STUB_RESULT}" - } > "${!_STUB_RUN}" - - exit "$status" - -fi diff --git a/test/test_helper.bash b/test/test_helper.bash index d6c3cf31d..b47f0e6b1 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -41,6 +41,14 @@ teardown() { rm -fr "${BATS_TMPDIR:?}"/* } +stub_repeated() { + local program="$1" + # shellcheck disable=SC2155 + local prefix="$(echo "$program" | tr a-z- A-Z_)" + export "${prefix}_STUB_NOINDEX"=1 + stub "$@" +} + run_inline_definition() { local definition="${BATS_TMPDIR}/build-definition" cat > "$definition"