aboutsummaryrefslogtreecommitdiffstats
path: root/ci/test_format.sh
blob: 502c84c5837b137ae13eacf191eb41adc5835d73 (plain)
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
#!/bin/bash
echo "clang-format - checking Code Formatting..."

if [[ "${TRAVIS_OS_NAME}" == "linux" ]] && \
   [[ "${TEST_CLANG_FORMAT}" == "yes" ]]; then

    RETURN=0
    CLANG_FORMAT="clang-format-3.9"

    which clang-format-3.9

    if [ ! -f ".clang-format" ]; then
        echo ".clang-format file not found!"
        exit 1
    fi

    FILES=`git diff master --name-only | grep -E "\.(cc|cpp|h)$"`

    for FILE in $FILES; do

        $CLANG_FORMAT $FILE | cmp  $FILE >/dev/null

        if [ $? -ne 0 ]; then
            echo "[!] Clang-Format Found INCORRECT FORMATTING. Please re-format and re-submit.  The following file failed: $FILE" >&2
            RETURN=1
        fi

    done

    exit $RETURN
fi

exit 0