简体   繁体   English

Makefile中的Shell脚本条件检查

[英]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 . 我有以下Makefile脚本,该脚本调用python测试套件,将结果写入名为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 运行它时,出现以下错误: 0/bin/sh: 1: [: =: unexpected operator

It's much simpler to make test.py have a non-zero exit status if any test fails. 如果任何测试失败,则使test.py具有非零的退出状态要容易得多。 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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