Reporting test details for all tests
[samplevnf.git] / VNFs / DPPD-PROX / helper-scripts / trailing.sh
1 #!/bin/bash
2
3 ##
4 ## Copyright (c) 2010-2017 Intel Corporation
5 ##
6 ## Licensed under the Apache License, Version 2.0 (the "License");
7 ## you may not use this file except in compliance with the License.
8 ## You may obtain a copy of the License at
9 ##
10 ##     http://www.apache.org/licenses/LICENSE-2.0
11 ##
12 ## Unless required by applicable law or agreed to in writing, software
13 ## distributed under the License is distributed on an "AS IS" BASIS,
14 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 ## See the License for the specific language governing permissions and
16 ## limitations under the License.
17 ##
18
19 bad_lines=$(grep -nHr -e "[[:space:]]$" *.c *.h gen/*.cfg config/*.cfg)
20
21 if [ -n "$bad_lines" ]; then
22     echo "Found trailing white-spaces:"
23     echo $bad_lines
24     exit 1;
25 fi
26
27 for f in *.c *.h gen/*.cfg config/*.cfg; do
28     result=$(tail -n 1 $f | grep "^$" | wc -l)
29
30     if [ "$result" == "1" ]; then
31         echo "Trailing newlines at end of file $f"
32         exit 1
33     fi
34 done;
35
36 prev="dummy"
37 function findDuplicate() {
38     line=1
39     while read p; do
40         if [ "$prev" == "" ]; then
41             if [ "$p" == "" ]; then
42                 echo "duplicate empty line at $1:$line"
43                 bad=1
44             fi
45         fi
46         prev=$p
47         let "line+=1"
48     done <$1
49 }
50
51 bad=0
52 for f in *.c *.h; do
53     findDuplicate $f
54 done;
55
56 if [ "$bad" != "0" ]; then
57     exit 1
58 fi
59
60 tab="   "
61 bad_lines=$(grep -nHr -e "^$tab$tab$tab$tab$tab$tab$tab" *.c *.h | head -n1)
62
63 if [ -n "$bad_lines" ]; then
64     echo "Code nested too deep:"
65     echo $bad_lines
66     exit 1;
67 fi
68
69 exit 0