aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/Support/ErrorTest.cpp
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2021-09-14 15:13:19 -0400
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2021-11-12 21:19:09 -0800
commit79c5479822e6039f764968225181b93f4c2924ad (patch)
tree5eecb8740c3f0c88aa6ff44820ff9b2d68876858 /llvm/unittests/Support/ErrorTest.cpp
parent6b9b86db9dd974585a5c71cf2e5231d1e3385f7c (diff)
downloadllvm-79c5479822e6039f764968225181b93f4c2924ad.zip
llvm-79c5479822e6039f764968225181b93f4c2924ad.tar.gz
llvm-79c5479822e6039f764968225181b93f4c2924ad.tar.bz2
Support: Pass wrapped Error's error code through FileError
Change FileError to pass through the error code from the Error it wraps. This allows APIs that return ECError to transition to FileError without changing returned std::error_code. This was extracted from https://reviews.llvm.org/D109345. Differential Revision: https://reviews.llvm.org/D113225
Diffstat (limited to 'llvm/unittests/Support/ErrorTest.cpp')
-rw-r--r--llvm/unittests/Support/ErrorTest.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/llvm/unittests/Support/ErrorTest.cpp b/llvm/unittests/Support/ErrorTest.cpp
index 4d557cc..3ca94b2 100644
--- a/llvm/unittests/Support/ErrorTest.cpp
+++ b/llvm/unittests/Support/ErrorTest.cpp
@@ -963,6 +963,33 @@ TEST(Error, FileErrorTest) {
});
}
+TEST(Error, FileErrorErrorCode) {
+ for (std::error_code EC : {
+ make_error_code(std::errc::not_supported),
+ make_error_code(std::errc::invalid_argument),
+ make_error_code(std::errc::no_such_file_or_directory),
+ }) {
+ EXPECT_EQ(EC, errorToErrorCode(
+ createFileError("file.bin", EC)));
+ EXPECT_EQ(EC, errorToErrorCode(
+ createFileError("file.bin", /*Line=*/5, EC)));
+ EXPECT_EQ(EC, errorToErrorCode(
+ createFileError("file.bin", errorCodeToError(EC))));
+ EXPECT_EQ(EC, errorToErrorCode(
+ createFileError("file.bin", /*Line=*/5, errorCodeToError(EC))));
+ }
+
+ // inconvertibleErrorCode() should be wrapped to avoid a fatal error.
+ EXPECT_EQ(
+ "A file error occurred.",
+ errorToErrorCode(createFileError("file.bin", inconvertibleErrorCode()))
+ .message());
+ EXPECT_EQ(
+ "A file error occurred.",
+ errorToErrorCode(createFileError("file.bin", /*Line=*/5, inconvertibleErrorCode()))
+ .message());
+}
+
enum class test_error_code {
unspecified = 1,
error_1,