Skip to content

Add back support for explicit template for *Return(obj). #337

@FranckRJ

Description

@FranckRJ

The syntax .Return<type>(obj) to force the object to be copied and .Return<type&>(obj) to force the object to be captured by reference have been removed by #330 be caused it caused issues with the new implementation of .Return(obj), and because it was not a real documented feature (but more a by-product of the implementation), I supposed no one was relying on it.

It turns out that some people use this feature (see #200 (comment) and #336 (comment)), not only to change the behavior of .Return(obj), but also to have a consistent behavior, i.e. having .Return(obj) do the same thing regardless of if the mocked function return a reference or an object.

What should be done:

  • Reintroduce back the support for .Return<type>(obj) and .Return<type&>(obj) to not break to much code with the new update, maybe mark them as deprecated:
  • .Return<type>(obj)
  • .Return<type&>(obj)
  • Make .ReturnCapture(obj) available on any function (those that return a reference and those that does not) so it can be used as a default when the user ALWAYS want to capture the value of the object, regardless of the return type of the mocked function.
  • Add an equivalent to .ReturnCapture(obj) but that forces the capture of the object by reference, this feature already as its own issue ((Always)Return doesn't seem to allow capturing locals by reference? #200).
  • Extend the two functions mentioned above so they support the extra features of Return (e.g. .Return(obj1, obj2, ...), .Return(val_Times(5)), maybe more).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions