aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/Support/ErrorTest.cpp
diff options
context:
space:
mode:
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,