mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-04 03:26:19 +00: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
|
||||
|
||||
TESTS=1
|
||||
plan 1
|
||||
|
||||
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
|
||||
|
||||
TESTS=20
|
||||
plan 20
|
||||
|
||||
TMPFILE="$TEST_TMPDIR/parse-opts-output"
|
||||
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
|
||||
|
||||
# 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.
|
||||
collect "$TMPDIR/collect" "2011_12_05" > $p-output 2>&1
|
||||
@@ -113,7 +113,7 @@ cmd_ok \
|
||||
"grep -qP '^wait_timeout\t\d' $p-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"
|
||||
|
||||
empty_files=0
|
||||
@@ -140,7 +140,7 @@ rm $TMPDIR/collect/*
|
||||
|
||||
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"
|
||||
|
||||
# ############################################################################
|
||||
|
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
|
||||
|
||||
TESTS=9
|
||||
plan 9
|
||||
|
||||
TMPDIR="$TEST_TMPDIR"
|
||||
local file="$TMPDIR/pid-file"
|
||||
file="$TMPDIR/pid-file"
|
||||
|
||||
source "$LIB_DIR/log_warn_die.sh"
|
||||
source "$LIB_DIR/daemon.sh"
|
||||
@@ -18,7 +18,7 @@ cmd_ok \
|
||||
"test -f $file" \
|
||||
"PID file created"
|
||||
|
||||
local pid=`cat $file`
|
||||
pid=`cat $file`
|
||||
is \
|
||||
"$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
|
||||
|
||||
TESTS=6
|
||||
plan 6
|
||||
|
||||
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
|
||||
|
||||
TESTS=78
|
||||
plan 78
|
||||
|
||||
TMPFILE="$TEST_TMPDIR/parse-opts-output"
|
||||
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"
|
||||
|
||||
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"
|
||||
|
||||
# ###########################################################################
|
||||
|
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
|
||||
|
||||
TESTS=11
|
||||
plan 11
|
||||
|
||||
source "$LIB_DIR/log_warn_die.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
|
||||
|
||||
TESTS=9
|
||||
plan 9
|
||||
|
||||
source "$LIB_DIR/log_warn_die.sh"
|
||||
source "$LIB_DIR/tmpdir.sh"
|
||||
@@ -21,7 +21,7 @@ is "$TMPDIR" "" "rm_tmpdir resets TMPDIR"
|
||||
# User-specified tmpdir.
|
||||
# ###########################################################################
|
||||
|
||||
local dir="/tmp/use--tmpdir"
|
||||
dir="/tmp/use--tmpdir"
|
||||
|
||||
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,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