【发布时间】:2019-08-02 10:04:04
【问题描述】:
我目前正在尝试使用 Catch 测试框架。我正在使用 cmake 来构建我的项目,目前我只是将所有 .h 和 .c 文件放在一起。出于测试目的,我取出了我的实际“主要”并将其替换为 Catch 的样本阶乘示例。我有两个文件:
// testmain.cpp
#define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp>
和
//test.cpp
#include "catch2/catch.hpp"
int Factorial( int number ) {
return number <= 1 ? number : Factorial( number - 1 ) * number; // fail
// return number <= 1 ? 1 : Factorial( number - 1 ) * number; // pass
}
TEST_CASE( "Factorial of 0 is 1 (fail)", "[single-file]" ) {
REQUIRE( Factorial(0) == 1 );
}
TEST_CASE( "Factorials of 1 and higher are computed (pass)", "[single-file]" ) {
REQUIRE( Factorial(1) == 1 );
REQUIRE( Factorial(2) == 2 );
REQUIRE( Factorial(3) == 6 );
REQUIRE( Factorial(10) == 3628800 );
}
现在发生的事情是它花费 3 秒构建和 1 分钟链接。在所有链接(1+分钟)之后,我得到了测试结果。我遵循以下两个教程,其中提到将这两个文件分开。
我阅读了 Catch 教程: https://github.com/catchorg/Catch2/blob/master/docs/tutorial.md
和
“慢编译”wiki 页面: https://github.com/catchorg/Catch2/blob/master/docs/slow-compiles.md
我不太清楚为什么链接需要这么长时间。有没有人遇到过这样的问题?
更新:
关于我的环境的更多信息:
cmake 3.14.0-rc1
g++ 8.1.0
【问题讨论】:
-
这里没有链接问题。 g++ 8.3.1
-
嗯,我正在使用 g++ 8.1.0 mingw。我想知道这是否导致缓慢。
-
我遇到的唯一速度问题是在
slow compilewiki 页面上描述的。我已经使用 Catch 至少一年了,没有其他速度问题。我已经定期进行 g++ 升级(OpenSuse Tumbleweed 滚动发行版) -
这似乎是一个 cmake 问题?每当我关闭调试并启用发布时,它的链接速度都非常快......不过需要更多调查。
-
显然这是 mingw 和 catch 的一个已知问题:github.com/catchorg/Catch2/issues/1205
标签: c++ unit-testing catch-unit-test