tests: introduce test-checkstyle-diff 57/31757/2
authorKlement Sekera <ksekera@cisco.com>
Wed, 24 Mar 2021 22:24:52 +0000 (23:24 +0100)
committerOle Tr�an <otroan@employees.org>
Thu, 25 Mar 2021 09:22:52 +0000 (09:22 +0000)
Make test-checkstyle-diff is a new target which checks PEP8 compliance
only for changed files. This makes it faster to execute and also more
readable as most of the time, only changed files will fail.

Type: improvement
Signed-off-by: Klement Sekera <ksekera@cisco.com>
Change-Id: I71baca76ab3a21a7a3790617cbfb0d48aacbd9ec

Makefile
test/Makefile

index a1226a7..78300e2 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -206,6 +206,7 @@ help:
        @echo " checkstyle           - check coding style"
        @echo " checkstyle-commit    - check commit message format"
        @echo " checkstyle-test      - check test framework coding style"
+       @echo " checkstyle-test-diff - check test framework coding style (only changed files)"
        @echo " checkstyle-api       - check api for incompatible changes"
        @echo " fixstyle             - fix coding style"
        @echo " doxygen              - (re)generate documentation"
@@ -478,6 +479,10 @@ test-wipe-all:
 test-checkstyle:
        @make -C test checkstyle
 
+.PHONY: test-checkstyle-diff
+test-checkstyle-diff:
+       @make -C test checkstyle-diff
+
 .PHONY: test-refresh-deps
 test-refresh-deps:
        @make -C test refresh-deps
index d33133a..2421086 100644 (file)
@@ -318,6 +318,21 @@ wipe-papi:
 wipe-all: wipe wipe-papi wipe-doc wipe-cov
        @rm -rf $(TEST_BR)
 
+.PHONY: checkstyle-diff
+checkstyle-diff: $(BUILD_TEST_SRC) $(PIP_INSTALL_DONE)
+       @bash -c "source $(VENV_PATH)/bin/activate &&\
+                 $(PYTHON_INTERP) -m pip install pycodestyle"
+       @bash -c "source $(VENV_PATH)/bin/activate &&\
+               cd $(WS_ROOT) && git diff --name-only --no-color --relative HEAD~1 ':!*.patch' | grep '.py$$' | xargs -n 1 -I XXX \
+               pycodestyle --show-source --ignore=W504,E126,E241,E226,E305,E704,E741,E722 -v XXX ||\
+               (echo \"*********************************************************************\" &&\
+                echo \"* Test framework PEP8 compliance check FAILED (checked changed files)\" &&\
+                echo \"*********************************************************************\" &&\
+                false)"
+       @echo "*********************************************************************"
+       @echo "* Test framework PEP8 compliance check passed (checked changed files)"
+       @echo "*********************************************************************"
+
 .PHONY: checkstyle
 checkstyle: $(BUILD_TEST_SRC) $(PIP_INSTALL_DONE)
        @bash -c "source $(VENV_PATH)/bin/activate &&\
@@ -325,11 +340,11 @@ checkstyle: $(BUILD_TEST_SRC) $(PIP_INSTALL_DONE)
        @bash -c "source $(VENV_PATH)/bin/activate &&\
                pycodestyle --show-source --ignore=W504,E126,E241,E226,E305,E704,E741,E722 -v $(BUILD_TEST_SRC)/*.py ||\
                (echo \"*******************************************************************\" &&\
-                echo \"* Test framework PEP8 compliance check FAILED \" &&\
+                echo \"* Test framework PEP8 compliance check FAILED (checked all files)\" &&\
                 echo \"*******************************************************************\" &&\
                 false)"
        @echo "*******************************************************************"
-       @echo "* Test framework PEP8 compliance check passed"
+       @echo "* Test framework PEP8 compliance check passed (checked all files)"
        @echo "*******************************************************************"
 
 .PHONY: help