diff --git a/test/build.bats b/test/build.bats index 1629e030e2..2190238002 100755 --- a/test/build.bats +++ b/test/build.bats @@ -61,8 +61,8 @@ assert_build_log() { cached_tarball "yaml-0.1.6" cached_tarball "ruby-2.0.0" - stub uname '-s : echo Linux' - stub brew false + stub_repeated uname '-s : echo Linux' + stub_repeated brew false stub_make_install stub_make_install @@ -70,6 +70,7 @@ assert_build_log() { assert_success unstub uname + unstub brew unstub make assert_build_log <> build.log' @@ -100,6 +101,7 @@ PATCH assert_success unstub uname + unstub brew unstub make unstub patch @@ -118,8 +120,8 @@ OUT cached_tarball "yaml-0.1.6" cached_tarball "ruby-2.0.0" - stub uname '-s : echo Linux' - stub brew false + stub_repeated uname '-s : echo Linux' + stub_repeated brew false stub_make_install stub_make_install stub patch ' : echo patch "$@" | sed -E "s/\.[[:alnum:]]+$/.XXX/" >> build.log' @@ -132,6 +134,7 @@ PATCH assert_success unstub uname + unstub brew unstub make unstub patch @@ -150,8 +153,8 @@ OUT cached_tarball "yaml-0.1.6" cached_tarball "ruby-2.0.0" - stub uname '-s : echo Linux' - stub brew false + stub_repeated uname '-s : echo Linux' + stub_repeated brew false stub_make_install stub_make_install stub patch ' : echo patch "$@" | sed -E "s/\.[[:alnum:]]+$/.XXX/" >> build.log' @@ -165,6 +168,7 @@ PATCH assert_success unstub uname + unstub brew unstub make unstub patch @@ -185,8 +189,8 @@ OUT brew_libdir="$TMP/homebrew-yaml" mkdir -p "$brew_libdir" - stub uname '-s : echo Linux' - stub brew false "--prefix libyaml : echo '$brew_libdir'" false + stub_repeated uname '-s : echo Linux' + stub_repeated brew "--prefix libyaml : echo '$brew_libdir'" stub_make_install run_inline_definition <> build.log' stub_make_install diff --git a/test/compiler.bats b/test/compiler.bats index 33c6f20243..7a681f369c 100755 --- a/test/compiler.bats +++ b/test/compiler.bats @@ -8,9 +8,9 @@ export -n CC export -n RUBY_CONFIGURE_OPTS @test "require_gcc on OS X 10.9" { - stub uname '-s : echo Darwin' + stub_repeated uname '-s : echo Darwin' stub sw_vers '-productVersion : echo 10.9.5' - stub gcc '--version : echo 4.2.1' '--version : echo 4.2.1' + stub_repeated gcc '--version : echo 4.2.1' run_inline_definition < ./configure <&2 && exit 2' \ "--definitions : echo 1.8.7 1.9.3-p0 1.9.3-p194 2.1.2 | tr ' ' $'\\n'" @@ -97,6 +97,7 @@ If the version you need is missing, try upgrading ruby-build: git -C ${BATS_TEST_DIRNAME}/.. pull OUT + unstub brew unstub ruby-build } diff --git a/test/stubs/stub b/test/stubs/stub index bd5c5d6880..c2ace56cb3 100755 --- a/test/stubs/stub +++ b/test/stubs/stub @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -e -status=0 +status=127 program="${0##*/}" PROGRAM="$(echo "$program" | tr a-z- A-Z_)" [ -n "$TMPDIR" ] || TMPDIR="/tmp" @@ -9,6 +9,7 @@ PROGRAM="$(echo "$program" | tr a-z- A-Z_)" _STUB_PLAN="${PROGRAM}_STUB_PLAN" _STUB_RUN="${PROGRAM}_STUB_RUN" _STUB_INDEX="${PROGRAM}_STUB_INDEX" +_STUB_NOINDEX="${PROGRAM}_STUB_NOINDEX" _STUB_RESULT="${PROGRAM}_STUB_RESULT" _STUB_END="${PROGRAM}_STUB_END" _STUB_DEBUG="${PROGRAM}_STUB_DEBUG" @@ -32,7 +33,7 @@ index=0 while IFS= read -r line; do index=$(($index + 1)) - if [ -z "${!_STUB_END}" ] && [ $index -eq "${!_STUB_INDEX}" ]; then + if [[ -z "${!_STUB_END}" && -n "${!_STUB_NOINDEX}" || $index -eq "${!_STUB_INDEX}" ]]; then # We found the plan line we're interested in. # Start off by assuming success. result=0 @@ -72,7 +73,8 @@ while IFS= read -r line; do ( eval "$command" ) status="$?" set -e - else + [ -z "${!_STUB_NOINDEX}" ] || break + elif [ -z "${!_STUB_NOINDEX}" ]; then eval "${_STUB_RESULT}"=1 fi fi @@ -95,7 +97,7 @@ if [ -n "${!_STUB_END}" ]; then else # If the requested index is larger than the number # of lines in the plan file, we failed. - if [ "${!_STUB_INDEX}" -gt $index ]; then + if [[ -z "${!_STUB_NOINDEX}" && "${!_STUB_INDEX}" -gt $index ]]; then eval "${_STUB_RESULT}"=1 fi diff --git a/test/test_helper.bash b/test/test_helper.bash index ea7ddae45d..982696e352 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -50,6 +50,13 @@ stub() { for arg in "$@"; do printf "%s\n" "$arg" >> "${TMP}/${program}-stub-plan"; done } +stub_repeated() { + local program="$1" + local prefix="$(echo "$program" | tr a-z- A-Z_)" + export "${prefix}_STUB_NOINDEX"=1 + stub "$@" +} + unstub() { local program="$1" local prefix="$(echo "$program" | tr a-z- A-Z_)"