diff options
author | Abseil Team <absl-team@google.com> | 2022-04-19 13:56:51 -0700 |
---|---|---|
committer | Andy Getz <durandal@google.com> | 2022-04-19 18:08:40 -0400 |
commit | 3dccef2a91243460364312d3e1100ff1d573fb1d (patch) | |
tree | 21dc4da934d938d21c013caae13a2be8c8a6ca29 /absl/status/status_test.cc | |
parent | c27ab06897f330267bed99061ed3e523e2606bf1 (diff) |
Export of internal Abseil changes
--
6457ad659de86ce4cae1e9f7cb03a701c6c2851e by Abseil Team <absl-team@google.com>:
Introduced ErrnoToStatusCode and ErrnoToStatus to abseil.
PiperOrigin-RevId: 442903450
Change-Id: I9c062b34a3811216f43eef56e631eada3b4e3e84
GitOrigin-RevId: 6457ad659de86ce4cae1e9f7cb03a701c6c2851e
Diffstat (limited to 'absl/status/status_test.cc')
-rw-r--r-- | absl/status/status_test.cc | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/absl/status/status_test.cc b/absl/status/status_test.cc index 1b038f6d..89cce7df 100644 --- a/absl/status/status_test.cc +++ b/absl/status/status_test.cc @@ -14,6 +14,8 @@ #include "absl/status/status.h" +#include <errno.h> + #include "gmock/gmock.h" #include "gtest/gtest.h" #include "absl/strings/str_cat.h" @@ -485,4 +487,22 @@ TEST(Status, Swap) { test_swap(no_payload, with_payload); test_swap(with_payload, no_payload); } + +TEST(StatusErrno, ErrnoToStatusCode) { + EXPECT_EQ(absl::ErrnoToStatusCode(0), absl::StatusCode::kOk); + + // Spot-check a few errno values. + EXPECT_EQ(absl::ErrnoToStatusCode(EINVAL), + absl::StatusCode::kInvalidArgument); + EXPECT_EQ(absl::ErrnoToStatusCode(ENOENT), absl::StatusCode::kNotFound); + + // We'll pick a very large number so it hopefully doesn't collide to errno. + EXPECT_EQ(absl::ErrnoToStatusCode(19980927), absl::StatusCode::kUnknown); +} + +TEST(StatusErrno, ErrnoToStatus) { + absl::Status status = absl::ErrnoToStatus(ENOENT, "Cannot open 'path'"); + EXPECT_EQ(status.code(), absl::StatusCode::kNotFound); + EXPECT_EQ(status.message(), "Cannot open 'path': No such file or directory"); +} } // namespace |