可能是gtest错误- ASSERT_EQ和ASSERT_TRUE编译失败
Maybe a gtest bug - ASSERT_EQ and ASSERT_TRUE compile failure
我使用的是最新的gtest。以下代码编译失败:
Error_code rc = some_function();
ASSERT_EQ(OK, rc);
Error_code是一个enum类型:
typedef enum {
OK = 0,
Warning,
Error
} Error_code;
错误信息没有意义:
Downloads/gtest-1.7.0/unzipped/include/gtest/internal/gtest-internal.h:1026:5: error: could not convert ‘testing::internal::AssertHelper((testing::TestPartResult::Type)2u, ((const char*)"source/unit_test/test.cpp"), 182, gtest_ar.testing::AssertionResult::failure_message()).testing::internal::AssertHelper::operator=((*(const testing::Message*)(& testing::Message())))’ from ‘void’ to ‘std::vector<Ttype>’
= ::testing::Message()
^
Downloads/gtest-1.7.0/unzipped/include/gtest/internal/gtest-internal.h:1029:3: note: in expansion of macro ‘GTEST_MESSAGE_AT_’
GTEST_MESSAGE_AT_(__FILE__, __LINE__, message, result_type)
^
Downloads/gtest-1.7.0/unzipped/include/gtest/internal/gtest-internal.h:1032:10: note: in expansion of macro ‘GTEST_MESSAGE_’
return GTEST_MESSAGE_(message, ::testing::TestPartResult::kFatalFailure)
^
Downloads/gtest-1.7.0/unzipped/include/gtest/gtest_pred_impl.h:80:5: note: in expansion of macro ‘GTEST_FATAL_FAILURE_’
on_failure(gtest_ar.failure_message())
^
Downloads/gtest-1.7.0/unzipped/include/gtest/gtest_pred_impl.h:147:3: note: in expansion of macro ‘GTEST_ASSERT_’
GTEST_ASSERT_(pred_format(#v1, #v2, v1, v2),
^
Downloads/gtest-1.7.0/unzipped/include/gtest/gtest_pred_impl.h:166:3: note: in expansion of macro ‘GTEST_PRED_FORMAT2_’
GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_FATAL_FAILURE_)
^
Downloads/gtest-1.7.0/unzipped/include/gtest/gtest.h:1993:3: note: in expansion of macro ‘ASSERT_PRED_FORMAT2’
ASSERT_PRED_FORMAT2(::testing::internal::
^
Downloads/gtest-1.7.0/unzipped/include/gtest/gtest.h:2011:32: note: in expansion of macro ‘GTEST_ASSERT_EQ’
# define ASSERT_EQ(val1, val2) GTEST_ASSERT_EQ(val1, val2)
^
source/unit_test/test.cpp:182:5: note: in expansion of macro ‘ASSERT_EQ’
ASSERT_EQ(OK, rc);
我把它改成了ASSERT_TRUE(OK == rc)
,类似的混乱错误。
然后我把它改为EXPECT_EQ(OK, rc)
,它编译和运行得很好!
在我看来,这是一个bug在某处测试。但是我想确认一下。
ASSERT_
宏不能用于非void函数。详细信息可在引语和此常见问题解答中找到。
相关文章:
- 无论条件是否为true,if总是在c++中执行
- flutter:即使shouldRepaint()返回true,自定义画家也不会重新绘制
- 如果条件为TRUE(最佳方式?),则在do while循环中后置增量
- Arduino-C++ bool 不会从 false 变为 true
- 如何使布尔变量仅在设置为 true 时才为真?
- 如何在 assert() 和 static_assert() 之间调度,如果在 constexpr 上下文中依赖?
- C++ 如果在 if 为 true 之后运行,为什么还会这样做
- 我关于函数"Assert"的C++代码有问题
- 为什么组合的上限和下限比较的计算结果总是为 true?
- 对于完成布尔值设置为 true 后未停止的循环
- 为什么'typeid(x) == typeid(y)'的计算结果为 true,其中 'x' 和 'y' 分别是 T 和 T& 类型的 id-表达式?
- OLE DB 大容量复制操作始终将 true 加载到位列中
- cin.fail() not returning true
- assert() 在发布模式下充当标识函数吗?
- Fmod 函数清楚地输出一个预期的双精度值,但 if(fmod == 预期的双精度值)的计算结果不是 true
- 如何使用boost定义布尔类,可能的值应该是TRUE或FALSE?
- 如何编写一个接受如下断言消息的自定义断言函数:assert(false) << "assertio
- 我在OpenCV中有错误的"approxPolyDP(ROI_Vertices, ROI_Poly, 1.0, true)"
- 如果语句表达式调用函数,则需要测试是否为 true
- 如何检查条件是否为 true 5 秒?