Unverified Commit 4079aa75 authored by Mislav Marohnić's avatar Mislav Marohnić
Browse files

add stub_repeated test helper

parent 40af31b4
Loading
Loading
Loading
Loading
+24 −20
Original line number Diff line number Diff line
@@ -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 <<OUT
@@ -86,8 +87,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'
@@ -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 <<DEF
@@ -211,7 +215,7 @@ OUT
  gmp_libdir="$TMP/homebrew-gmp"
  mkdir -p "$gmp_libdir"

  stub brew false "--prefix gmp : echo '$gmp_libdir'"
  stub_repeated brew "--prefix gmp : echo '$gmp_libdir'"
  stub_make_install

  run_inline_definition <<DEF
@@ -235,7 +239,7 @@ OUT
  readline_libdir="$TMP/homebrew-readline"
  mkdir -p "$readline_libdir"

  stub brew "--prefix readline : echo '$readline_libdir'" false
  stub_repeated brew "--prefix readline : echo '$readline_libdir'"
  stub_make_install

  run_inline_definition <<DEF
@@ -256,7 +260,7 @@ OUT
@test "readline is not linked from Homebrew when explicitly defined" {
  cached_tarball "ruby-2.0.0"

  stub brew false
  stub_repeated brew false
  stub_make_install

  export RUBY_CONFIGURE_OPTS='--with-readline-dir=/custom'
@@ -278,7 +282,7 @@ OUT
@test "number of CPU cores defaults to 2" {
  cached_tarball "ruby-2.0.0"

  stub uname '-s : echo Darwin' false
  stub_repeated uname '-s : echo Darwin'
  stub sysctl false
  stub_make_install

@@ -301,7 +305,7 @@ OUT
@test "number of CPU cores is detected on Mac" {
  cached_tarball "ruby-2.0.0"

  stub uname '-s : echo Darwin' false
  stub_repeated uname '-s : echo Darwin'
  stub sysctl '-n hw.ncpu : echo 4'
  stub_make_install

@@ -325,7 +329,7 @@ OUT
@test "number of CPU cores is detected on FreeBSD" {
  cached_tarball "ruby-2.0.0"

  stub uname '-s : echo FreeBSD' false
  stub_repeated uname '-s : echo FreeBSD'
  stub sysctl '-n hw.ncpu : echo 1'
  stub_make_install

@@ -349,7 +353,7 @@ OUT
@test "setting RUBY_MAKE_INSTALL_OPTS to a multi-word string" {
  cached_tarball "ruby-2.0.0"

  stub uname '-s : echo Linux'
  stub_repeated uname '-s : echo Linux'
  stub_make_install

  export RUBY_MAKE_INSTALL_OPTS="DOGE=\"such wow\""
@@ -371,7 +375,7 @@ OUT
@test "setting MAKE_INSTALL_OPTS to a multi-word string" {
  cached_tarball "ruby-2.0.0"

  stub uname '-s : echo Linux'
  stub_repeated uname '-s : echo Linux'
  stub_make_install

  export MAKE_INSTALL_OPTS="DOGE=\"such wow\""
@@ -402,7 +406,7 @@ OUT
@test "make on FreeBSD defaults to gmake" {
  cached_tarball "ruby-2.0.0"

  stub uname "-s : echo FreeBSD" false
  stub_repeated uname "-s : echo FreeBSD"
  MAKE=gmake stub_make_install

  MAKE= install_fixture definitions/vanilla-ruby
@@ -421,7 +425,7 @@ apply -p1 -i /my/patch.diff
exec ./configure "\$@"
CONF

  stub uname '-s : echo Linux'
  stub_repeated uname '-s : echo Linux'
  stub apply 'echo apply "$@" >> build.log'
  stub_make_install

+20 −10
Original line number Diff line number Diff line
@@ -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 <<DEF
require_gcc
@@ -22,12 +22,16 @@ DEF
CC=${TMP}/bin/gcc
MACOSX_DEPLOYMENT_TARGET=no
OUT

  unstub uname
  unstub sw_vers
  unstub gcc
}

@test "require_gcc on OS X 10.10" {
  stub uname '-s : echo Darwin'
  stub_repeated uname '-s : echo Darwin'
  stub sw_vers '-productVersion : echo 10.10'
  stub gcc '--version : echo 4.2.1' '--version : echo 4.2.1'
  stub_repeated gcc '--version : echo 4.2.1'

  run_inline_definition <<DEF
require_gcc
@@ -39,6 +43,10 @@ DEF
CC=${TMP}/bin/gcc
MACOSX_DEPLOYMENT_TARGET=10.9
OUT

  unstub uname
  unstub sw_vers
  unstub gcc
}

@test "require_gcc silences warnings" {
@@ -55,13 +63,10 @@ DEF
  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 $@'
  stub_repeated brew 'false'
  stub_repeated make 'echo make $@'

  cat > ./configure <<CON
#!${BASH}
@@ -83,4 +88,9 @@ CFLAGS=no
make -j 2
make install
OUT

  unstub uname
  unstub sw_vers
  unstub brew
  unstub make
}
+2 −1
Original line number Diff line number Diff line
@@ -77,7 +77,7 @@ OUT
}

@test "nonexistent version" {
  stub brew false
  stub_repeated brew false
  stub_ruby_build 'echo ERROR >&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
}

+6 −4
Original line number Diff line number Diff line
#!/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

+7 −0
Original line number Diff line number Diff line
@@ -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_)"