lnav/TESTS_ENVIRONMENT.in

191 lines
4.0 KiB
Plaintext
Raw Normal View History

2014-01-14 06:29:14 +00:00
#! /bin/bash
2009-09-14 01:07:32 +00:00
top_srcdir="@abssrcdir@"
export top_srcdir
srcdir="@abssrcdir@/test"
export srcdir
2009-09-14 01:07:32 +00:00
# The top build directory, derived from the path to this script.
top_builddir=`dirname $0`
export top_builddir
2009-09-14 01:07:32 +00:00
builddir=`pwd`
export builddir
test_dir="@abssrcdir@/test"
export test_dir
2009-09-14 01:07:32 +00:00
# Let the tests know whether bzip is supported or not.
BZIP2_SUPPORT="@BZIP2_SUPPORT@"
export BZIP2_SUPPORT
BZIP2_CMD="@BZIP2_CMD@"
export BZIP2_CMD
2021-01-11 06:04:55 +00:00
XZ_CMD="@XZ_CMD@"
export XZ_CMD
LIBARCHIVE_LIBS="@LIBARCHIVE_LIBS@"
export LIBARCHIVE_LIBS
HOME="${top_builddir}/test"
export HOME
2009-09-14 01:07:32 +00:00
# The full path of the test case
test_file=$1
# The base name of the test case
test_file_base=`basename $1`
# The current test number for shell based tests.
test_num=0
2014-04-18 12:17:24 +00:00
lnav_test="${top_builddir}/src/lnav-test"
export lnav_test
lnav="${top_builddir}/src/lnav"
export lnav
2014-05-05 13:44:58 +00:00
LNAV_LOG_PATH="${top_builddir}/test/test.log"
export LNAV_LOG_PATH
SFTP_TEST_URL="@SFTP_TEST_URL@"
export SFTP_TEST_URL
HAVE_SQLITE3_VALUE_SUBTYPE="@HAVE_SQLITE3_VALUE_SUBTYPE@"
export HAVE_SQLITE3_VALUE_SUBTYPE
2009-09-14 01:07:32 +00:00
## BEGIN Functions
LAST_TEST=""
#
# Run a test case and capture its standard out and standard err.
#
# Usage: run_test <utility> [<argument> ...]
#
# Example:
#
# To run rktimes and capture all of its stdio output:
#
# run_test rktimes -V
#
run_test() {
LAST_TEST="test: $@"
2021-05-26 05:27:09 +00:00
export test_num=`expr ${test_num} \+ 1`
"$@" > ${test_file_base}_${test_num}.tmp 2> ${test_file_base}_${test_num}.err
2009-09-14 01:07:32 +00:00
}
#
# Check the output generated by a run_test() call.
#
# Usage: check_output <fail message> {Expected output on stdin}
#
# Example:
#
# To check the output of 'rktimes -V' and print out 'Unable to get version?'
# if the output doesn't match:
#
# run_test rktimes -V
# check_output "Unable to get version?" <<EOF
# 0.5
# EOF
#
check_output() {
2021-06-07 15:59:24 +00:00
sed -ibak \
2021-05-26 05:27:09 +00:00
-e "s;${test_dir};{test_dir};g" \
-e "s;${top_srcdir};{top_srcdir};g" \
${test_file_base}_${test_num}.tmp
diff -w -u - ${test_file_base}_${test_num}.tmp > ${test_file_base}_${test_num}.diff
2009-09-14 01:07:32 +00:00
if test $? -ne 0; then
echo $LAST_TEST
echo $1
cat ${test_file_base}_${test_num}.diff
exit 1
2009-09-14 01:07:32 +00:00
fi
}
2015-12-25 20:03:44 +00:00
check_output_ws() {
diff -u - ${test_file_base}_${test_num}.tmp > ${test_file_base}_${test_num}.diff
if test $? -ne 0; then
echo $LAST_TEST
echo $1
cat ${test_file_base}_${test_num}.diff
exit 1
fi
}
2021-01-31 22:41:24 +00:00
test_filename() {
echo ${test_file_base}_${test_num}.tmp
}
test_err_filename() {
echo ${test_file_base}_${test_num}.err
}
check_error_output() {
2021-06-07 15:59:24 +00:00
sed -ibak \
2021-05-26 05:27:09 +00:00
-e "s;${test_dir};{test_dir};g" \
-e "s;${top_srcdir};{top_srcdir};g" \
${test_file_base}_${test_num}.err
diff -w -u - ${test_file_base}_${test_num}.err \
> ${test_file_base}_${test_num}.err.diff
if test $? -ne 0; then
echo $LAST_TEST
echo $1
cat ${test_file_base}_${test_num}.err.diff
exit 1
fi
}
2009-09-14 01:07:32 +00:00
#
# Grep for a string in the output generated by a run_test() call.
#
# Usage: grep_output_for <string> <fail maessage>
#
# Example:
#
# To check the output of 'cbhey -l' for 'IDL:Foobar:1.0' and print out
# 'Unable to list supported interfaces?' if it is not found:
#
# run_test cbhey -l
# grep_output_for "IDL:Foobar:1.0" "Unable to list supported interface?"
#
grep_output_for() {
if grep -q $1 ${test_file_base}_${test_num}.tmp > /dev/null 2>&1; then
:
else
echo "${test_file_base}_${test_num}.tmp: $2"
exit 1
fi
}
2021-02-06 00:04:34 +00:00
on_error_log() {
if test $? -ne 0; then
echo $1 > /dev/stderr
cat ${test_file_base}_${test_num}.tmp
cat ${test_file_base}_${test_num}.err
fi
}
2009-09-14 01:07:32 +00:00
on_error_fail_with() {
if test $? -ne 0; then
echo $1 > /dev/stderr
cat ${test_file_base}_${test_num}.tmp
cat ${test_file_base}_${test_num}.err
2009-09-14 01:07:32 +00:00
exit 1
fi
}
## END Functions
# Finally, run the test...
if test -x $1 && test `basename $1 .sh` == `basename $1`; then
exec $*
else
# Shell script
shift
. ${test_file}
fi