test: enhance unit test script with output logging and error handling
This commit is contained in:
parent
c4af33740e
commit
522ef765b2
|
@ -1,5 +1,5 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
# set -x
|
||||||
function usage() {
|
function usage() {
|
||||||
echo "$0"
|
echo "$0"
|
||||||
echo -e "\t -e enterprise edition"
|
echo -e "\t -e enterprise edition"
|
||||||
|
@ -24,24 +24,36 @@ while getopts "e:h" opt; do
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
script_dir=`dirname $0`
|
script_dir=$(dirname "$0")
|
||||||
cd ${script_dir}
|
cd "${script_dir}"
|
||||||
PWD=`pwd`
|
PWD=$(pwd)
|
||||||
|
|
||||||
if [ $ent -eq 0 ]; then
|
if [ $ent -eq 0 ]; then
|
||||||
cd ../../debug
|
cd ../../debug
|
||||||
else
|
else
|
||||||
cd ../../../debug
|
cd ../../../debug
|
||||||
fi
|
fi
|
||||||
|
PWD=$(pwd)
|
||||||
|
echo "PWD: $PWD"
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
pgrep taosd || taosd >> /dev/null 2>&1 &
|
pgrep taosd || taosd >> /dev/null 2>&1 &
|
||||||
|
|
||||||
sleep 10
|
sleep 10
|
||||||
|
|
||||||
ctest -E "cunit_test" -j8
|
# Run ctest and capture output and return code
|
||||||
|
ctest_output="unit-test.log"
|
||||||
|
ctest -E "cunit_test" -j8 2>&1 | tee "$ctest_output"
|
||||||
|
ctest_ret=${PIPESTATUS[0]}
|
||||||
|
|
||||||
ret=$?
|
# Read the captured output
|
||||||
exit $ret
|
ctest_output=$(cat "$ctest_output")
|
||||||
|
|
||||||
|
# Check if ctest failed or no tests were found
|
||||||
|
if [ $ctest_ret -ne 0 ]; then
|
||||||
|
echo "ctest failed, failing the script."
|
||||||
|
exit 1
|
||||||
|
elif echo "$ctest_output" | grep -q "No tests were found"; then
|
||||||
|
echo "No tests were found, failing the script."
|
||||||
|
exit 1
|
||||||
|
fi
|
Loading…
Reference in New Issue