-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.sh
executable file
·62 lines (55 loc) · 2.02 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
#!/bin/bash
USUAL_COLOR='\033[0;32m'
FAILURE_COLOR='\033[0;31m'
NEUTRAL_COLOR='\033[0;33m'
NO_COLOR='\033[0m'
BIN_DIRECTORY="./build"
TEST_ARGUMENTS="" # Arguments to pass on to each test binary, such as -q, -s, -v, -e, or -i
if [ $# -ne 0 ] && [[ $1 == -* ]]; then
TEST_ARGUMENTS="$1"
shift
fi
if [ $# -eq 0 ]; then
ALL_EXECUTABLES_TEMP="$(find "${BIN_DIRECTORY}" -maxdepth 1 -type f -name "test_*")"
ALL_EXECUTABLES=""
for EXECUTABLE in $ALL_EXECUTABLES_TEMP
do
ALL_EXECUTABLES="${ALL_EXECUTABLES} ${EXECUTABLE#"${BIN_DIRECTORY}/test_"}"
done
if [ -z "$ALL_EXECUTABLES" ]; then
echo -e "${FAILURE_COLOR}No test executable name to test provided, and none in test folder.${NO_COLOR}"
exit 1
fi
else
ALL_EXECUTABLES="$@"
fi
if [ "$1" = "-h" ]; then
echo -e "Runs through each provided test."
echo -e "Tests are provided through command line arguments, being the name of any test executable, minus the 'test_' prefix.\n"
echo -e "Example : ./tests.sh [dash-args (-q|-v|-s|-e|-i)] tinytest1"
echo -e "\tWill run the executable '$BIN_DIRECTORY/test_tinytest1'"
echo -e "If no name is provided, will run every test in the test directory."
echo -e "The dash-args (-q, -v, -s, -e, -i) will be passed to each test, and correspond to TinyTest command line arguments."
exit 0
fi
# Goes through each test provided through the command line
for EXECUTABLE in $ALL_EXECUTABLES
do
# Runs the test
echo -e "${USUAL_COLOR}Running tests of project '${NEUTRAL_COLOR}${EXECUTABLE}${USUAL_COLOR}'${NO_COLOR}"
"$BIN_DIRECTORY/test_$EXECUTABLE" $TEST_ARGUMENTS
EXIT_CODE=$?
if [ $EXIT_CODE == 0 ]
then
echo -e "${USUAL_COLOR}Program exited with code $EXIT_CODE${NO_COLOR}"
else
echo -e "${NEUTRAL_COLOR}Program exited with code ${FAILURE_COLOR}$EXIT_CODE${NO_COLOR}"
fi
if [ $EXIT_CODE == 139 ]
then
echo -e "${FAILURE_COLOR}Program crashed. Cleaning terminal...${NO_COLOR}"
read -n 1 -s
stty sane
clear
fi
done