如何在 Makefile 中运行二进制文件的测试用例

发布于 2025-01-19 10:18:33 字数 1248 浏览 5 评论 0原文

有一个生成二进制应用程序的小项目。源代码是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

长不大的小祸害 2025-01-26 10:18:33

Autotools的内置测试跑步者希望您通过make变量tests来指定可执行测试的名称。您不能只将随机文件名放入其中,并期望make或自动化知道该如何处理它们。

可以构建测试的程序,生成的脚本,与项目分发的静态脚本或上述任何组合。

我该如何解决该检查的脚本,最后我得到了[测试摘要报告]?

您已经确认您的配置文件不是脚本,所以请停止称呼它们!实际上,这是问题的症结所在。最简单的解决方案可能是创建实际可执行脚本,每种情况一个,而 在您的tests variable中的名称​​。每个人都会使用适当的配置文件运行正在测试的二进制文件(也就是说,如果您想执行这些测试,则可以使他们这样做)。

另请参见自动化手册的术语一章

The Autotools' built-in test runner expects you to specify the names of executable tests via the make variable TESTS. You cannot just put random filenames in there and expect make 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.

How can I solve that make check runs my tool with the scripts above, and finally I get a [test summary report]?

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.

天赋异禀 2025-01-26 10:18:33

好的,来自在这里的解决方案。 :

tests/Makefile.am:
==================

TEST_EXTENSIONS = .conf
CONF_LOG_COMPILER = ./test-suit.sh


TESTS=
TESTS+=config1.conf
TESTS+=config2.conf
TESTS+=config3.conf
TESTS+=config4.conf
TESTS+=config5.conf
TESTS+=config6.conf
TESTS+=config7.conf
TESTS+=config8.conf
TESTS+=config9.conf
TESTS+=config10.conf
TESTS+=config11.conf
test/test-suit.sh:
==================

#!/bin/sh

CONF=$1

exec ../src/mytool $CONF

结果:

make check
...
PASS: config1.conf
PASS: config2.conf
PASS: config3.conf
PASS: config4.conf
PASS: config5.conf
PASS: config6.conf
PASS: config7.conf
PASS: config8.conf
PASS: config9.conf
PASS: config10.conf
PASS: config11.conf
============================================================================
Testsuite summary for mytool 0.1
============================================================================
# TOTAL: 11
# PASS:  11
# SKIP:  0
# XFAIL: 0
# FAIL:  0
# XPASS: 0
# ERROR: 0
============================================================================

这就是我所期望的。

Okay, the solution from here:

tests/Makefile.am:
==================

TEST_EXTENSIONS = .conf
CONF_LOG_COMPILER = ./test-suit.sh


TESTS=
TESTS+=config1.conf
TESTS+=config2.conf
TESTS+=config3.conf
TESTS+=config4.conf
TESTS+=config5.conf
TESTS+=config6.conf
TESTS+=config7.conf
TESTS+=config8.conf
TESTS+=config9.conf
TESTS+=config10.conf
TESTS+=config11.conf
test/test-suit.sh:
==================

#!/bin/sh

CONF=$1

exec ../src/mytool $CONF

And the result:

make check
...
PASS: config1.conf
PASS: config2.conf
PASS: config3.conf
PASS: config4.conf
PASS: config5.conf
PASS: config6.conf
PASS: config7.conf
PASS: config8.conf
PASS: config9.conf
PASS: config10.conf
PASS: config11.conf
============================================================================
Testsuite summary for mytool 0.1
============================================================================
# TOTAL: 11
# PASS:  11
# SKIP:  0
# XFAIL: 0
# FAIL:  0
# XPASS: 0
# ERROR: 0
============================================================================

This is what I expected.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文