-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestscript.sh
More file actions
58 lines (53 loc) · 1.54 KB
/
Copy pathtestscript.sh
File metadata and controls
58 lines (53 loc) · 1.54 KB
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
# Terminal colors
WHITE="\e[0m"
RED="\e[91m"
GREEN="\e[92m"
YELLOW="\e[93m"
# Checks
echo -e "${YELLOW}(1/4) Checking for newlines at end of all file${WHITE}"
for f in $(git diff-tree --no-commit-id --name-only -M -r HEAD); do
if ([[ $f == *.cpp ]] || [[ $f == *.py ]])
then
if ! [ -z "$(tail -c 1 "$f")" ]
then
echo -e "${RED}No newline at end of file - $f${WHITE}"
exit 1
fi
fi
done
echo -e "${YELLOW}(2/4) Checking for trailing whitespaces${WHITE}"
for f in $(git diff-tree --no-commit-id --name-only -M -r HEAD); do
if ([[ $f == *.cpp ]] || [[ $f == *.py ]])
then
if grep -rli '[[:blank:]]$' $f
then
echo -e "${RED}Trailing whitespaces - $f${WHITE}"
exit 1
fi
fi
done
echo -e "${YELLOW}(3/4) Compiling python files${WHITE}"
for f in $(git diff-tree --no-commit-id --name-only -M -r HEAD); do
if [[ $f == *.py ]]
then
echo "Compiling - $f"
if ! python3 -c "import py_compile; py_compile.compile('$f', doraise=True)"
then
echo -e "${RED}Error compiling file - $f${WHITE}"
exit 1
fi
fi
done
echo -e "${YELLOW}(4/4) Compiling C++ files${WHITE}"
for f in $(git diff-tree --no-commit-id --name-only -M -r HEAD); do
if [[ $f == *.cpp ]]
then
echo "Compiling - $f"
if ! g++ -pipe -Wfatal-errors $f
then
echo -e "${RED}Error compiling file - $f${WHITE}"
exit 1
fi
fi
done
echo -e "${GREEN}Sucessfully done ${WHITE}"