gpt4 book ai didi

c++ - 可能是 gtest 错误 - ASSERT_EQ 和 ASSERT_TRUE 编译失败

转载 作者:太空狗 更新时间:2023-10-29 20:59:45 30 4
gpt4 key购买 nike

我正在使用最新的 gtest。以下代码编译失败:

Error_code rc = some_function();
ASSERT_EQ(OK, rc);

Error_code 是一个枚举类型定义:

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),它编译并运行得很好!

在我看来,这是 gtest 某处的错误。但想确认一下。

最佳答案

ASSERT_ 宏不能在非空函数中使用。详情可在 primer 找到还有这个FAQ item .

关于c++ - 可能是 gtest 错误 - ASSERT_EQ 和 ASSERT_TRUE 编译失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23925131/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com