Catch测试框架问题:不能使用Catch::Session()
Catch test framework issue: cannot use Catch::Session()
我在编写一些测试的c++文件中得到这个错误:
error: no member named 'Session' in namespace 'Catch'
testResult = Catch::Session().run(test_argc, test_argv);
~~~~~~~^
查看catch.hpp单个头文件,我注意到应该实现Session()成员函数的代码是灰色的,可能是因为某个地方的#ifdef,我找不到。
是否有任何宏设置使用会话类?
捕获版本:1.5.3和1.5.6。
参考:https://github.com/philsquared/Catch/blob/master/docs/own-main.md
您试图从没有定义要执行的main
的文件中调用Catch::Session
的构造函数。根据定义自己的main的文档,应该只有一个Catch::Session
实例:
Catch::Session session; // There must be exactly once instance
很可能Catch是在翻译单元中阻止Catch::Session
的构造,在那里它不能在自定义main
定义中使用(因为这是它应该被使用的地方),以防止您从编译中所犯的错误。
参考https://github.com/catchorg/Catch2/blob/master/docs/own-main.md
您只能在定义CATCH_CONFIG_RUNNER的同一文件中提供main。
#define CATCH_CONFIG_RUNNER
#include "catch.hpp"
int main( int argc, char* argv[] ) {
// global setup...
int result = Catch::Session().run( argc, argv );
// global clean-up...
return result;
}
相关文章:
- 为什么catch中的代码没有被执行
- catch框架有没有办法比较流或文件
- 从 Rcpp Catch 测试中获取有关"inst/extdata"的数据
- 在C++中使用 Catch 测试框架编译错误"error: expected ';' at end of declaration list"
- 编译器是否必须始终删除 try-catch 块(如果它被证明是非抛出的)
- 有没有更好的方法来处理异常? try-catch块真的很丑
- 不能将重载比较运算符与 Catch 测试一起使用
- 对 soci::session::get_last_insert_id 的未定义引用
- #pragma 警告不适用于 catch 语句
- TensorFlow c++ API 在 session->run() 上崩溃
- 我可以使用 try catch 语句来捕获任何错误而不是具体错误吗?
- 在大型应用程序的main上使用try-catch
- RapidXML 节点在 try catch 块中具有正确的值,但它在块外为 nullptr
- 提取 try-catch 时出现运行时错误
- 无法在"catch(const std::exception &ex)"中捕获 std::invalid_argument
- std::unique_ptr 在 try-catch 块中未捕获取消引用异常
- 如果一个对象是在本地创建的,并在C++中作为异常抛出,那么本地对象如何在其范围之外有效,即在 catch 块中?
- C++ Catch 是否有类似 NUnit 的测试用例的东西,具有多个参数/输入选项
- 何时删除 try-catch 块中的指针
- Catch测试框架问题:不能使用Catch::Session()