【问题标题】:Execute all tests in subdirs even if some fail执行子目录中的所有测试,即使有些测试失败
【发布时间】:2015-11-19 12:34:31
【问题描述】:

我们利用 autotools (autoconf&automake) 基础架构在我们的软件中进行了多项回归测试。这些回归测试根据它们测试的功能/单元分为不同的子目录。我们发现,一旦其中一个子目录在任何测试中失败,即将到来的子目录中的后续测试都不会执行,因此我们无法全面了解哪些功能继续按预期工作。有没有办法改变这种行为并强制执行所有测试,即使有些测试失败了?

考虑以下最小示例,其中 subdir1 失败,然后 make 检查不进行到 subdir2。使用 make check 的输出(通过 autoreconf -fiv 和简单的 ./configure 调用生成配置后)是:

...
make[2]: Entering directory `x/subdir1'
make[3]: Entering directory `x/subdir1'
FAIL: fail
PASS: pass
make[4]: Entering directory `x/subdir1'
make[4]: Nothing to be done for `all'.
make[4]: Leaving directory `x/subdir1'
============================================================================
Testsuite summary for test 1.0
============================================================================
# TOTAL: 2
# PASS:  1
# SKIP:  0
# XFAIL: 0
# FAIL:  1
# XPASS: 0
# ERROR: 0
============================================================================
See subdir1/test-suite.log
============================================================================
make[3]: *** [test-suite.log] Error 1
make[3]: Leaving directory `x/subdir1'
make[2]: *** [check-TESTS] Error 2
make[2]: Leaving directory `x/subdir1'
make[1]: *** [check-am] Error 2
make[1]: Leaving directory `x/subdir1'
make: *** [check-recursive] Error 1

这个小测试的文件是:

configure.ac

AC_INIT([test], [1.0])
AM_INIT_AUTOMAKE()
AC_PROG_CC
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_FILES([
 Makefile
 subdir1/Makefile
 subdir2/Makefile
])
AC_OUTPUT

subdir1/Makefile.am

check_PROGRAMS = fail pass
TESTS = fail pass
fail_SOURCES = fail.c
pass_SOURCES = pass.c

subdir2/Makefile.am

check_PROGRAMS = pass
TESTS = pass
pass_SOURCES = pass.c

fail.c 和 pass.c 的共享源

pass.c

int main (void)
{ return 0; }

fail.c

int main (void)
{ return 1; }

【问题讨论】:

    标签: testing automated-tests autotools automake regression-testing


    【解决方案1】:

    要继续执行make,即使某些子目标失败,您也可以添加-k 标志 - 无论实际的目标如何,这都有效:

    make -k check
    

    【讨论】:

    • 太棒了!我已经在启动所有测试的根目录的 Makefile.am 中的 MAKEFLAGS 变量中添加了 -k 选项,它运行良好!
    【解决方案2】:

    我知道这并不漂亮,但解决您的问题的一种方法是将所有子目录中的所有测试放入一个 Makefile 中的单个 TESTS 对象中。例如:

    configure.ac

    AC_INIT([test], [1.0])
    AM_INIT_AUTOMAKE()
    AC_PROG_CC
    AC_CONFIG_HEADERS([config.h])
    AC_CONFIG_FILES([
     Makefile
     subdir1/Makefile
     subdir2/Makefile
    ])
    AC_OUTPUT
    

    subdir1/Makefile.am

    check_PROGRAMS = fail pass
    fail_SOURCES = fail.c
    pass_SOURCES = pass.c
    

    subdir2/Makefile.am

    check_PROGRAMS = pass
    pass_SOURCES = pass.c
    

    附加到顶级Makefile.am

    TESTS = subdir1/fail subdir1/pass subdir2/pass
    

    【讨论】:

    • 第二。此外,请考虑使用顶级Makefile.am。使用 automake SUBDIRS 很快就会变得非常混乱。
    猜你喜欢
    • 1970-01-01
    • 2011-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多