abseil-cpp icon indicating copy to clipboard operation
abseil-cpp copied to clipboard

absl::Status matchers in googletest

Open jiawen opened this issue 4 years ago • 9 comments
trafficstars

This may be more of a question for googletest. Now that absl::Status is available, I was wondering if the community should expect a corresponding set of matchers such as EXPECT_OK. It would make testing code that returns absl::Status nicer.

jiawen avatar Apr 28 '21 05:04 jiawen

Some of the maintainers of Abseil also maintain GoogleTest :-)

The answer is that we do plan on releasing the absl::Status matchers, though the plan is to release them in Abseil, not GoogleTest.

There are some things that we have to figure out how to deal with though. Abseil doesn't release forks of code, though sometimes we do strip out features. It would be easy if we just forked them, but it would make maintenance harder. We do have a plan to deal with the issues, but it will take some time. I can't give you an estimate of when this might happen.

If you need them in the short term, you might be able to copy a simple implementation from https://github.com/abseil/abseil-cpp/blob/bcc11a8918f8cc9b43c9a0dc5da7b52d48452bd3/absl/status/statusor_test.cc#L46-L161

derekmauro avatar Apr 28 '21 13:04 derekmauro

Awesome, thanks! Looking forward to it!

Also, I'm happy to contribute to abseil the RETURN_IF_ERROR and ASSIGN_OR_RETURN macros as seen elsewhere on the web if the project finds them useful (and if plans aren't already underway).

jiawen avatar May 16 '21 18:05 jiawen

It would be great to have RETURN_IF_ERROR and ASSIGN_OR_RETURN macros in the public API, since these help a lot to write concise yet fairly readable code IMHO.

ormandi avatar Apr 05 '22 19:04 ormandi

Just wanted to bubble this back up now that GoogleTest has officially announced plans to take on abseil as a dependency :).

jiawen avatar Sep 12 '22 19:09 jiawen

Until RETURN_IF_ERROR and ASSIGN_OR_RETURN become part of abseil, I've posted a bazel target for them here.

jimrogerz avatar Jul 11 '23 00:07 jimrogerz

Are there any updates to this? Currently, there are various versions of these matchers floating around in various OSS projects. Having an officially-supported version of the macros, as well as matchers like IsStatus, will be greatly helpful.

davidzchen avatar Mar 21 '24 22:03 davidzchen

Are there any updates to this? Currently, there are various versions of these matchers floating around in various OSS projects. Having an officially-supported version of the macros, as well as matchers like IsStatus, will be greatly helpful.

Someone (not me) is actively working on this. There is a surprising amount of work though.

derekmauro avatar Mar 21 '24 22:03 derekmauro

The absl::Status GoogleTest matchers are now published: https://github.com/abseil/abseil-cpp/blob/master/absl/status/status_matchers.h

Note that EXPECT_OK is intentionally not included. Use EXPECT_THAT(status, IsOk()) instead.

The macros like RETURN_IF_ERROR are probably a few months away. We currently believe that there are some performance wins we can get by changing their current interface, so we want to investigate making that change before releasing them.

derekmauro avatar May 03 '24 23:05 derekmauro

Woot! Thanks @derekmauro!

jiawen avatar May 05 '24 20:05 jiawen