Fix clang-format version checking

This commit is contained in:
Petri Lehtinen
2019-10-21 07:33:12 +03:00
parent f912430cda
commit bb4f99e919
2 changed files with 12 additions and 12 deletions

View File

@@ -1,21 +1,19 @@
#!/bin/bash
clangformat="clang-format"
if [ -n "$1" ]; then
clangformat="clang-format-$1"
fi
CLANG_FORMAT=${CLANG_FORMAT:-clang-format}
CLANG_FORMAT_VERSION=${CLANG_FORMAT_VERSION:-}
if ! type $clangformat >/dev/null; then
# clang-format not found. If running tests, mark this test as
# skipped.
if ! type $CLANG_FORMAT >/dev/null || \
! $CLANG_FORMAT --version | grep -q "version ${CLANG_FORMAT_VERSION}"; then
# If running tests, mark this test as skipped.
exit 77
fi
errors=0
paths=$(find . -type f -a '(' -name '*.c' -o -name '*.h' ')')
paths=$(git ls-files | grep '\.[ch]$')
for path in $paths; do
in=$(cat $path)
out=$($clangformat $path)
out=$($CLANG_FORMAT $path)
if [ "$in" != "$out" ]; then
diff -u -L $path -L "$path.formatted" $path - <<<$out