如何向 KDevelop 中基于 automake 的项目添加自定义构建步骤?

发布于 2024-07-04 20:32:44 字数 613 浏览 10 评论 0原文

我最近开始使用 C++ 和 KDevelop 进行个人编码项目。 虽然我一开始只是乱搞,但我认为从长远来看,如果我在走得更远之前建立一个适当的单元测试套件会更好。 我创建了一个单独的测试运行程序可执行文件作为子项目,并且我添加到其中的测试似乎运行正常。 至此,成功。

但是,我真的希望每次构建时都运行单元测试,而不仅仅是在我显式运行它们时。 当我将造成的混乱分成方便的库时尤其如此,每个库可能都有自己的测试可执行文件。 我不想手动运行它们,而是想让它们作为构建过程的最后一步运行。 我已经查看了项目菜单和 automake 管理器中的所有选项,但我不知道如何设置它。

我想这可能可以通过手动编辑 makefile 来完成。 不幸的是,我的 makefile-fu 有点弱,而且我还担心下次我通过 IDE 更改某些内容时 KDevelop 可能会覆盖我手动所做的任何更改。 因此,如果有一个关于如何通过 KDevelop 本身来完成此操作的选项,我更愿意这样做。

有谁知道如何让 KDevelop 在构建过程中运行我的测试可执行文件? 谢谢你!

(我并不是 100% 依赖 KDevelop。如果 KDevelop 不能做到这一点,或者如果有一个 IDE 可以使这变得更容易,我可能会被说服切换。)

I recently started work on a personal coding project using C++ and KDevelop. Although I started out by just hacking around, I figure it'll be better in the long run if I set up a proper unit test suite before going too much further. I've created a seperate test-runner executable as a sub project, and the tests I've added to it appear to function properly. So far, success.

However, I'd really like to get my unit tests running every time I build, not only when I explicitly run them. This will be especially true as I split up the mess I've made into convenience libraries, each of which will probably have its own test executable. Rather than run them all by hand, I'd like to get them to run as the final step in my build process. I've looked all through the options in the project menu and the automake manager, but I can't figure out how to set this up.

I imagine this could probably be done by editing the makefile by hand. Unfortunately, my makefile-fu is a bit weak, and I'm also afraid that KDevelop might overwrite any changes I make by hand the next time I change something through the IDE. Therefore, if there's an option on how to do this through KDevelop itself, I'd much prefer to go that way.

Does anybody know how I could get KDevelop to run my test executables as part of the build process? Thank you!

(I'm not 100% tied to KDevelop. If KDevelop can't do this, or else if there's an IDE that makes this much easier, I could be convinced to switch.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

墨小沫ゞ 2024-07-11 20:32:47

我以这种方式工作:

$ cat src/base64.c
//code to be tested
int encode64(...) { ... }

#ifdef UNITTEST
#include <assert.h>
int main(int argc, char* argv[])
{
  assert( encode64(...) == 0 );
  return 0;
}
#endif //UNITTEST
/* end file.c */

$ cat src/Makefile.am
...
check_PROGRAMS = base64-test
base64_test_SOURCES = base64.c
base64_test_CPPFLAGS = -I../include -DUNITTEST
TESTS = base64-test

make check 将构建 src/base64-test 并运行它:

$ make check
...
PASS: base64-test
==================
All 1 tests passed
==================
...

现在我尝试将其全部封装为要像这样使用的 m4 宏:

MAKE_UNITTEST(base64.c)

应该生成像上面的解决方案一样。

希望这可以帮助。

I got it working this way:

$ cat src/base64.c
//code to be tested
int encode64(...) { ... }

#ifdef UNITTEST
#include <assert.h>
int main(int argc, char* argv[])
{
  assert( encode64(...) == 0 );
  return 0;
}
#endif //UNITTEST
/* end file.c */

$ cat src/Makefile.am
...
check_PROGRAMS = base64-test
base64_test_SOURCES = base64.c
base64_test_CPPFLAGS = -I../include -DUNITTEST
TESTS = base64-test

A make check would build src/base64-test and run it:

$ make check
...
PASS: base64-test
==================
All 1 tests passed
==================
...

Now I'm trying to encapsulate it all as a m4 macro to be used like this:

MAKE_UNITTEST(base64.c)

which should produce something like the solution above.

Hope this helps.

全部不再 2024-07-11 20:32:46

尽管您可以操纵默认的“make”目标来运行测试,
通常不建议这样做,因为每次调用

make

将运行所有测试。
您应该使用“检查”目标,
这是软件包中公认的准标准。
通过这样做,
测试仅在您运行时开始

make check

然后您可以轻松配置 KDevelop
运行“make check”而不仅仅是“make”。

由于您正在使用 automake(通过 KDevelop),
您不需要自己编写“检查”目标。
相反,只需编辑“Makefile.am”并设置一些变量:

TESTS = ...

请看一下
automake 文档,“测试套件支持”
了解更多信息。

Although you could manipulate the default `make` target to run your tests,
it is generally not recommended, because every invocation of

make

would run all the tests.
You should use the "check" target instead,
which is an accepted quasi-standard among software packages.
By doing that,
the tests are only started when you run

make check

You can then easily configure KDevelop
to run "make check" instead of just "make".

Since you are using automake (through KDevelop),
you don't need to write the "check" target yourself.
Instead, just edit your `Makefile.am` and set some variables:

TESTS = ...

Please have a look at the
automake documentation, "Support for test suites"
for further information.

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