如何让GNU明确测试失败? [英] How to have GNU make explicitly test for failure?
问题描述
在多年不使用make的情况下,我发现自己再次需要它,现在是gnu版本.我很确定我应该能够做我想做的事,但是还没有弄清楚该怎么做,或者还没有找到与Google相关的答案等等.
After years of not using make, I find myself needing it again, the gnu version now. I'm pretty sure I should be able to do what I want, but haven't figured out how, or found an answer with Google, etc.
我正在尝试创建一个测试目标,该目标将多次执行我的程序,并将结果保存在日志文件中.某些测试应导致我的程序中止.不幸的是,我的makefile在第一次测试时中止,从而导致错误.我有类似的东西:
I'm trying to create a test target which will execute my program a number of times, saving the results in a log file. Some tests should cause my program to abort. Unfortunately, my makefile aborts on the first test which leads to an error. I have something like:
# Makefile
#
test:
myProg -h > test.log # Display help
myProg good_input >> test.log # should run fine
myProg bad_input1 >> test.log # Error 1
myProg bad_input2 >> test.log # Error 2
使用上述方法,make在bad_input1运行后退出,再也不会进入bad_input2运行.
With the above, make quits after the bad_input1 run, never getting to the bad_input2 run.
推荐答案
如果您希望目标失败,则正确的解决方案是取消其退出代码.
The proper solution if you want to require the target to fail is to negate its exit code.
# Makefile
#
test:
myProg -h > test.log # Display help
myProg good_input >> test.log # should run fine
! myProg bad_input1 >> test.log # Error 1
! myProg bad_input2 >> test.log # Error 2
现在,在这两种情况下成功都是错误的.
Now, it is an error to succeed in those two cases.
这篇关于如何让GNU明确测试失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!