簡體   English   中英

Makefile中的Shell腳本條件檢查

[英]Shell script condition checking in Makefile

我有以下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

如果任何測試失敗,則使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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM