2014-01-17 07:14:30 -05:00
|
|
|
export TMP="$BATS_TEST_DIRNAME/tmp"
|
2019-04-07 21:05:34 -04:00
|
|
|
export PYTHON_BUILD_CURL_OPTS=
|
|
|
|
export PYTHON_BUILD_HTTP_CLIENT="curl"
|
2014-01-17 07:14:30 -05:00
|
|
|
|
|
|
|
if [ "$FIXTURE_ROOT" != "$BATS_TEST_DIRNAME/fixtures" ]; then
|
|
|
|
export FIXTURE_ROOT="$BATS_TEST_DIRNAME/fixtures"
|
|
|
|
export INSTALL_ROOT="$TMP/install"
|
2019-04-07 21:05:34 -04:00
|
|
|
PATH="/usr/bin:/bin:/usr/sbin:/sbin"
|
|
|
|
if [ "FreeBSD" = "$(uname -s)" ]; then
|
|
|
|
PATH="/usr/local/bin:$PATH"
|
|
|
|
fi
|
2014-01-17 07:14:30 -05:00
|
|
|
PATH="$BATS_TEST_DIRNAME/../bin:$PATH"
|
|
|
|
PATH="$TMP/bin:$PATH"
|
|
|
|
export PATH
|
|
|
|
fi
|
|
|
|
|
|
|
|
teardown() {
|
2015-12-06 20:22:57 -05:00
|
|
|
rm -fr "${TMP:?}"/*
|
2014-01-17 07:14:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
stub() {
|
|
|
|
local program="$1"
|
|
|
|
local prefix="$(echo "$program" | tr a-z- A-Z_)"
|
|
|
|
shift
|
|
|
|
|
|
|
|
export "${prefix}_STUB_PLAN"="${TMP}/${program}-stub-plan"
|
|
|
|
export "${prefix}_STUB_RUN"="${TMP}/${program}-stub-run"
|
2021-09-20 20:17:58 -04:00
|
|
|
export "${prefix}_STUB_LOG"="${TMP}/${program}-stub-log"
|
2014-01-17 07:14:30 -05:00
|
|
|
export "${prefix}_STUB_END"=
|
|
|
|
|
|
|
|
mkdir -p "${TMP}/bin"
|
|
|
|
ln -sf "${BATS_TEST_DIRNAME}/stubs/stub" "${TMP}/bin/${program}"
|
|
|
|
|
|
|
|
touch "${TMP}/${program}-stub-plan"
|
|
|
|
for arg in "$@"; do printf "%s\n" "$arg" >> "${TMP}/${program}-stub-plan"; done
|
|
|
|
}
|
|
|
|
|
|
|
|
unstub() {
|
|
|
|
local program="$1"
|
|
|
|
local prefix="$(echo "$program" | tr a-z- A-Z_)"
|
|
|
|
local path="${TMP}/bin/${program}"
|
|
|
|
|
|
|
|
export "${prefix}_STUB_END"=1
|
|
|
|
|
|
|
|
local STATUS=0
|
|
|
|
"$path" || STATUS="$?"
|
|
|
|
|
|
|
|
rm -f "$path"
|
|
|
|
rm -f "${TMP}/${program}-stub-plan" "${TMP}/${program}-stub-run"
|
|
|
|
return "$STATUS"
|
|
|
|
}
|
|
|
|
|
|
|
|
run_inline_definition() {
|
|
|
|
local definition="${TMP}/build-definition"
|
|
|
|
cat > "$definition"
|
|
|
|
run python-build "$definition" "${1:-$INSTALL_ROOT}"
|
|
|
|
}
|
|
|
|
|
|
|
|
install_fixture() {
|
|
|
|
local args
|
|
|
|
|
|
|
|
while [ "${1#-}" != "$1" ]; do
|
|
|
|
args="$args $1"
|
|
|
|
shift 1
|
|
|
|
done
|
|
|
|
|
|
|
|
local name="$1"
|
|
|
|
local destination="$2"
|
|
|
|
[ -n "$destination" ] || destination="$INSTALL_ROOT"
|
|
|
|
|
|
|
|
run python-build $args "$FIXTURE_ROOT/$name" "$destination"
|
|
|
|
}
|
|
|
|
|
|
|
|
assert() {
|
|
|
|
if ! "$@"; then
|
|
|
|
flunk "failed: $@"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-02-07 19:01:02 -05:00
|
|
|
refute() {
|
|
|
|
if "$@"; then
|
|
|
|
flunk "expected to fail: $@"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2014-01-17 07:14:30 -05:00
|
|
|
flunk() {
|
|
|
|
{ if [ "$#" -eq 0 ]; then cat -
|
|
|
|
else echo "$@"
|
|
|
|
fi
|
|
|
|
} | sed "s:${TMP}:\${TMP}:g" >&2
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_success() {
|
|
|
|
if [ "$status" -ne 0 ]; then
|
|
|
|
{ echo "command failed with exit status $status"
|
|
|
|
echo "output: $output"
|
|
|
|
} | flunk
|
|
|
|
elif [ "$#" -gt 0 ]; then
|
|
|
|
assert_output "$1"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_failure() {
|
|
|
|
if [ "$status" -eq 0 ]; then
|
|
|
|
flunk "expected failed exit status"
|
|
|
|
elif [ "$#" -gt 0 ]; then
|
|
|
|
assert_output "$1"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_equal() {
|
|
|
|
if [ "$1" != "$2" ]; then
|
|
|
|
{ echo "expected: $1"
|
|
|
|
echo "actual: $2"
|
|
|
|
} | flunk
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_output() {
|
|
|
|
local expected
|
|
|
|
if [ $# -eq 0 ]; then expected="$(cat -)"
|
|
|
|
else expected="$1"
|
|
|
|
fi
|
|
|
|
assert_equal "$expected" "$output"
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_output_contains() {
|
|
|
|
local expected="$1"
|
2015-01-15 09:13:36 -05:00
|
|
|
if [ -z "$expected" ]; then
|
|
|
|
echo "assert_output_contains needs an argument" >&2
|
|
|
|
return 1
|
|
|
|
fi
|
2021-05-17 03:40:35 -04:00
|
|
|
echo "$output" | $(type -P ggrep grep | head -1) -F "$expected" >/dev/null || {
|
2014-01-17 07:14:30 -05:00
|
|
|
{ echo "expected output to contain $expected"
|
|
|
|
echo "actual: $output"
|
|
|
|
} | flunk
|
|
|
|
}
|
|
|
|
}
|