每次捕获测试框架 long link 次

Catch testing framework long link time every time

我目前正在尝试使用 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

"slow compile" 维基页面: https://github.com/catchorg/Catch2/blob/master/docs/slow-compiles.md

我不太清楚为什么链接要花这么长时间。有人 运行 遇到过这样的问题吗?

更新:

关于我的环境的更多信息:

所以根据这个已知问题判断:

github.com/catchorg/Catch2/issues/1205

Mingw 在 link 时间优化方面真的很糟糕。然而;我偶然发现了一个适合我的解决方案。将 cmake 构建类型设置为

RELWITHDEBINFO

似乎将 link 速度提高了 10 倍。