2015-07-30 02:37:31 +00:00
|
|
|
#!/usr/bin/env bash
|
2015-05-18 19:44:22 +00:00
|
|
|
# Usage: . testlib.sh
|
|
|
|
# Simple shell command language test library.
|
|
|
|
#
|
|
|
|
# Tests must follow the basic form:
|
|
|
|
#
|
|
|
|
# begin_test "the thing"
|
|
|
|
# (
|
|
|
|
# set -e
|
|
|
|
# echo "hello"
|
|
|
|
# false
|
|
|
|
# )
|
|
|
|
# end_test
|
|
|
|
#
|
|
|
|
# When a test fails its stdout and stderr are shown.
|
|
|
|
#
|
|
|
|
# Note that tests must `set -e' within the subshell block or failed assertions
|
|
|
|
# will not cause the test to fail and the result may be misreported.
|
|
|
|
#
|
|
|
|
# Copyright (c) 2011-13 by Ryan Tomayko <http://tomayko.com>
|
|
|
|
# License: MIT
|
|
|
|
|
2015-07-30 02:14:01 +00:00
|
|
|
fullfile="$(pwd)/$0"
|
|
|
|
|
2015-05-18 23:28:58 +00:00
|
|
|
. "test/testenv.sh"
|
2015-05-19 01:09:32 +00:00
|
|
|
set -e
|
2015-05-18 19:44:22 +00:00
|
|
|
|
|
|
|
# keep track of num tests and failures
|
|
|
|
tests=0
|
|
|
|
failures=0
|
|
|
|
|
|
|
|
# this runs at process exit
|
|
|
|
atexit () {
|
2015-05-18 23:15:32 +00:00
|
|
|
shutdown
|
2015-05-18 19:44:22 +00:00
|
|
|
|
2015-05-18 23:15:32 +00:00
|
|
|
if [ $failures -gt 0 ]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
2015-07-30 02:14:01 +00:00
|
|
|
|
|
|
|
exit 0
|
2015-05-18 19:44:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# create the trash dir
|
|
|
|
trap "atexit" EXIT
|
|
|
|
|
|
|
|
SHUTDOWN_LFS=yes
|
|
|
|
GITSERVER=undefined
|
|
|
|
|
|
|
|
# if the file exists, assume another process started it, and will clean it up
|
|
|
|
# when it's done
|
|
|
|
if [ -s $LFS_URL_FILE ]; then
|
|
|
|
SHUTDOWN_LFS=no
|
|
|
|
else
|
2015-06-07 15:40:35 +00:00
|
|
|
setup || {
|
|
|
|
failures=$(( failures + 1 ))
|
|
|
|
exit $?
|
|
|
|
}
|
2015-05-18 19:44:22 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
GITSERVER=$(cat "$LFS_URL_FILE")
|
|
|
|
cd "$TRASHDIR"
|
|
|
|
|
|
|
|
# Mark the beginning of a test. A subshell should immediately follow this
|
|
|
|
# statement.
|
|
|
|
begin_test () {
|
|
|
|
test_status=$?
|
|
|
|
[ -n "$test_description" ] && end_test $test_status
|
|
|
|
unset test_status
|
|
|
|
|
|
|
|
tests=$(( tests + 1 ))
|
|
|
|
test_description="$1"
|
|
|
|
|
|
|
|
exec 3>&1 4>&2
|
|
|
|
out="$TRASHDIR/out"
|
|
|
|
err="$TRASHDIR/err"
|
2015-09-04 14:45:07 +00:00
|
|
|
trace="$TRASHDIR/trace"
|
|
|
|
|
2015-05-18 19:44:22 +00:00
|
|
|
exec 1>"$out" 2>"$err"
|
|
|
|
|
2015-06-28 12:48:59 +00:00
|
|
|
# reset global git config
|
2015-07-30 02:03:57 +00:00
|
|
|
HOME="$TRASHDIR/home"
|
2015-09-04 14:45:07 +00:00
|
|
|
export GIT_TRACE=$trace
|
2015-09-08 15:34:38 +00:00
|
|
|
rm -rf "$trace"
|
|
|
|
touch "$trace"
|
2015-07-30 02:03:57 +00:00
|
|
|
rm -rf "$TRASHDIR/home"
|
|
|
|
mkdir "$HOME"
|
|
|
|
cp "$TESTHOME/.gitconfig" "$HOME/.gitconfig"
|
|
|
|
|
|
|
|
if [ "$OSXKEYFILE" ]; then
|
|
|
|
ln -s "$TESTHOME/Library" "$HOME"
|
|
|
|
fi
|
2015-06-28 12:48:59 +00:00
|
|
|
|
2015-05-18 19:44:22 +00:00
|
|
|
# allow the subshell to exit non-zero without exiting this process
|
|
|
|
set -x +e
|
|
|
|
}
|
|
|
|
|
|
|
|
# Mark the end of a test.
|
|
|
|
end_test () {
|
|
|
|
test_status="${1:-$?}"
|
|
|
|
set +x -e
|
|
|
|
exec 1>&3 2>&4
|
|
|
|
|
|
|
|
if [ "$test_status" -eq 0 ]; then
|
|
|
|
printf "test: %-60s OK\n" "$test_description ..."
|
|
|
|
else
|
|
|
|
failures=$(( failures + 1 ))
|
|
|
|
printf "test: %-60s FAILED\n" "$test_description ..."
|
|
|
|
(
|
|
|
|
echo "-- stdout --"
|
|
|
|
sed 's/^/ /' <"$TRASHDIR/out"
|
|
|
|
echo "-- stderr --"
|
|
|
|
grep -v -e '^\+ end_test' -e '^+ set +x' <"$TRASHDIR/err" |
|
|
|
|
sed 's/^/ /'
|
2015-09-04 14:45:07 +00:00
|
|
|
echo "-- git trace --"
|
|
|
|
sed 's/^/ /' <"$TRASHDIR/trace"
|
2015-05-18 19:44:22 +00:00
|
|
|
) 1>&2
|
|
|
|
fi
|
|
|
|
unset test_description
|
|
|
|
}
|