-
Notifications
You must be signed in to change notification settings - Fork 9
/
test-cpp-compile.sh
executable file
·54 lines (40 loc) · 1023 Bytes
/
test-cpp-compile.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
#!/bin/bash
set -f
IFS=$'\n';
GIT_ROOT_DIR=`git rev-parse --show-toplevel`
CHECK_DIR=`./`
if [ $# == 1 ]
then
CHECK_DIR=$1
if [ ! -d "$1" ]; then
echo "Directory '$1' does not exist."
exit 0
fi
fi
CPP_FILES=`find $CHECK_DIR -name '*.cpp'`
if ! command -v uuidgen &> /dev/null
then
TEST_PROG_FILE=`head /dev/urandom | tr -dc A-Za-z0-9 | head -c 10 ; echo ''`
else
TEST_PROG_FILE=`uuidgen`
fi
TEST_EXIT_STATUS=0
echo "Checking if all *.cpp files compiles successfully 🙃 inside $CHECK_DIR directory"
for path in $CPP_FILES
do
# To support programs using pthread we add flag
# TODO: Use pthread flag only when required
EXTRA_ARGS="-std=c++17"
HEADER_PATH="-I$GIT_ROOT_DIR/Templates"
g++ $EXTRA_ARGS $HEADER_PATH -o $TEST_PROG_FILE $path -pthread
if [ -f $TEST_PROG_FILE ];
then
echo "$path: ✅"
rm $TEST_PROG_FILE
else
echo "$path: ❌"
TEST_EXIT_STATUS=1
fi
done
unset IFS; set +f
exit $TEST_EXIT_STATUS