Have make fail if unit tests fail

只谈情不闲聊 提交于 2019-12-24 03:26:19

问题


I have a makefile for compiling a static library. This makefile has a rule for compiling a unit test suite associated with the static library. Once the test suite is compiled, a python script is invoked to run the tests and log the results. It looks like this:

unit:
    $(MAKE) -C cXbase/unit
    python $(TESTS_RUNNER) $(UNIT_TESTS_EXEC) $(UNIT_TESTS_LOG)

I use Python to make the tests invocation portable. Right now, everything works fine: the tests compile and the test runner is called and logs everything properly in Linux and Windows. Only, when a test fail, I would like to stop the whole make process and return an error. More precisely, I would like not to be able to make all or to make unit when a unit test fails (or many).

If a unit test fails, the Python script returns a specific exit code. I would like to be able to capture it in a portable way and have make fail if that exit code is captured.

Would you have any recommendations on how to do this? I have found nothing convincing or portable elsewhere.

Thanks


回答1:


It seems the solution was way simpler than I imagined. The python exit code reflects directly in make it's exit code. In other words, if the script fails (exit code other than 0), make sees this as a command error and stops.

I had an error in my Python script exit code handling upon tests failure which hid this from me. Now it is solved and it works perfectly.

I found out about this here: Handling exit code returned by python in shell script



来源:https://stackoverflow.com/questions/43957679/have-make-fail-if-unit-tests-fail

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!