Conversation
|
Oh i didn't tested the formatting of the error of the matcher. |
| When(Method(mock, strfunc).Using(StrEq("second"))).Return(2); | ||
|
|
||
| SomeInterface &i = mock.get(); | ||
| ASSERT_EQUAL(1, i.strfunc("first")); |
There was a problem hiding this comment.
Will this work if the const char* is pointing to a temporary, instead of a literal?
There was a problem hiding this comment.
I looked a bit more, matchers aren't really design to hold copy of stuff, they just hold references. The issue is the same for all matchers, so I won't change it only for this one.
Like others matchers, it's up to the user to ensure that the references that are passed stay valid for the lifetime of the matcher.
There was a problem hiding this comment.
Like you said in another message maybe it could be improved depending of the value category of the variable but it's outside of the scope of this PR i think.
There was a problem hiding this comment.
yeah - I see no problem. Could be a future improvement. (I'm just seeing lots of scope for small improvements in this library in general)
There was a problem hiding this comment.
Re "references" in general. There are a number of cases where Fakeit stops temporaries and/or rvalue refs from being used (this one, const char*, is less likely to have issues with temporaries though).
And so sometimes makes the tests a little more complicated than necessarily, and adds more gotchas, where it might be possible to avoid.
|
If the temporary is not valid anymore, then no. But I guess it's a reasonable requirement for this kind of stuff, no ?
Or do you think I should strdup the string to store it somewhere ?
…-------- Message d'origine --------
Le 18 nov. 2021, 01:44, Malcolm Davey a écrit :
@malcolmdavey commented on this pull request.
---------------------------------------------------------------
In [tests/argument_matching_tests.cpp](#256 (comment)):
> @@ -165,6 +167,21 @@ struct ArgumentMatchingTests: tpunit::TestFixture {
Verify(Method(mock, func).Using(Ne(10))).Twice();
}
+ void test_str_eq_matcher() {
+
+ Mock<SomeInterface> mock;
+
+ When(Method(mock, strfunc).Using(StrEq("first"))).Return(1);
+ When(Method(mock, strfunc).Using(StrEq("second"))).Return(2);
+
+ SomeInterface &i = mock.get();
+ ASSERT_EQUAL(1, i.strfunc("first"));
Will this work if the const char* is pointing to a temporary, instead of a literal?
—
You are receiving this because you authored the thread.
Reply to this email directly, [view it on GitHub](#256 (review)), or [unsubscribe](https://github.com/notifications/unsubscribe-auth/ABX5ET6ZYGEUKPKDXGY3RBTUMRD7ZANCNFSM5CTIOSSQ).
Triage notifications on the go with GitHub Mobile for [iOS](https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675) or [Android](https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub).
|
Short answer - yes, ideally. Just for clarity, as I was not sure if I was clear. Was referring to the I think most of the time you can get away without the copy, but also thinking of how to make the library more complete/forgiving, and not always needing to worry about cases of potentially dangling references. Had been looking at the other main case where we currently only story references, and was thinking if and how we could find ways to store a copy (either in some cases implicitly where we can detect it makes sense - e.g. revalue ref, or explicitly - will working on some ideas for it). |
|
You're right. I'll change that to copy the string.
…-------- Message d'origine --------
Le 22 nov. 2021, 07:53, Malcolm Davey a écrit :
> If the temporary is not valid anymore, then no. But I guess it's a reasonable requirement for this kind of stuff, no ? Or do you think I should strdup the string to store it somewhere ?
Short answer - yes, ideally.
Just for clarity, as I was not sure if I was clear. Was referring to the Using lines, and other if it made sense to use a copy.
When(Method(mock, strfunc).Using(StrEq("first"))).Return(1);
I think most of the time you can get away without the copy, but also thinking of how to make the library more complete/forgiving, and not always needing to worry about cases of potentially dangling references.
Had been looking at the other main case where we currently only story references, and was thinking if and how we could find ways to store a copy (either in some cases implicitly where we can detect it makes sense - e.g. revalue ref, or explicitly - will working on some ideas for it).
—
You are receiving this because you authored the thread.
Reply to this email directly, [view it on GitHub](#256 (comment)), or [unsubscribe](https://github.com/notifications/unsubscribe-auth/ABX5ETY55Z2F5PE5WF3S6ITUNHSFHANCNFSM5CTIOSSQ).
Triage notifications on the go with GitHub Mobile for [iOS](https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675) or [Android](https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub).
|
|
Also I haven't really tested out the |
eb10dc6 to
65e9cab
Compare
65e9cab to
5529f49
Compare
No description provided.