mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-10 21:19:59 +00:00
Add Bash libs tmpdir and log_warn_die. Docu parse_options. Don't use TMPDIR in test-bash-functions; add ok() to test-bash-functions.
This commit is contained in:
@@ -34,9 +34,10 @@ die() {
|
||||
# Paths
|
||||
# ############################################################################
|
||||
|
||||
TMPDIR="/tmp/percona-toolkit.test"
|
||||
if [ ! -d $TMPDIR ]; then
|
||||
mkdir $TMPDIR
|
||||
# Do not use TMPDIR because the tools use it for their own secure tmpdir.
|
||||
TEST_TMPDIR="/tmp/percona-toolkit.test"
|
||||
if [ ! -d $TEST_TMPDIR ]; then
|
||||
mkdir $TEST_TMPDIR
|
||||
fi
|
||||
|
||||
# ############################################################################
|
||||
@@ -69,7 +70,7 @@ load_tests() {
|
||||
# Source a test file to run whatever it contains (hopefully tests!).
|
||||
run_test() {
|
||||
local t=$1 # test file name, e.g. "group-by-all-01" for pt-diskstats
|
||||
rm -rf $TMPDIR/* >/dev/null 2>&1
|
||||
rm -rf $TEST_TMPDIR/* >/dev/null 2>&1
|
||||
|
||||
TEST_NUMBER=1 # test number in this test file
|
||||
|
||||
@@ -98,8 +99,8 @@ result() {
|
||||
echo "not ok $testno - $TEST_FILE $test_name"
|
||||
failed_tests=$(( failed_tests + 1))
|
||||
echo "# Failed '$test_command'" >&2
|
||||
if [ -f $TMPDIR/failed_result ]; then
|
||||
cat $TMPDIR/failed_result | sed -e 's/^/# /' -e '30q' >&2
|
||||
if [ -f $TEST_TMPDIR/failed_result ]; then
|
||||
cat $TEST_TMPDIR/failed_result | sed -e 's/^/# /' -e '30q' >&2
|
||||
fi
|
||||
fi
|
||||
testno=$((testno + 1))
|
||||
@@ -115,7 +116,7 @@ no_diff() {
|
||||
local got=$1
|
||||
local expected=$2
|
||||
test_command="diff $got $expected"
|
||||
eval $test_command > $TMPDIR/failed_result 2>&1
|
||||
eval $test_command > $TEST_TMPDIR/failed_result 2>&1
|
||||
result $?
|
||||
}
|
||||
|
||||
@@ -127,6 +128,12 @@ is() {
|
||||
result $?
|
||||
}
|
||||
|
||||
ok() {
|
||||
local test_command=$1
|
||||
$test_command
|
||||
result $?
|
||||
}
|
||||
|
||||
# ############################################################################
|
||||
# Script starts here
|
||||
# ############################################################################
|
||||
@@ -157,6 +164,6 @@ for t in "${tests[@]}"; do
|
||||
run_test $t
|
||||
done
|
||||
|
||||
rm -rf $TMPDIR
|
||||
rm -rf $TEST_TMPDIR
|
||||
|
||||
exit $failed_tests
|
||||
|
Reference in New Issue
Block a user