【发布时间】:2018-10-13 11:58:37
【问题描述】:
我的 Catch 测试框架中有以下简单的表达式。理想情况下,如果测试失败,测试应该发出警告。
很遗憾,Catch 无法编译以下代码片段:
#define CATCH_CONFIG_MAIN
#include "catch2.hpp"
TEST_CASE("Simple") {
int a = 4;
int b = 1;
CHECK(a == 5 || b == 2);
}
Visual Studio 2015 发出以下错误:
error C2676: Binary operator "||": "const Catch::BinaryExpr<LhsT,const int &>" does not define this operator or a conversion for this operator of to suitable type
我希望得到以下内容:
4==5 || 1==2 => false || false => false
这可以用 Catch 实现还是我必须使用额外的括号:
#define CATCH_CONFIG_MAIN
#include "catch2.hpp"
TEST_CASE("Simple") {
int a = 4;
int b = 1;
CHECK((a == 5 || b == 2));
}
【问题讨论】:
-
您能告诉我们您遇到了什么错误吗?完整、完整、未经修改并复制粘贴为文本。当然是在问题的正文中,而不是作为评论。
-
使用额外的括号将无法分解表达式并随意扩展。
-
另外,你知道右手部分 (
b == 2) 甚至不会被评估?
标签: c++ unit-testing catch-unit-test