-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.sh
executable file
·92 lines (76 loc) · 1.97 KB
/
test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/bash
# Test script for the ${{VAR_PROJECT_NAME}} application.
USAGE="Usage: test.sh [options]";
HELP_TEXT=$(cat << EOS
Tests the ${{VAR_PROJECT_NAME}} application.
${USAGE}
Options:
${{VAR_SCRIPT_TEST_ISOLATED_OPT}}
[-?|--help] Show this help message.
EOS
)
# Arg flags
${{VAR_SCRIPT_BUILD_ISOLATED_ARGFLAG}}
ARG_SHOW_HELP=false;
${{VAR_SCRIPT_BUILD_ISOLATED_ARGARRAY}}
# Parse all arguments given to this script
for arg in "$@"; do
case $arg in
${{VAR_SCRIPT_BUILD_ISOLATED_ARGPARSE}}
-\?|--help)
ARG_SHOW_HELP=true;
shift
;;
*)
# Unknown Argument
echo "Unknown argument: '$arg'";
echo "$USAGE";
echo "";
echo "Run 'test.sh --help' for more information";
exit 1;
;;
esac
done
# Check if help is triggered
if [[ $ARG_SHOW_HELP == true ]]; then
echo "$HELP_TEXT";
exit 0;
fi
# Need to prematurely create the build dir if it does not exist
# so it can be used as a volume by Docker when using
# an isolated test execution
if ! [ -d "build" ]; then
mkdir "build";
fi
${{VAR_SCRIPT_TEST_ISOLATED_MAIN}}
# Ensure the required executables are available
if ! command -v "cmake" &> /dev/null; then
echo "ERROR: Could not find the 'cmake' executable.";
echo "ERROR: Please make sure that CMake is correctly installed";
exit 1;
fi
if ! command -v "ctest" &> /dev/null; then
echo "ERROR: Could not find the 'ctest' executable.";
echo "ERROR: Please make sure that CMake and CTest are correctly installed";
exit 1;
fi
# Check if the build dir is empty
if [ -z "$(ls -A build)" ]; then
# Build the tests first
echo "Building project before test run execution";
bash build.sh;
if (( $? != 0 )); then
exit $?;
fi
fi
cd "build";
if (( $? != 0 )); then
exit $?;
fi
# By default, GTest does not use colourful output when logging
# the test results to a file. But as we also show the tests
# in a terminal, we explicitly activate colourful output.
export GTEST_COLOR=1;
# Run tests with CTest
ctest --output-on-failure;
exit $?;