-
Notifications
You must be signed in to change notification settings - Fork 5
/
42ShellTester.sh
122 lines (110 loc) · 2.62 KB
/
42ShellTester.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/bin/bash
# /*
# Launcher
# */
get_install_directory()
{
local SOURCE="${BASH_SOURCE[0]}"
local DIR
while [ -h "${SOURCE}" ]
do
DIR="$(cd -P "$(dirname "${SOURCE}")" && pwd)"
SOURCE="$(readlink "${SOURCE}")"
[[ "${SOURCE}" != /* ]] && SOURCE="${DIR}/${SOURCE}"
done
printf "%s" "$(cd -P "$(dirname "${SOURCE}")" && pwd)"
}
# global variables
GLOBAL_PROG=""
GLOBAL_PROG_REFERENCE=""
GLOBAL_SPECS_FILTER=""
GLOBAL_ENTRYPATH=$(pwd)
GLOBAL_INSTALLDIR="$(get_install_directory)"
GLOBAL_TMP_DIRECTORY="${GLOBAL_INSTALLDIR}/tmp"
GLOBAL_LOCALBRANCH=$(git branch | awk '$0 ~ /^\*/ {print $2; exit}')
GLOBAL_TOKEN="TOKEN$(date +%Y%m%d%H%M)"
GLOBAL_TOTAL_TESTS=0
GLOBAL_TOTAL_FAILED_TESTS=0
GLOBAL_TOTAL_PENDING_TESTS=0
GLOBAL_LOG=""
GLOBAL_SHOW_SUCCESS=0
GLOBAL_RUN_POSIX_ONLY=0
GLOBAL_RUN_PENDING_TESTS=0
GLOBAL_RUN_HARD_TESTS=0
GLOBAL_RUN_ALL_TESTS=0
GLOBAL_INVALID_OPTION=0
C_BOLD="\033[37;1m"
C_RED="\033[31m\033[38;5;160m"
C_GREEN="\033[31m\033[38;5;34m"
C_YELLOW="\033[31m\033[1;33m"
C_GREY="\033[38;5;239m"
C_CLEAR="\033[0m"
# retrieve options
while [ ! -z "${1}" ]; do
if [[ "${1}" =~ ^-- ]]
then
case "${1}" in
"--reference")
shift 1
GLOBAL_PROG_REFERENCE="$(which ${1})"
;;
"--filter")
shift 1
GLOBAL_SPECS_FILTER="${1}"
;;
"--show-success")
GLOBAL_SHOW_SUCCESS=1
;;
"--pending")
GLOBAL_RUN_PENDING_TESTS=1
;;
"--posix")
GLOBAL_RUN_POSIX_ONLY=1
;;
"--hard")
GLOBAL_RUN_HARD_TESTS=1
;;
"--all")
GLOBAL_RUN_ALL_TESTS=1
;;
*)
printf "%s\n" "Invalid option: ${1}"
exit 1
;;
esac
else
if [ "${GLOBAL_PROG}" == "" ]
then
[[ "${1}" =~ ^[\.][\.]\/ ]] && GLOBAL_PROG="../${1}" || GLOBAL_PROG="$(which ${1})"
fi
fi
shift 1
done
# go to install directory
cd "${GLOBAL_INSTALLDIR}"
# load application sources
for FILE in ./lib/* ./lib/verbs/*
do
if [ -f "${FILE}" ]
then
source "${FILE}"
fi
done
# create and go to temporary directory
mkdir -p "${GLOBAL_TMP_DIRECTORY}"
cd "${GLOBAL_TMP_DIRECTORY}"
# compile support binaries
make re -C "${GLOBAL_INSTALLDIR}/support/" TARGET_DIR=${GLOBAL_TMP_DIRECTORY} 1>- 2>-
# run main function
run_main
# display log
printf "%s\n\nTotal tests: %s\nTotal failed tests: %s\nTotal pending tests: %s\n" "${GLOBAL_LOG}" "${GLOBAL_TOTAL_TESTS}" "${GLOBAL_TOTAL_FAILED_TESTS}" "${GLOBAL_TOTAL_PENDING_TESTS}"
# go back to entry directory
cd "${GLOBAL_ENTRYPATH}"
# exit with success or error status
if [ "${GLOBAL_TOTAL_FAILED_TESTS}" == "0" ]
then
exit 0
else
exit 1
fi