2014-01-14 06:29:14 +00:00
|
|
|
#! /bin/bash
|
2009-09-14 01:07:32 +00:00
|
|
|
|
2023-05-24 04:04:08 +00:00
|
|
|
unset NO_COLOR
|
|
|
|
|
2009-09-14 01:07:32 +00:00
|
|
|
top_srcdir="@abssrcdir@"
|
|
|
|
export top_srcdir
|
|
|
|
|
2022-08-04 16:22:09 +00:00
|
|
|
top_srcdir_parent=`dirname ${top_srcdir}`
|
|
|
|
export top_srcdir_parent
|
|
|
|
|
2014-03-15 11:40:58 +00:00
|
|
|
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`
|
2014-03-02 16:55:00 +00:00
|
|
|
export top_builddir
|
2009-09-14 01:07:32 +00:00
|
|
|
|
2021-10-03 06:03:23 +00:00
|
|
|
builddir=`pwd -P`
|
2020-10-29 04:17:57 +00:00
|
|
|
export builddir
|
|
|
|
|
2014-03-02 16:55:00 +00:00
|
|
|
test_dir="@abssrcdir@/test"
|
|
|
|
export test_dir
|
2009-09-14 01:07:32 +00:00
|
|
|
|
2015-03-28 08:25:09 +00:00
|
|
|
# Let the tests know whether bzip is supported or not.
|
|
|
|
BZIP2_SUPPORT="@BZIP2_SUPPORT@"
|
|
|
|
export BZIP2_SUPPORT
|
|
|
|
|
2014-03-15 11:40:58 +00:00
|
|
|
BZIP2_CMD="@BZIP2_CMD@"
|
|
|
|
export BZIP2_CMD
|
|
|
|
|
2021-01-11 06:04:55 +00:00
|
|
|
XZ_CMD="@XZ_CMD@"
|
|
|
|
export XZ_CMD
|
|
|
|
|
2021-11-05 22:13:16 +00:00
|
|
|
TSHARK_CMD="@TSHARK_CMD@"
|
|
|
|
export TSHARK_CMD
|
|
|
|
|
2020-10-29 04:17:57 +00:00
|
|
|
LIBARCHIVE_LIBS="@LIBARCHIVE_LIBS@"
|
|
|
|
export LIBARCHIVE_LIBS
|
|
|
|
|
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
|
|
|
|
|
2024-05-01 05:04:18 +00:00
|
|
|
HOME="${top_builddir}/test/cfg/${test_file_base}"
|
|
|
|
export HOME
|
|
|
|
|
|
|
|
rm -rf "${top_builddir}/test/cfg/${test_file_base}"
|
|
|
|
mkdir -p ${HOME}
|
|
|
|
|
2022-04-30 20:05:42 +00:00
|
|
|
test_hash=""
|
|
|
|
|
2014-04-18 12:17:24 +00:00
|
|
|
lnav_test="${top_builddir}/src/lnav-test"
|
|
|
|
export lnav_test
|
|
|
|
|
2015-08-02 13:43:57 +00:00
|
|
|
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
|
|
|
|
|
2015-08-02 13:43:57 +00:00
|
|
|
SFTP_TEST_URL="@SFTP_TEST_URL@"
|
|
|
|
export SFTP_TEST_URL
|
|
|
|
|
2015-12-10 05:20:49 +00:00
|
|
|
HAVE_SQLITE3_VALUE_SUBTYPE="@HAVE_SQLITE3_VALUE_SUBTYPE@"
|
|
|
|
export HAVE_SQLITE3_VALUE_SUBTYPE
|
|
|
|
|
2022-07-08 22:55:53 +00:00
|
|
|
HAVE_SQLITE3_ERROR_OFFSET="@HAVE_SQLITE3_ERROR_OFFSET@"
|
|
|
|
export HAVE_SQLITE3_ERROR_OFFSET
|
|
|
|
|
2009-09-14 01:07:32 +00:00
|
|
|
## BEGIN Functions
|
|
|
|
|
|
|
|
LAST_TEST=""
|
|
|
|
|
2022-04-30 20:05:42 +00:00
|
|
|
LAST_CAP_TEST=()
|
|
|
|
|
|
|
|
has_errors=""
|
|
|
|
|
2009-09-14 01:07:32 +00:00
|
|
|
#
|
|
|
|
# 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() {
|
2022-04-30 20:05:42 +00:00
|
|
|
printf "%s \033[0;35m=============================================================\033[0m\n" $(date -Iseconds)
|
|
|
|
LAST_TEST=("test: $@")
|
|
|
|
echo "${LAST_TEST[@]}"
|
2021-05-26 05:27:09 +00:00
|
|
|
export test_num=`expr ${test_num} \+ 1`
|
2014-03-03 00:52:18 +00:00
|
|
|
"$@" > ${test_file_base}_${test_num}.tmp 2> ${test_file_base}_${test_num}.err
|
2009-09-14 01:07:32 +00:00
|
|
|
}
|
|
|
|
|
2022-04-30 20:05:42 +00:00
|
|
|
run_cap_test() {
|
|
|
|
LAST_CAP_TEST=("test: $@")
|
2022-07-23 06:37:25 +00:00
|
|
|
local full_cmd=$(echo "${LAST_CAP_TEST[@]}" | sed -e "s;${test_dir};{test_dir};g" -e "s;${top_srcdir};{top_srcdir};g")
|
2022-05-01 01:38:39 +00:00
|
|
|
export test_hash=$(echo "${full_cmd}" | shasum | cut -f 1 -d ' ')
|
|
|
|
echo "${full_cmd}" > ${test_file_base}_${test_hash}.cmd
|
2022-04-30 20:05:42 +00:00
|
|
|
"$@" > ${test_file_base}_${test_hash}.out 2> ${test_file_base}_${test_hash}.err
|
|
|
|
|
|
|
|
sed -ibak \
|
|
|
|
-e "s;${test_dir};{test_dir};g" \
|
2022-08-06 20:46:50 +00:00
|
|
|
-e "s;${builddir};{test_dir};g" \
|
2022-04-30 20:05:42 +00:00
|
|
|
-e "s;${top_srcdir};{top_srcdir};g" \
|
2022-08-04 16:22:09 +00:00
|
|
|
-e "s;${top_srcdir_parent};{top_srcdir_parent};g" \
|
2023-07-19 12:41:13 +00:00
|
|
|
-e "s;lnav-user-${UID}-work;lnav-user-{uid}-work;g" \
|
2022-04-30 20:05:42 +00:00
|
|
|
${test_file_base}_${test_hash}.out
|
|
|
|
echo
|
|
|
|
printf "%s \033[0;35m=============================================================\033[0m\n" $(date -Iseconds)
|
|
|
|
printf '\033[0;35mCommand\033[0m: %s\n' "${full_cmd}"
|
|
|
|
printf '\033[0;32mBEGIN\033[0m %s\n' "${test_file_base}_${test_hash}.out"
|
|
|
|
cat "${test_file_base}_${test_hash}.out"
|
|
|
|
printf '\033[0;32mEND\033[0m %s\n' "${test_file_base}_${test_hash}.out"
|
|
|
|
if test -f ${srcdir}/expected/${test_file_base}_${test_hash}.out; then
|
|
|
|
diff -w -u \
|
|
|
|
${srcdir}/expected/${test_file_base}_${test_hash}.out \
|
|
|
|
${test_file_base}_${test_hash}.out \
|
|
|
|
> ${test_file_base}_${test_hash}.diff
|
|
|
|
if test $? -ne 0; then
|
|
|
|
echo OUT: "${full_cmd}"
|
|
|
|
cat ${test_file_base}_${test_hash}.diff
|
2022-04-30 21:42:21 +00:00
|
|
|
echo "FAIL! EXPECTED OUT DIFF"
|
2022-04-30 20:05:42 +00:00
|
|
|
export has_errors="yes"
|
|
|
|
fi
|
|
|
|
else
|
2022-09-22 17:54:09 +00:00
|
|
|
echo "FAIL! EXPECTED OUT MISSING -- ${srcdir}/expected/${test_file_base}_${test_hash}.out"
|
2022-04-30 20:05:42 +00:00
|
|
|
export has_errors="yes"
|
|
|
|
fi
|
|
|
|
|
|
|
|
sed -ibak -E \
|
|
|
|
-e "s;${test_dir};{test_dir};g" \
|
2022-05-01 04:15:15 +00:00
|
|
|
-e "s;${builddir};{builddir};g" \
|
2022-04-30 20:05:42 +00:00
|
|
|
-e "s;${top_srcdir};{top_srcdir};g" \
|
2023-07-19 12:41:13 +00:00
|
|
|
-e "s;lnav-user-${UID}-work;lnav-user-{uid}-work;g" \
|
2022-04-30 20:05:42 +00:00
|
|
|
-e 's;"errorId":".+";;g' \
|
|
|
|
${test_file_base}_${test_hash}.err
|
|
|
|
printf '\033[0;31mBEGIN\033[0m %s\n' "${test_file_base}_${test_hash}.err"
|
|
|
|
cat "${test_file_base}_${test_hash}.err"
|
|
|
|
printf '\033[0;31mEND\033[0m %s\n' "${test_file_base}_${test_hash}.err"
|
|
|
|
if test -f ${srcdir}/expected/${test_file_base}_${test_hash}.err; then
|
|
|
|
diff -w -u ${srcdir}/expected/${test_file_base}_${test_hash}.err \
|
|
|
|
${test_file_base}_${test_hash}.err \
|
|
|
|
> ${test_file_base}_${test_hash}.err.diff
|
|
|
|
if test $? -ne 0; then
|
|
|
|
echo ERR: "${full_cmd}"
|
|
|
|
cat ${test_file_base}_${test_hash}.err.diff
|
2022-04-30 21:42:21 +00:00
|
|
|
echo "FAIL! EXPECTED ERR DIFF"
|
2022-04-30 20:05:42 +00:00
|
|
|
export has_errors="yes"
|
|
|
|
fi
|
|
|
|
else
|
2022-04-30 21:42:21 +00:00
|
|
|
echo "FAIL! EXPECTED ERR MISSING"
|
2022-04-30 20:05:42 +00:00
|
|
|
export has_errors="yes"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
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
|
2015-04-11 02:50:05 +00:00
|
|
|
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
|
2022-04-30 20:05:42 +00:00
|
|
|
echo "${LAST_TEST[@]}"
|
2014-03-02 16:55:00 +00:00
|
|
|
echo $1
|
2013-05-29 16:06:52 +00:00
|
|
|
cat ${test_file_base}_${test_num}.diff
|
2014-03-03 00:52:18 +00:00
|
|
|
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
|
2022-04-30 20:05:42 +00:00
|
|
|
echo "${LAST_TEST[@]}"
|
2015-12-25 20:03:44 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2015-07-11 23:32:48 +00:00
|
|
|
test_err_filename() {
|
|
|
|
echo ${test_file_base}_${test_num}.err
|
|
|
|
}
|
|
|
|
|
2014-03-03 00:52:18 +00:00
|
|
|
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
|
2015-04-11 02:50:05 +00:00
|
|
|
diff -w -u - ${test_file_base}_${test_num}.err \
|
2014-03-03 00:52:18 +00:00
|
|
|
> ${test_file_base}_${test_num}.err.diff
|
|
|
|
if test $? -ne 0; then
|
2022-04-30 20:05:42 +00:00
|
|
|
echo "${LAST_TEST[@]}"
|
2014-03-03 00:52:18 +00:00
|
|
|
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.
|
|
|
|
#
|
2021-08-25 11:20:38 +00:00
|
|
|
# Usage: grep_output_for <string> <fail message>
|
2009-09-14 01:07:32 +00:00
|
|
|
#
|
|
|
|
# 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
|
2021-01-08 22:08:52 +00:00
|
|
|
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
|
2022-04-30 20:05:42 +00:00
|
|
|
|
|
|
|
cleanup() {
|
|
|
|
if test "${has_errors}"x = "yes"x; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
trap "cleanup" EXIT
|