mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-10 13:11:32 +00:00
Simplify and individuate Bash tests so prove reports failures where they happen.
This commit is contained in:
@@ -14,21 +14,26 @@ die() {
|
||||
exit 255
|
||||
}
|
||||
|
||||
(
|
||||
if [ -n "$PERCONA_TOOLKIT_BRANCH" ]; then
|
||||
BRANCH=$PERCONA_TOOLKIT_BRANCH
|
||||
cd $BRANCH
|
||||
else
|
||||
while [ ! -f Makefile.PL ] && [ $(pwd) != "/" ]; do
|
||||
cd ..
|
||||
done
|
||||
if [ ! -f Makefile.PL ]; then
|
||||
die "Cannot find the root directory of the Percona Toolkit branch"
|
||||
exit 1
|
||||
fi
|
||||
BRANCH=`pwd`
|
||||
cwd="$PWD"
|
||||
if [ -n "$PERCONA_TOOLKIT_BRANCH" ]; then
|
||||
BRANCH=$PERCONA_TOOLKIT_BRANCH
|
||||
cd $BRANCH
|
||||
else
|
||||
while [ ! -f Makefile.PL ] && [ $(pwd) != "/" ]; do
|
||||
cd ..
|
||||
done
|
||||
if [ ! -f Makefile.PL ]; then
|
||||
die "Cannot find the root directory of the Percona Toolkit branch"
|
||||
exit 1
|
||||
fi
|
||||
)
|
||||
BRANCH="$PWD"
|
||||
fi
|
||||
cd "$cwd"
|
||||
|
||||
BIN_DIR="$BRANCH/bin";
|
||||
LIB_DIR="$BRANCH/lib/bash";
|
||||
T_LIB_DIR="$BRANCH/t/lib";
|
||||
SANDBOX_VERSION="$($BRANCH/sandbox/test-env version)"
|
||||
|
||||
# ############################################################################
|
||||
# Paths
|
||||
@@ -108,6 +113,13 @@ result() {
|
||||
return $result
|
||||
}
|
||||
|
||||
plan() {
|
||||
local n_tests=${1:-""}
|
||||
if [ "$n_tests" ]; then
|
||||
echo "1..$n_tests"
|
||||
fi
|
||||
}
|
||||
|
||||
#
|
||||
# The following subs are for the test files to call.
|
||||
#
|
||||
@@ -141,32 +153,38 @@ cmd_ok() {
|
||||
# Script starts here
|
||||
# ############################################################################
|
||||
|
||||
if [ $# -lt 2 ]; then
|
||||
die "Usage: test-back-functions FILE TESTS"
|
||||
fi
|
||||
|
||||
# Check and source the bash file. This is the code being tested.
|
||||
# All its global vars and subs will be imported.
|
||||
bash_file=$1
|
||||
shift
|
||||
if [ ! -f "$bash_file" ]; then
|
||||
die "$bash_file does not exist"
|
||||
fi
|
||||
head -n1 $bash_file | grep -q -E 'bash|sh' || die "$bash_file is not a bash file"
|
||||
source $bash_file
|
||||
|
||||
# Load (count) the tests so that we can write a TAP test plan like 1..5
|
||||
# for expecting 5 tests. Perl prove needs this.
|
||||
declare -a tests
|
||||
load_tests "$@"
|
||||
|
||||
# Run the test files.
|
||||
testno=1
|
||||
failed_tests=0
|
||||
for t in "${tests[@]}"; do
|
||||
run_test $t
|
||||
done
|
||||
|
||||
if [ $# -eq 0 ]; then
|
||||
TEST_FILE=$(basename "$0")
|
||||
TEST="${TEST_FILE%".t"}"
|
||||
source "$BRANCH/t/lib/bash/$TEST.sh"
|
||||
else
|
||||
if [ $# -lt 2 ]; then
|
||||
die "Usage: test-bash-functions FILE TESTS"
|
||||
fi
|
||||
|
||||
# Check and source the bash file. This is the code being tested.
|
||||
# All its global vars and subs will be imported.
|
||||
bash_file=$1
|
||||
shift
|
||||
if [ ! -f "$bash_file" ]; then
|
||||
die "$bash_file does not exist"
|
||||
fi
|
||||
head -n1 $bash_file | grep -q -E 'bash|sh' || die "$bash_file is not a bash file"
|
||||
source $bash_file
|
||||
|
||||
# Load (count) the tests so that we can write a TAP test plan like 1..5
|
||||
# for expecting 5 tests. Perl prove needs this.
|
||||
declare -a tests
|
||||
load_tests "$@"
|
||||
|
||||
# Run the test files.
|
||||
for t in "${tests[@]}"; do
|
||||
run_test $t
|
||||
done
|
||||
fi
|
||||
|
||||
rm -rf $TEST_TMPDIR
|
||||
|
||||
exit $failed_tests
|
||||
|
Reference in New Issue
Block a user