2015-11-11 76 views
-1

我有下面的Makefile脚本,它调用一个python测试套件,将结果写入名为test_results.txt的文件中。然后显示这些文件并读取最后一行,该行的状态表明是否所有的测试用例都已执行。基于这个价值,我回应了一个声明。Makefile中的Shell脚本条件检查

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 

当我运行它,我得到以下错误:0/bin/sh: 1: [: =: unexpected operator

+0

不要在配方中使用'$(shell)'。时机错了。只需使用普通的shell'$()'命令替换即可。 –

+1

这个问题与CMake有关吗?如果没有,请移除'cmake'标签。 – Tsyvarev

回答

2

这是更简单,使test.py有一个非零退出状态,如果任何测试失败。那么你的配方只是

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