diff options
author | Pavel Labath <pavel@labath.sk> | 2019-08-14 13:33:28 +0000 |
---|---|---|
committer | Pavel Labath <pavel@labath.sk> | 2019-08-14 13:33:28 +0000 |
commit | 40837e97b199b4d6546df9f8912e14a56c434417 (patch) | |
tree | 99297768aa856be011a1fd62ef93806f019e2eb5 /llvm/unittests/Support/ErrorTest.cpp | |
parent | 4894eeecc99d9729259dba54efc207be4bc4ddf5 (diff) | |
download | llvm-40837e97b199b4d6546df9f8912e14a56c434417.zip llvm-40837e97b199b4d6546df9f8912e14a56c434417.tar.gz llvm-40837e97b199b4d6546df9f8912e14a56c434417.tar.bz2 |
raw_ostream: add operator<< overload for std::error_code
Summary:
The main motivation for this is unit tests, which contain a large macro
for pretty-printing std::error_code, and this macro is duplicated in
every file that needs to do this. However, the functionality may be
useful elsewhere too.
In this patch I have reimplemented the existing ASSERT_NO_ERROR macros
to reuse the new functionality, but I have kept the macro (as a
one-liner) as it is slightly more readable than ASSERT_EQ(...,
std::error_code()).
Reviewers: sammccall, ilya-biryukov
Subscribers: zturner, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65643
llvm-svn: 368849
Diffstat (limited to 'llvm/unittests/Support/ErrorTest.cpp')
-rw-r--r-- | llvm/unittests/Support/ErrorTest.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/llvm/unittests/Support/ErrorTest.cpp b/llvm/unittests/Support/ErrorTest.cpp index c4a9f3e..ec5c30b5 100644 --- a/llvm/unittests/Support/ErrorTest.cpp +++ b/llvm/unittests/Support/ErrorTest.cpp @@ -933,7 +933,7 @@ public: class TestErrorCategory : public std::error_category { public: - const char *name() const noexcept override { return "error"; } + const char *name() const noexcept override { return "test_error"; } std::string message(int Condition) const override { switch (static_cast<test_error_code>(Condition)) { case test_error_code::unspecified: @@ -975,4 +975,11 @@ TEST(Error, SubtypeStringErrorTest) { 0); } +TEST(Error, error_codeErrorMessageTest) { + EXPECT_NONFATAL_FAILURE( + EXPECT_EQ(make_error_code(test_error_code::unspecified), + make_error_code(test_error_code::error_2)), + "Which is: An unknown error has occurred. (test_error:1)"); +} + } // namespace |