如何在 Makefile 中运行二进制文件的测试用例
有一个生成二进制应用程序的小项目。源代码是 C,我使用 autotools 来创建 Makefile
并构建二进制文件 - 它也可以工作。
我想用该二进制文件运行测试用例。这就是我所做的:
SUBDIRS = src
dist_doc_DATA = README
TESTS=
TESTS+=tests/config1.conf
TESTS+=tests/config2.conf
TESTS+=tests/config3.conf
TESTS+=tests/config4.conf
TESTS+=tests/config5.conf
TESTS+=tests/config6.conf
TESTS+=tests/config7.conf
TESTS+=tests/config8.conf
TESTS+=tests/config9.conf
TESTS+=tests/config10.conf
TESTS+=tests/config11.conf
我想使用该工具将这些案例作为参数运行。当我运行 make check
时,我得到:
make[3]: Entering directory '/home/airween/src/mytool'
FAIL: tests/config1.conf
FAIL: tests/config2.conf
FAIL: tests/config3.conf
这是正确的,因为这些文件是简单的配置文件。
我怎样才能解决 make check
使用上面的脚本运行我的工具,最后我得到一个包含成功、失败、...测试数量的列表,就像在这种情况下:
============================================================================
Testsuite summary for mytool 0.1
============================================================================
# TOTAL: 11
# PASS: 0
# SKIP: 0
# XFAIL: 0
# FAIL: 11
# XPASS: 0
# ERROR: 0
编辑:所以我会喜欢模拟这些运行:
for f in `ls -1 tests/*.conf; do src/mytool ${f}; done
但是 - 当然 - 我想在最后看到总结。
谢谢。
There is a small project which produces a binary application. The source code is C, I'm using autotools to create the Makefile
and build the binary - it works as well.
I would like to run tests cases with that binary. Here is what I did:
SUBDIRS = src
dist_doc_DATA = README
TESTS=
TESTS+=tests/config1.conf
TESTS+=tests/config2.conf
TESTS+=tests/config3.conf
TESTS+=tests/config4.conf
TESTS+=tests/config5.conf
TESTS+=tests/config6.conf
TESTS+=tests/config7.conf
TESTS+=tests/config8.conf
TESTS+=tests/config9.conf
TESTS+=tests/config10.conf
TESTS+=tests/config11.conf
I would like to run these cases as argument with the tool. When I run make check
, I got:
make[3]: Entering directory '/home/airween/src/mytool'
FAIL: tests/config1.conf
FAIL: tests/config2.conf
FAIL: tests/config3.conf
which is correct, because those files are simple configurations files.
How can I solve that make check
runs my tool with the scripts above, and finally I get a list with number of success, failed, ... tests, like in that case:
============================================================================
Testsuite summary for mytool 0.1
============================================================================
# TOTAL: 11
# PASS: 0
# SKIP: 0
# XFAIL: 0
# FAIL: 11
# XPASS: 0
# ERROR: 0
Edit: so I would like to emulate these runs:
for f in `ls -1 tests/*.conf; do src/mytool ${f}; done
but - of course - I want to see the summary at the end.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Autotools的内置测试跑步者希望您通过
make
变量tests
来指定可执行测试的名称。您不能只将随机文件名放入其中,并期望make
或自动化知道该如何处理它们。可以构建测试的程序,生成的脚本,与项目分发的静态脚本或上述任何组合。
您已经确认您的配置文件不是脚本,所以请停止称呼它们!实际上,这是问题的症结所在。最简单的解决方案可能是创建实际可执行脚本,每种情况一个,而 在您的
tests
variable中的名称。每个人都会使用适当的配置文件运行正在测试的二进制文件(也就是说,如果您想执行这些测试,则可以使他们这样做)。另请参见自动化手册的术语一章。
The Autotools' built-in test runner expects you to specify the names of executable tests via the
make
variableTESTS
. You cannot just put random filenames in there and expectmake
or Automake to know what to do with them.The tests can be built programs, generated scripts, static scripts distributed with the project, or any combination of the above.
You have acknowledged that your configuration files are not scripts, so stop calling them that! This is in fact the crux of the problem. The easiest solution is probably to create actual executable scripts, one for each case, and name those in your
TESTS
variable. Each one would run the binary under test with the appropriate configuration file (that is, you're responsible for making them do that if those are the tests you want to perform).See also the Automake Manual's chapter on tests.
好的,来自在这里的解决方案。 :
结果:
这就是我所期望的。
Okay, the solution from here:
And the result:
This is what I expected.