commit | c6efce1e7839de5e263954f0df4e85a97d7fed07 | [log] [tgz] |
---|---|---|
author | Jiyong Park <jiyong@google.com> | Mon Dec 20 15:17:58 2021 +0900 |
committer | Jiyong Park <jiyong@google.com> | Fri Dec 31 11:19:49 2021 +0900 |
tree | 8170b985027bad54f2bfcc85f891b8b889fc3c7a | |
parent | 7706f49b24f10d6943ca0c6ea516d959e066b802 [diff] |
ASSERT/EXPECT_RESULT_OK follows gtest style. Like other macros ASSERT_* and EXPECT_* from gtest, ASSERT_RESULT_OK and EXPECT_RESULT_OK now accepts additional error message via "<<" operator at the end. e.g. ASSERT_RESULT_OK(stmt) << "custom message"; This change also fixes a bug that "tmp.ok()" is printed instead of the expression that is given to the macro. In addition, this change removes CHECK_RESULT_OK which is not used anywhere. It has had a potential problem due to its dependency to android-base/logging.h because that header is not available everywhere. Test: build and run the following statement. ASSERT_RESULT_OK([]() -> Result<int> { return Error(EPERM) << "custom error"; }()) << "assertion message"; It builds, and the output is ... system/libbase/result_test.cpp:604: Failure Failed Value of: []() -> Result<int> { return Error(EPERM) << "custom error"; }() Actual: custom error: Operation not permitted Expected: is ok assertion message Bug: 210629279 Change-Id: I6abcededec71e3edfb7e5c8bf28d56074c69d623
This library is a collection of convenience functions to make common tasks easier and less error-prone.
In this context, "error-prone" covers both "hard to do correctly" and "hard to do with good performance", but as a general purpose library, libbase's primary focus is on making it easier to do things easily and correctly when a compromise has to be made between "simplest API" on the one hand and "fastest implementation" on the other. Though obviously the ideal is to have both.
The intention is to cover the 80% use cases, not be all things to all users.
If you have a routine that's really useful in your project, congratulations. But that doesn't mean it should be here rather than just in your project.
The question for libbase is "should everyone be doing this?"/"does this make everyone's code cleaner/safer?". Historically we've considered the bar for inclusion to be "are there at least three unrelated projects that would be cleaned up by doing so".
If your routine is actually something from a future C++ standard (that isn't yet in libc++), or it's widely used in another library, that helps show that there's precedent. Being able to say "so-and-so has used this API for n years" is a good way to reduce concerns about API choices.
Unlike most Android code, code in libbase has to build for Mac and Windows too.
Code here is also expected to have good test coverage.
By its nature, it's difficult to change libbase API. It's often best to start using your routine just in your project, and let it "graduate" after you're certain that the API is solid.