如果 Python 可用,则选择性地启用测试程序 - automake

发布于 2024-11-26 19:44:40 字数 705 浏览 6 评论 0原文

我有一个用 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 技术交流群。

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

发布评论

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

评论(1

轻许诺言 2024-12-03 19:44:40

您必须仅将 _SOURCES 用于已编译的内容,因此这就是添加 $(EXEEXT) 的原因。试试这个:

TESTS = unittests
if HAVE_PYTHON
TESTS += tester.py
# Possibly use += here depending on the rest of your Makefile.am
check_SCRIPTS = tester.py
# I added $(srcdir) here so VPATH builds still work.
tester.py: $(srcdir)/src/test/tester.py.in Makefile
        $(SED) -e 's,[@]PYTHON[@],$(PYTHON),' < 
lt; > $@
        chmod +x $@
endif

有什么理由不通过 configure.ac 进行替换吗?

AS_IF([test "$PYTHON" != ":"], [AC_CONFIG_FILES([src/test/tester.py])])

这将使用 config.status 重新创建脚本并自动生成重建规则。

编辑1:

如果你真正想做的是运行Python测试脚本作为make check的一部分,我会这样做:(

check-local:
if HAVE_PYTHON
        $(PYTHON) $(srcdir)/src/test/tester.py
endif

我把check -localif HAVE_PYTHON 之外,以便您可以定义其他命令作为 check-local 的一部分运行(如果需要)。)

您可能更喜欢这样写,相反:

check-local:
        test "$(PYTHON)" != ":" && $(PYTHON) $(srcdir)/src/test/tester.py

参见扩展

You must use _SOURCES for compiled things only, so that's why it'a adding $(EXEEXT). Try this:

TESTS = unittests
if HAVE_PYTHON
TESTS += tester.py
# Possibly use += here depending on the rest of your Makefile.am
check_SCRIPTS = tester.py
# I added $(srcdir) here so VPATH builds still work.
tester.py: $(srcdir)/src/test/tester.py.in Makefile
        $(SED) -e 's,[@]PYTHON[@],$(PYTHON),' < 
lt; > $@
        chmod +x $@
endif

Is there any reason you don't just do the substitution via configure.ac?

AS_IF([test "$PYTHON" != ":"], [AC_CONFIG_FILES([src/test/tester.py])])

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:

check-local:
if HAVE_PYTHON
        $(PYTHON) $(srcdir)/src/test/tester.py
endif

(I put the check-local outside the if HAVE_PYTHON so that you can define other commands to run as part of check-local, if needed.)

You might prefer writing this, instead:

check-local:
        test "$(PYTHON)" != ":" && $(PYTHON) $(srcdir)/src/test/tester.py

See extending in the automake manual.

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