Skip to content

Commit

Permalink
Add ctest for style, using clang-format
Browse files Browse the repository at this point in the history
When user touches a file, that file will be fed to `git clang-format`,
and if the tool reports a new diff it will consider the test failed. The
files to check will be anything in the current workspace compared to
origin/master.
  • Loading branch information
Brenden Blanco committed Apr 19, 2016
1 parent af8552b commit 581fc7d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion scripts/git-clang-format
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python2
#
#===- git-clang-format - ClangFormat Git Integration ---------*- python -*--===#
#
Expand Down
25 changes: 25 additions & 0 deletions scripts/style-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

# Runs clang-format on the files changed between HEAD and $1, which defaults to
# origin/master.

# to pick up git-clang-format from scripts/
export PATH=$(dirname $0):$PATH

CLANG_FORMAT=${CLANG_FORMAT:-clang-format}
GITREF=${1:-origin/master}

if ! hash $CLANG_FORMAT 2> /dev/null; then
echo "Could not find clang-format tool" 1>&2
exit 1
fi

n=$(git clang-format $GITREF --binary $CLANG_FORMAT --style llvm --diff --quiet | wc -l)
if [ $n -gt 0 ]; then
echo "git clang-format $GITREF --binary $CLANG_FORMAT --style llvm --diff"
echo
git clang-format $GITREF --binary $CLANG_FORMAT --style llvm --diff
echo
echo "clang-format returned non-empty diff, please fixup the style" 1>&2
exit 1
fi
2 changes: 2 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ configure_file(wrapper.sh.in "${CMAKE_CURRENT_BINARY_DIR}/wrapper.sh" @ONLY)

set(TEST_WRAPPER ${CMAKE_CURRENT_BINARY_DIR}/wrapper.sh)

add_test(NAME style-check COMMAND ${CMAKE_SOURCE_DIR}/scripts/style-check.sh)

add_subdirectory(cc)
add_subdirectory(python)
add_subdirectory(lua)

0 comments on commit 581fc7d

Please sign in to comment.