我目前正在尝试使用Catch测试框架。我正在使用cmake来构建我的项目,目前我只是把所有的.h和.c文件放在一起。出于测试目的,我取出了实际的"main“,并将其替换为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
我不太清楚为什么连接要这么长时间。有人遇到过这样的问题吗?
最新情况:
关于我的环境的更多信息:
发布于 2019-03-12 23:19:27
因此,从这个已知的问题来看:
Github.com/catchorg/Catch2 2/issues/1205
使用链接时间优化是非常糟糕的。然而,我偶然发现了一个对我有用的解决方案。将cmake生成类型设置为
RELWITHDEBINFO似乎以10倍的速度加速了连接。
https://stackoverflow.com/questions/55112909
复制相似问题