如果 Python 可用,则选择性地启用测试程序 - automake
我有一个用 C 编写的程序,使用 automake/autoconf 构建,并且有两个测试套件。一个是单元测试套件,也是用 C 编写的;另一个是端到端的,(当前)用 Python 编写。我希望“make check”始终运行单元测试,并且仅在安装了 Python 的情况下才运行端到端测试。这就是我现在所拥有的:
TESTS = unittests
if HAVE_PYTHON
TESTS += tester.py
tester_py_SOURCES = src/test/tester.py.in
tester.py: src/test/tester.py.in Makefile
$(SED) -e 's,[@]PYTHON[@],$(PYTHON),' < $< > $@
chmod +x $@
endif
HAVE_PYTHON
由配置脚本设置
AM_PATH_PYTHON([2.6],, [:])
AM_CONDITIONAL([HAVE_PYTHON], [test "$PYTHON" != ":"])
这在 Unix 上可以正常工作,但在 Windows 上会因“没有规则来生成 tester.py.exe”而崩溃。此外,用于正确获取 #!
行的复制和替换技术意味着我无法将测试套件分解为多个模块。
有更好的方法吗?
I've got a program that's written in C, built using automake/autoconf, and has two test suites. One is a unit test suite also written in C; the other is end-to-end and is (currently) written in Python. I want "make check" to run the unit tests always, and the end-to-end tests only if Python is installed. This is what I have now:
TESTS = unittests
if HAVE_PYTHON
TESTS += tester.py
tester_py_SOURCES = src/test/tester.py.in
tester.py: src/test/tester.py.in Makefile
$(SED) -e 's,[@]PYTHON[@],$(PYTHON),' < lt; > $@
chmod +x $@
endif
HAVE_PYTHON
is set by the configure script with
AM_PATH_PYTHON([2.6],, [:])
AM_CONDITIONAL([HAVE_PYTHON], [test "$PYTHON" != ":"])
This works correctly on Unix, but blows up with "no rule to make tester.py.exe" on Windows. Also, the copy-and-substitute technique for getting the #!
line right means I can't break up the test suite into multiple modules.
Is there a better way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须仅将
_SOURCES
用于已编译的内容,因此这就是添加$(EXEEXT)
的原因。试试这个:有什么理由不通过
configure.ac
进行替换吗?这将使用 config.status 重新创建脚本并自动生成重建规则。
编辑1:
如果你真正想做的是运行Python测试脚本作为
make check
的一部分,我会这样做:(我把
check -local
在if HAVE_PYTHON
之外,以便您可以定义其他命令作为check-local
的一部分运行(如果需要)。)您可能更喜欢这样写,相反:
参见扩展 。
You must use
_SOURCES
for compiled things only, so that's why it'a adding$(EXEEXT)
. Try this:Is there any reason you don't just do the substitution via
configure.ac
?This will remake the script using
config.status
and autogenerate rebuild rules.EDIT 1:
If what you really want to do is run the python tester script as part of
make check
, I'd do this:(I put the
check-local
outside theif HAVE_PYTHON
so that you can define other commands to run as part ofcheck-local
, if needed.)You might prefer writing this, instead:
See extending in the automake manual.