-
Notifications
You must be signed in to change notification settings - Fork 214
/
Copy pathcppclean.sh
executable file
·54 lines (53 loc) · 2.36 KB
/
cppclean.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
#
# Copyright 2022 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
CPPCLEAN_RESULTS_FILE_SRC="cppclean_src"
CPPCLEAN_RESULTS_FILE_TEST="cppclean_test"
cppclean ./src/ 2>&1 | grep -v test > ${CPPCLEAN_RESULTS_FILE_SRC};
cppclean ./src/ 2>&1 | grep test > ${CPPCLEAN_RESULTS_FILE_TEST};
NO_WARNINGS=$(wc -l ${CPPCLEAN_RESULTS_FILE_SRC} | awk '{print $1}')
NO_WARNINGS_TEST=$(wc -l ${CPPCLEAN_RESULTS_FILE_TEST} | awk '{print $1}')
NO_WARNINGS_FORWARD=$(grep "use a forward declaration instead" ${CPPCLEAN_RESULTS_FILE_SRC} | wc -l)
NO_WARNINGS_DIRECT=$(grep "not found in any directly #included header" ${CPPCLEAN_RESULTS_FILE_SRC} | wc -l)
NO_WARNINGS_NOTUSED=$(grep " not used$" ${CPPCLEAN_RESULTS_FILE_SRC} | wc -l)
echo "Number of warnings:" ${NO_WARNINGS}
echo "Number of warnings in tests:" ${NO_WARNINGS_TEST}
echo "Number of warnings about not using forward delares:" ${NO_WARNINGS_FORWARD}
echo "Number of warnings about not direct includes:" ${NO_WARNINGS_DIRECT}
echo "Number of warnings about not used: " ${NO_WARNINGS_NOTUSED}
trap "cat ${CPPCLEAN_RESULTS_FILE_SRC}" err exit
if [ ${NO_WARNINGS_FORWARD} -gt 6 ]; then
echo "Failed due to not using forward declarations where possible: ${NO_WARNINGS_FORWARD}";
exit 1;
fi
if [ ${NO_WARNINGS_DIRECT} -gt 14 ]; then
echo "Failed probably due to not using static keyword with functions definitions: ${NO_WARNINGS_DIRECT}";
exit 1;
fi
if [ ${NO_WARNINGS_NOTUSED} -gt 3 ]; then
echo "Failed probably due to unnecessary forward includes: ${NO_WARNINGS_NOTUSED}";
exit 1;
fi
if [ ${NO_WARNINGS} -gt 187 ]; then
echo "Failed due to higher than allowed number of issues in code: ${NO_WARNINGS}"
exit 1
fi
if [ ${NO_WARNINGS_TEST} -gt 128 ]; then
echo "Failed due to higher than allowed number of issues in test code: ${NO_WARNINGS_TEST}"
cat ${CPPCLEAN_RESULTS_FILE_TEST}
exit 1
fi
exit 0