简体   繁体   中英

Shell script condition checking in Makefile

I've got the following Makefile script which calls a python test suite that writes the results to a file called test_results.txt . Then I display the files and read the last line which has a status that indicates whether all the test cases have been executed or not. Based on that value I echo a statement.

target: test.py
    $(PYTHON) test.py
    @cat test/test_results.txt
    @if [ $(shell sed -e '$$!d' test/test_results.txt) = 0 ]; then\
        echo "\nAll tests passed successfully";\
    else \
        echo "\nNot all the tests were passed";\
    fi

When I run it, I get the following error: 0/bin/sh: 1: [: =: unexpected operator

It's much simpler to make test.py have a non-zero exit status if any test fails. Then your recipe is simply

target: test.py        
    @if $(PYTHON) test.py; then\
     echo "\nAll tests passed successfully";\
    else \
     echo "\nNot all the tests were passed";\
    fi
    @cat test/test_results.txt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM