【问题标题】:Shell script condition checking in MakefileMakefile 中的 Shell 脚本条件检查
【发布时间】:2015-11-11 21:10:10
【问题描述】:

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

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

【问题讨论】:

  • 不要在食谱中使用$(shell)。时机不对。只需使用普通 shell $() 命令替换即可。
  • 这个问题与CMake有关吗?如果没有,请删除cmake 标签。

标签: bash shell cmake makefile


【解决方案1】:

如果任何测试失败,使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

【讨论】:

    猜你喜欢
    • 2015-10-10
    • 2014-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-05
    • 1970-01-01
    • 2014-09-30
    相关资源
    最近更新 更多