mirror of
https://github.com/percona/percona-toolkit.git
synced 2026-04-17 01:01:39 +08:00
Simplify and individuate Bash tests so prove reports failures where they happen.
This commit is contained in:
25
t/lib/bash.t
25
t/lib/bash.t
@@ -1,25 +0,0 @@
|
|||||||
#!/usr/bin/env perl
|
|
||||||
|
|
||||||
BEGIN {
|
|
||||||
die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n"
|
|
||||||
unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH};
|
|
||||||
unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib";
|
|
||||||
};
|
|
||||||
|
|
||||||
use strict;
|
|
||||||
use warnings FATAL => 'all';
|
|
||||||
use English qw(-no_match_vars);
|
|
||||||
|
|
||||||
use PerconaTest;
|
|
||||||
|
|
||||||
my ($tool) = $PROGRAM_NAME =~ m/([\w-]+)\.t$/;
|
|
||||||
push @ARGV, "$trunk/t/lib/bash/*.sh" unless @ARGV;
|
|
||||||
|
|
||||||
$ENV{BIN_DIR} = "$trunk/bin";
|
|
||||||
$ENV{LIB_DIR} = "$trunk/lib/bash";
|
|
||||||
$ENV{T_LIB_DIR} = "$trunk/t/lib";
|
|
||||||
$ENV{SANDBOX_VERSION} = "$sandbox_version";
|
|
||||||
|
|
||||||
system("$trunk/util/test-bash-functions $trunk/t/lib/samples/bash/dummy.sh @ARGV");
|
|
||||||
|
|
||||||
exit;
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
TESTS=1
|
plan 1
|
||||||
|
|
||||||
source "$LIB_DIR/alt_cmds.sh"
|
source "$LIB_DIR/alt_cmds.sh"
|
||||||
|
|
||||||
|
|||||||
1
t/lib/bash/alt_cmds.t
Symbolic link
1
t/lib/bash/alt_cmds.t
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../../util/test-bash-functions
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
TESTS=20
|
plan 20
|
||||||
|
|
||||||
TMPFILE="$TEST_TMPDIR/parse-opts-output"
|
TMPFILE="$TEST_TMPDIR/parse-opts-output"
|
||||||
TMPDIR="$TEST_TMPDIR"
|
TMPDIR="$TEST_TMPDIR"
|
||||||
@@ -18,7 +18,7 @@ source "$LIB_DIR/collect.sh"
|
|||||||
parse_options "$BIN_DIR/pt-stalk" --run-time 1 -- --defaults-file=/tmp/12345/my.sandbox.cnf
|
parse_options "$BIN_DIR/pt-stalk" --run-time 1 -- --defaults-file=/tmp/12345/my.sandbox.cnf
|
||||||
|
|
||||||
# Prefix (with path) for the collect files.
|
# Prefix (with path) for the collect files.
|
||||||
local p="$TMPDIR/collect/2011_12_05"
|
p="$TMPDIR/collect/2011_12_05"
|
||||||
|
|
||||||
# Default collect, no extras like gdb, tcpdump, etc.
|
# Default collect, no extras like gdb, tcpdump, etc.
|
||||||
collect "$TMPDIR/collect" "2011_12_05" > $p-output 2>&1
|
collect "$TMPDIR/collect" "2011_12_05" > $p-output 2>&1
|
||||||
@@ -113,7 +113,7 @@ cmd_ok \
|
|||||||
"grep -qP '^wait_timeout\t\d' $p-variables" \
|
"grep -qP '^wait_timeout\t\d' $p-variables" \
|
||||||
"variables"
|
"variables"
|
||||||
|
|
||||||
local iters=$(cat $p-df | grep -c '^TS ')
|
iters=$(cat $p-df | grep -c '^TS ')
|
||||||
is "$iters" "1" "1 iteration/1s run time"
|
is "$iters" "1" "1 iteration/1s run time"
|
||||||
|
|
||||||
empty_files=0
|
empty_files=0
|
||||||
@@ -140,7 +140,7 @@ rm $TMPDIR/collect/*
|
|||||||
|
|
||||||
collect "$TMPDIR/collect" "2011_12_05" > $p-output 2>&1
|
collect "$TMPDIR/collect" "2011_12_05" > $p-output 2>&1
|
||||||
|
|
||||||
local iters=$(cat $p-df | grep -c '^TS ')
|
iters=$(cat $p-df | grep -c '^TS ')
|
||||||
is "$iters" "2" "2 iteration/2s run time"
|
is "$iters" "2" "2 iteration/2s run time"
|
||||||
|
|
||||||
# ############################################################################
|
# ############################################################################
|
||||||
|
|||||||
1
t/lib/bash/collect.t
Symbolic link
1
t/lib/bash/collect.t
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../../util/test-bash-functions
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
TESTS=9
|
plan 9
|
||||||
|
|
||||||
TMPDIR="$TEST_TMPDIR"
|
TMPDIR="$TEST_TMPDIR"
|
||||||
local file="$TMPDIR/pid-file"
|
file="$TMPDIR/pid-file"
|
||||||
|
|
||||||
source "$LIB_DIR/log_warn_die.sh"
|
source "$LIB_DIR/log_warn_die.sh"
|
||||||
source "$LIB_DIR/daemon.sh"
|
source "$LIB_DIR/daemon.sh"
|
||||||
@@ -18,7 +18,7 @@ cmd_ok \
|
|||||||
"test -f $file" \
|
"test -f $file" \
|
||||||
"PID file created"
|
"PID file created"
|
||||||
|
|
||||||
local pid=`cat $file`
|
pid=`cat $file`
|
||||||
is \
|
is \
|
||||||
"$pid" \
|
"$pid" \
|
||||||
"$$" \
|
"$$" \
|
||||||
|
|||||||
1
t/lib/bash/daemon.t
Symbolic link
1
t/lib/bash/daemon.t
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../../util/test-bash-functions
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
TESTS=6
|
plan 6
|
||||||
|
|
||||||
source "$LIB_DIR/log_warn_die.sh"
|
source "$LIB_DIR/log_warn_die.sh"
|
||||||
|
|
||||||
|
|||||||
1
t/lib/bash/log_warn_die.t
Symbolic link
1
t/lib/bash/log_warn_die.t
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../../util/test-bash-functions
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
TESTS=78
|
plan 78
|
||||||
|
|
||||||
TMPFILE="$TEST_TMPDIR/parse-opts-output"
|
TMPFILE="$TEST_TMPDIR/parse-opts-output"
|
||||||
TOOL="pt-stalk"
|
TOOL="pt-stalk"
|
||||||
@@ -93,7 +93,7 @@ parse_options "$T_LIB_DIR/samples/bash/po001.sh" --foo >$TMPFILE 2>&1
|
|||||||
cmd_ok "grep -q 'Unknown option: --foo' $TMPFILE" "Error on unknown option"
|
cmd_ok "grep -q 'Unknown option: --foo' $TMPFILE" "Error on unknown option"
|
||||||
|
|
||||||
usage_or_errors "$T_LIB_DIR/samples/bash/po001.sh" >$TMPFILE 2>&1
|
usage_or_errors "$T_LIB_DIR/samples/bash/po001.sh" >$TMPFILE 2>&1
|
||||||
local err=$?
|
err=$?
|
||||||
is "$err" "1" "Non-zero exit on unknown option"
|
is "$err" "1" "Non-zero exit on unknown option"
|
||||||
|
|
||||||
# ###########################################################################
|
# ###########################################################################
|
||||||
|
|||||||
1
t/lib/bash/parse_options.t
Symbolic link
1
t/lib/bash/parse_options.t
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../../util/test-bash-functions
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
TESTS=11
|
plan 11
|
||||||
|
|
||||||
source "$LIB_DIR/log_warn_die.sh"
|
source "$LIB_DIR/log_warn_die.sh"
|
||||||
source "$LIB_DIR/safeguards.sh"
|
source "$LIB_DIR/safeguards.sh"
|
||||||
|
|||||||
1
t/lib/bash/safeguards.t
Symbolic link
1
t/lib/bash/safeguards.t
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../../util/test-bash-functions
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
TESTS=9
|
plan 9
|
||||||
|
|
||||||
source "$LIB_DIR/log_warn_die.sh"
|
source "$LIB_DIR/log_warn_die.sh"
|
||||||
source "$LIB_DIR/tmpdir.sh"
|
source "$LIB_DIR/tmpdir.sh"
|
||||||
@@ -21,7 +21,7 @@ is "$TMPDIR" "" "rm_tmpdir resets TMPDIR"
|
|||||||
# User-specified tmpdir.
|
# User-specified tmpdir.
|
||||||
# ###########################################################################
|
# ###########################################################################
|
||||||
|
|
||||||
local dir="/tmp/use--tmpdir"
|
dir="/tmp/use--tmpdir"
|
||||||
|
|
||||||
is "$TMPDIR" "" "TMPDIR not defined"
|
is "$TMPDIR" "" "TMPDIR not defined"
|
||||||
|
|
||||||
|
|||||||
1
t/lib/bash/tmpdir.t
Symbolic link
1
t/lib/bash/tmpdir.t
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../../util/test-bash-functions
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
# This is a dummy script for testing the Bash libs. t/lib/bashLibs.t
|
|
||||||
# calls "util/test-bash-functions dummy.sh <lib-test-files.sh>".
|
|
||||||
@@ -14,7 +14,7 @@ die() {
|
|||||||
exit 255
|
exit 255
|
||||||
}
|
}
|
||||||
|
|
||||||
(
|
cwd="$PWD"
|
||||||
if [ -n "$PERCONA_TOOLKIT_BRANCH" ]; then
|
if [ -n "$PERCONA_TOOLKIT_BRANCH" ]; then
|
||||||
BRANCH=$PERCONA_TOOLKIT_BRANCH
|
BRANCH=$PERCONA_TOOLKIT_BRANCH
|
||||||
cd $BRANCH
|
cd $BRANCH
|
||||||
@@ -26,9 +26,14 @@ die() {
|
|||||||
die "Cannot find the root directory of the Percona Toolkit branch"
|
die "Cannot find the root directory of the Percona Toolkit branch"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
BRANCH=`pwd`
|
BRANCH="$PWD"
|
||||||
fi
|
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
|
# Paths
|
||||||
@@ -108,6 +113,13 @@ result() {
|
|||||||
return $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.
|
# The following subs are for the test files to call.
|
||||||
#
|
#
|
||||||
@@ -141,8 +153,16 @@ cmd_ok() {
|
|||||||
# Script starts here
|
# Script starts here
|
||||||
# ############################################################################
|
# ############################################################################
|
||||||
|
|
||||||
|
testno=1
|
||||||
|
failed_tests=0
|
||||||
|
|
||||||
|
if [ $# -eq 0 ]; then
|
||||||
|
TEST_FILE=$(basename "$0")
|
||||||
|
TEST="${TEST_FILE%".t"}"
|
||||||
|
source "$BRANCH/t/lib/bash/$TEST.sh"
|
||||||
|
else
|
||||||
if [ $# -lt 2 ]; then
|
if [ $# -lt 2 ]; then
|
||||||
die "Usage: test-back-functions FILE TESTS"
|
die "Usage: test-bash-functions FILE TESTS"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check and source the bash file. This is the code being tested.
|
# Check and source the bash file. This is the code being tested.
|
||||||
@@ -161,12 +181,10 @@ declare -a tests
|
|||||||
load_tests "$@"
|
load_tests "$@"
|
||||||
|
|
||||||
# Run the test files.
|
# Run the test files.
|
||||||
testno=1
|
|
||||||
failed_tests=0
|
|
||||||
for t in "${tests[@]}"; do
|
for t in "${tests[@]}"; do
|
||||||
run_test $t
|
run_test $t
|
||||||
done
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
rm -rf $TEST_TMPDIR
|
rm -rf $TEST_TMPDIR
|
||||||
|
|
||||||
exit $failed_tests
|
exit $failed_tests
|
||||||
|
|||||||
Reference in New Issue
Block a user