Make test-bash-tool work with prove. Add .t for remaining bash tools.

This commit is contained in:
Daniel Nichter
2011-07-01 11:18:02 -06:00
parent a9e002cc5a
commit 71574c842f
5 changed files with 92 additions and 21 deletions

View File

@@ -1,9 +1,17 @@
#!/usr/bin/env perl
#!/usr/bin/evn 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 Test::More;
use MaatkitTest;
print `ls *`;
system("$trunk/util/test-bash-tool pt-mysql-summary @ARGV");
exit;

17
t/pt-pmp/pt-pmp.t Normal file
View File

@@ -0,0 +1,17 @@
#!/usr/bin/evn 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 MaatkitTest;
system("$trunk/util/test-bash-tool pt-pmp @ARGV");
exit;

17
t/pt-summary/pt-summary.t Normal file
View File

@@ -0,0 +1,17 @@
#!/usr/bin/evn 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 MaatkitTest;
system("$trunk/util/test-bash-tool pt-summary @ARGV");
exit;

17
t/pt-usl/pt-usl.t Normal file
View File

@@ -0,0 +1,17 @@
#!/usr/bin/evn 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 MaatkitTest;
system("$trunk/util/test-bash-tool pt-usl @ARGV");
exit;

View File

@@ -5,10 +5,6 @@ die() {
exit 255
}
warn() {
echo $1 >&2
}
if [ -n "$PERCONA_TOOLKIT_BRANCH" ]; then
BRANCH=$PERCONA_TOOLKIT_BRANCH
cd $BRANCH
@@ -26,7 +22,7 @@ fi
result() {
result=$1
if [ $result -eq 0 ]; then
echo -n "ok $testno - $t"
echo "ok $testno - $t"
else
echo "not ok $testno - $t"
failed_tests=$(( failed_tests + 1))
@@ -39,17 +35,13 @@ result() {
# All variables are named GL_whatever so they don't get overwritten with stuff
# that happens in the functions sourced.
GL_input="/tmp/percona-toolkit-test"
GL_expected="/tmp/percona-toolkit-test-expected"
GL_result="/tmp/percona-toolkit-test-result"
GL_input="/tmp/aspersa"
GL_expected="/tmp/aspersa-reference"
GL_result="/tmp/aspersa-result"
run_test() {
t=$1 # test file name, e.g. "group-by-all-01" for pt-diskstats
# Return unless the test file is bash. There may be other types of
# files in the tool's test dir.
head -n 1 $t | grep -q bash || die "$t is not a bash file"
# The format of the test file is as follows:
# - line 1 is the shebang
# - line 2 is the command to run, commented out
@@ -74,7 +66,24 @@ run_test() {
result $?
# Clean up
rm -f /tmp/percona-toolkit-test*
rm -f /tmp/aspersa*
}
load_tests() {
test_files="$@"
i=0
for t in $test_files; do
# Return unless the test file is bash. There may be other types of
# files in the tool's test dir.
if [ ! -f $t ]; then
continue
fi
head -n 1 $t | grep -q bash || continue
tests[$i]=$t
i=$(( i + 1 ))
done
echo "1..$i"
}
tool=$1 # bash tool, e.g. pt-diskstats
@@ -87,7 +96,7 @@ cd $BRANCH/bin
if [ ! -f $tool ]; then
die "$tool does not exist"
fi
head -n1 $tool | grep bash || die "$tool is not a bash file"
head -n1 $tool | grep -q bash || die "$tool is not a bash file"
# Source the tool, i.e. import its functions.
source $tool
@@ -95,14 +104,17 @@ source $tool
cd $BRANCH/t/$tool
testno=1
failed_tests=0
declare -a tests
if [ -z "$t" ]; then
# Run all the tool's tests.
for t in *; do
run_test $t
done
load_tests *
else
# Run just the specified test.
run_test $t
load_tests $t
fi
for t in "${tests[@]}"; do
run_test $t
done
exit $failed_tests