mirror of
https://github.com/percona/percona-toolkit.git
synced 2026-04-11 01:01:36 +08:00
Make test-bash-tool work with prove. Add .t for remaining bash tools.
This commit is contained in:
@@ -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 strict;
|
||||||
use warnings FATAL => 'all';
|
use warnings FATAL => 'all';
|
||||||
use English qw(-no_match_vars);
|
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
17
t/pt-pmp/pt-pmp.t
Normal 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
17
t/pt-summary/pt-summary.t
Normal 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
17
t/pt-usl/pt-usl.t
Normal 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;
|
||||||
@@ -5,10 +5,6 @@ die() {
|
|||||||
exit 255
|
exit 255
|
||||||
}
|
}
|
||||||
|
|
||||||
warn() {
|
|
||||||
echo $1 >&2
|
|
||||||
}
|
|
||||||
|
|
||||||
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,7 +22,7 @@ fi
|
|||||||
result() {
|
result() {
|
||||||
result=$1
|
result=$1
|
||||||
if [ $result -eq 0 ]; then
|
if [ $result -eq 0 ]; then
|
||||||
echo -n "ok $testno - $t"
|
echo "ok $testno - $t"
|
||||||
else
|
else
|
||||||
echo "not ok $testno - $t"
|
echo "not ok $testno - $t"
|
||||||
failed_tests=$(( failed_tests + 1))
|
failed_tests=$(( failed_tests + 1))
|
||||||
@@ -39,17 +35,13 @@ result() {
|
|||||||
|
|
||||||
# All variables are named GL_whatever so they don't get overwritten with stuff
|
# All variables are named GL_whatever so they don't get overwritten with stuff
|
||||||
# that happens in the functions sourced.
|
# that happens in the functions sourced.
|
||||||
GL_input="/tmp/percona-toolkit-test"
|
GL_input="/tmp/aspersa"
|
||||||
GL_expected="/tmp/percona-toolkit-test-expected"
|
GL_expected="/tmp/aspersa-reference"
|
||||||
GL_result="/tmp/percona-toolkit-test-result"
|
GL_result="/tmp/aspersa-result"
|
||||||
|
|
||||||
run_test() {
|
run_test() {
|
||||||
t=$1 # test file name, e.g. "group-by-all-01" for pt-diskstats
|
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:
|
# The format of the test file is as follows:
|
||||||
# - line 1 is the shebang
|
# - line 1 is the shebang
|
||||||
# - line 2 is the command to run, commented out
|
# - line 2 is the command to run, commented out
|
||||||
@@ -74,7 +66,24 @@ run_test() {
|
|||||||
result $?
|
result $?
|
||||||
|
|
||||||
# Clean up
|
# 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
|
tool=$1 # bash tool, e.g. pt-diskstats
|
||||||
@@ -87,7 +96,7 @@ cd $BRANCH/bin
|
|||||||
if [ ! -f $tool ]; then
|
if [ ! -f $tool ]; then
|
||||||
die "$tool does not exist"
|
die "$tool does not exist"
|
||||||
fi
|
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 the tool, i.e. import its functions.
|
||||||
source $tool
|
source $tool
|
||||||
@@ -95,14 +104,17 @@ source $tool
|
|||||||
cd $BRANCH/t/$tool
|
cd $BRANCH/t/$tool
|
||||||
testno=1
|
testno=1
|
||||||
failed_tests=0
|
failed_tests=0
|
||||||
|
declare -a tests
|
||||||
if [ -z "$t" ]; then
|
if [ -z "$t" ]; then
|
||||||
# Run all the tool's tests.
|
# Run all the tool's tests.
|
||||||
for t in *; do
|
load_tests *
|
||||||
run_test $t
|
|
||||||
done
|
|
||||||
else
|
else
|
||||||
# Run just the specified test.
|
# Run just the specified test.
|
||||||
run_test $t
|
load_tests $t
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
for t in "${tests[@]}"; do
|
||||||
|
run_test $t
|
||||||
|
done
|
||||||
|
|
||||||
exit $failed_tests
|
exit $failed_tests
|
||||||
|
|||||||
Reference in New Issue
Block a user