From b583e58d0f78f4564f26df9f2688da30ff0a0cff Mon Sep 17 00:00:00 2001
From: ralfulrich <ralf.ulrich@kit.edu>
Date: Mon, 20 May 2019 22:15:46 +0200
Subject: [PATCH] also run clang-format checking automatically as unit test

---
 CMakeLists.txt     |  5 ++++-
 do-clang-format.sh | 11 ++++++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 693c1625..c3e85793 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -108,9 +108,12 @@ if (CMAKE_BUILD_TYPE STREQUAL Coverage)
   add_custom_target(coverage DEPENDS coverage-report)
 endif ()
 
-# add call to do-interaction to run as unit-test-case
+# add call to ./do-copyright.py to run as unit-test-case
 add_test (NAME copyright_notices COMMAND "./do-copyright.py" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
 
+# add call to do-clang-format.sh checking to run as unit-test-case
+add_test (NAME clang_format COMMAND ./do-clang-format.sh check WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
+
 find_package (Pythia8) # optional
 find_package (Eigen3 REQUIRED)
 
diff --git a/do-clang-format.sh b/do-clang-format.sh
index c7680e48..ebfcb232 100755
--- a/do-clang-format.sh
+++ b/do-clang-format.sh
@@ -1 +1,10 @@
-clang-format -i -style=file `find . -iregex '^.*\.\(cc\|h\)$' -not -path './ThirdParty/*'`
+#!/bin/bash
+
+command="clang-format -style=file `find . -iregex '^.*\.\(cc\|h\)$' -not -path './ThirdParty/*'`"
+
+if [ "$1" == "check" ];
+then
+    ! ${command}  -output-replacements-xml | grep -c "<replacement " 
+else
+    ${command} -i
+fi
-- 
GitLab