使用Automake进行单元测试

编程入门 行业动态 更新时间:2024-10-24 04:37:44
本文介绍了使用Automake进行单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用GNU自动工具与团队中的其他人一起工作在一个项目中.在项目中,我们对每个不重要的C ++类都使用单元测试.我发现有对单元测试的支持.为此,我正在使用以下结构:

./ + tests/ + Makefile.am + classA_test.cc .... + classB_test.cc + src/ + lib/ + Makefile.am

问题来了,因为我的主要Makefile.am使用的是 subdir-objects 选项-请注意,我没有对源文件使用递归的makefile-我无法导出变量- as,AM_CPPFLAGS--到另一个Makefile.到目前为止,我使用以下方法使之起作用:

$ make check

但是当我这样做时,我总是遇到路径和选项方面的问题

$ make distcheck

所以我的问题是,处理单元测试的标准方法是什么?

只要我从tests/Makefile.am中删除子目录对象,就可以使它起作用.现在它会发出一些警告,但会编译.仍然似乎不是处理单元测试的合适方法

解决方案

经过一些研究,我想出了处理单元测试和Automake的适当方法:

遵循先前的方案:

./ + tests/ + Makefile.am + classA_test.cc .... + classB_test.cc + src/ + lib/ + Makefile.am

根目录中的makefile.am将是主目录,该目录将调用tests目录中的makefile.

$ cat Makefile.am SUBDIRS = . tests # (Super Important) note the "." before tests, # it means it will be executed first .... $ cat test/Makefile.am AM_CXXFLAGS = ... AM_LDFLAGS = -L @top_srcdir@/lib #If needed LDADD = -llibraryfortests #If needed TESTS = test1 .. testN test1_SOURCES = test1.cc ../src/somewhere/classtotest.cc testN_SOURCES = ... $ cat configure.ac AM_INIT_AUTOMAKE([subdir-objects]) AC_CONFIG_FILES([Makefile]) AC_CONFIG_FILES([tests/Makefile]) ...

现在,如果您想运行测试

$ sh ../pathto/configure $ make check

dist [check]也应该起作用

$ make distcheck ... make[3]: Entering directory `/home/vicente/test/tests' PASS: settings ============================================================================ Testsuite summary for Pepinos 00.13.15 ============================================================================ # TOTAL: 1 # PASS: 1 # SKIP: 0 # XFAIL: 0 # FAIL: 0 # XPASS: 0 # ERROR: 0 ============================================================================ make[3]: Leaving directory `/home/vicente/test/tests' ...

要回答另一个问题吗?

问: 我无法将我的变量(例如AM_CPPFLAGS)导出到另一个Makefile .

A.是的,但是我总是可以在configure.ac和AC_SUBT中声明一个变量,以使其对其他Makefile.am可见

来源: stackoverflow/a/29255889/2420872

I am working in a project with other people in the team using GNU autotools. In the project we are using unit test for each non trivial C++ class. I found out that there is support for unit testing. For that I am using this structure:

./ + tests/ + Makefile.am + classA_test.cc .... + classB_test.cc + src/ + lib/ + Makefile.am

The problem comes since my main Makefile.am is using subdir-objects options --note that I am not using recursive makefile for the source files--, I cannot export my variables --such as, AM_CPPFLAGS-- to the other Makefile. So far I made it work using:

$ make check

but I keep getting problems for the paths and the options when I do

$ make distcheck

So my questions is, how is the standard way to deal with unit tests?

EDIT:

I made it work as long as I remove the subdir-objects from the tests/Makefile.am. Now it throw some warnings but it compiles. Still it seems not to be an appropriate way to deal with unit tests

解决方案

After some research I came up with the appropiate way to deal with Unit tests and Automake:

Following the previous scheme:

./ + tests/ + Makefile.am + classA_test.cc .... + classB_test.cc + src/ + lib/ + Makefile.am

The makefile.am in the root will be the main one, this one calls the makefile in the tests directory

$ cat Makefile.am SUBDIRS = . tests # (Super Important) note the "." before tests, # it means it will be executed first .... $ cat test/Makefile.am AM_CXXFLAGS = ... AM_LDFLAGS = -L @top_srcdir@/lib #If needed LDADD = -llibraryfortests #If needed TESTS = test1 .. testN test1_SOURCES = test1.cc ../src/somewhere/classtotest.cc testN_SOURCES = ... $ cat configure.ac AM_INIT_AUTOMAKE([subdir-objects]) AC_CONFIG_FILES([Makefile]) AC_CONFIG_FILES([tests/Makefile]) ...

Now if you want to run the tests

$ sh ../pathto/configure $ make check

As well dist[check] should work

$ make distcheck ... make[3]: Entering directory `/home/vicente/test/tests' PASS: settings ============================================================================ Testsuite summary for Pepinos 00.13.15 ============================================================================ # TOTAL: 1 # PASS: 1 # SKIP: 0 # XFAIL: 0 # FAIL: 0 # XPASS: 0 # ERROR: 0 ============================================================================ make[3]: Leaving directory `/home/vicente/test/tests' ...

So to answer the other question?

Q. I cannot export my variables --such as, AM_CPPFLAGS-- to the other Makefile.

A. True, but I can always declare a variable in the configure.ac and AC_SUBT to make it visible to other Makefile.am

Sources: stackoverflow/a/29255889/2420872

更多推荐

使用Automake进行单元测试

本文发布于:2023-06-13 09:34:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/679004.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单元测试   Automake

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!