[英]Google test ASSERT_EQ does not compile
I have a class, let's say it is named Foo
in which I did not define an equality operator and I do not wish to define one (for my own reasons). 我有一个类,假设它名为
Foo
在该类中我没有定义一个相等运算符,并且我也不希望定义一个(因为我自己的原因)。
I wanted to test some functions which operate on Foo and I wrote the following code: 我想测试一些在Foo上运行的功能,并编写了以下代码:
inline bool operator==(const Foo& left, const Foo& right)
{
// here I test my equality condition....
}
TEST(SomeTestCase, SomeTest)
{
Foo expected = ...
Foo actual = ...
ASSERT_EQ(expected, actual); // does NOT compile
ASSERT_TRUE(expected == actual); // compiles without a problem
}
Does anybody know how can I make ASSERT_EQ compile, so that in case of failure it will print a meaningful error message? 有人知道如何使ASSERT_EQ编译,以便在失败的情况下会打印出有意义的错误消息吗?
I am using MSVC2012 and the error message is: 我正在使用MSVC2012,错误消息是:
1>D:\3rdpartycache\CPP\gmock\1.6.0-2\sdk\gtest\include\gtest/gtest.h(1316): error C2784: 'bool testing::internal::operator ==(T *,const testing::internal::linked_ptr<T> &)' : could not deduce template argument for 'T *' from 'const Foo'
1> D:\3rdpartycache\CPP\gmock\1.6.0-2\sdk\gtest\include\gtest/internal/gtest-linked_ptr.h(213) : see declaration of 'testing::internal::operator =='
1> D:\3rdpartycache\CPP\gmock\1.6.0-2\sdk\gtest\include\gtest/gtest.h(1353) : see reference to function template instantiation 'testing::AssertionResult testing::internal::CmpHelperEQ<T1,T2>(const char *,const char *,const T1 &,const T2 &)' being compiled
1> with
1> [
1> T1=Foo,
1> T2=Foo
1> ]
1> OperationsOnFooTest.cpp(146) : see reference to function template instantiation 'testing::AssertionResult testing::internal::EqHelper<lhs_is_null_literal>::Compare<Foo,T>(const char *,const char *,const T1 &,const T2 &)' being compiled
1> with
1> [
1> lhs_is_null_literal=false,
1> T=Foo,
1> T1=Foo,
1> T2=Foo
1> ]
1> OperationsOnFooTest.cpp(146) : see reference to function template instantiation 'testing::AssertionResult testing::internal::EqHelper<lhs_is_null_literal>::Compare<Foo,T>(const char *,const char *,const T1 &,const T2 &)' being compiled
1> with
1> [
1> lhs_is_null_literal=false,
1> T=Foo,
1> T1=Foo,
1> T2=Foo
1> ]
Try to verify that your operator== and Foo class are in same namespace. 尝试验证您的operator ==和Foo类是否在同一名称空间中。 I experienced a similar error that solved this way.
我遇到了类似的错误,此问题已解决。
You are right about the ASSERT_EQ compile error message though... not really helpful... 尽管您对ASSERT_EQ编译错误消息的看法是正确的,但是并没有真正的帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.