summaryrefslogtreecommitdiff
path: root/absl/status/statusor_test.cc
diff options
context:
space:
mode:
authorGravatar Dino Radakovic <dinor@google.com>2023-05-04 12:37:11 -0700
committerGravatar Copybara-Service <copybara-worker@google.com>2023-05-04 12:38:14 -0700
commitb2abe7ad28fd79cbb889dbf9814292be495f04ed (patch)
tree1193cbd2a4883a4f45711e12b801f9ff097df5a5 /absl/status/statusor_test.cc
parent3d604bc673b8c6d72a45afdfdc24e9d442b6f372 (diff)
Make `absl::StatusOr::AssignStatus` public. Recommend against using it outside of generic programming
PiperOrigin-RevId: 529484669 Change-Id: I9889a9f7a7fa7dc6ef8c731f1b583a74e6afd2cf
Diffstat (limited to 'absl/status/statusor_test.cc')
-rw-r--r--absl/status/statusor_test.cc33
1 files changed, 33 insertions, 0 deletions
diff --git a/absl/status/statusor_test.cc b/absl/status/statusor_test.cc
index 29021543..e65f5d27 100644
--- a/absl/status/statusor_test.cc
+++ b/absl/status/statusor_test.cc
@@ -1844,4 +1844,37 @@ TEST(StatusOr, AssignmentFromTypeConvertibleToStatus) {
}
}
+TEST(StatusOr, StatusAssignmentFromStatusError) {
+ absl::StatusOr<absl::Status> statusor;
+ statusor.AssignStatus(absl::CancelledError());
+
+ EXPECT_FALSE(statusor.ok());
+ EXPECT_EQ(statusor.status(), absl::CancelledError());
+}
+
+#if GTEST_HAS_DEATH_TEST
+TEST(StatusOr, StatusAssignmentFromStatusOk) {
+ EXPECT_DEBUG_DEATH(
+ {
+ absl::StatusOr<absl::Status> statusor;
+ // This will DCHECK.
+ statusor.AssignStatus(absl::OkStatus());
+ // In optimized mode, we are actually going to get error::INTERNAL for
+ // status here, rather than crashing, so check that.
+ EXPECT_FALSE(statusor.ok());
+ EXPECT_EQ(statusor.status().code(), absl::StatusCode::kInternal);
+ },
+ "An OK status is not a valid constructor argument to StatusOr<T>");
+}
+#endif
+
+TEST(StatusOr, StatusAssignmentFromTypeConvertibleToStatus) {
+ CustomType<MyType, kConvToStatus> v;
+ absl::StatusOr<MyType> statusor;
+ statusor.AssignStatus(v);
+
+ EXPECT_FALSE(statusor.ok());
+ EXPECT_EQ(statusor.status(), static_cast<absl::Status>(v));
+}
+
} // namespace