diff options
author | Victor Leschuk <vleschuk@accesssoftek.com> | 2018-07-26 02:21:40 +0000 |
---|---|---|
committer | Victor Leschuk <vleschuk@accesssoftek.com> | 2018-07-26 02:21:40 +0000 |
commit | e58e9907aca25316afad9573df077325f717ef18 (patch) | |
tree | ba0e9e53a6bb6ad0fc782e2377bf5addb40ac3d5 /llvm/unittests/Support/ErrorTest.cpp | |
parent | fdd089aa14d90fcf220d54fb3fbfd2170f89de78 (diff) | |
download | llvm-e58e9907aca25316afad9573df077325f717ef18.zip llvm-e58e9907aca25316afad9573df077325f717ef18.tar.gz llvm-e58e9907aca25316afad9573df077325f717ef18.tar.bz2 |
[Support] Introduce createStringError helper function
The function in question is copy-pasted lots of times in DWARF-related classes.
Thus it will make sense to place its implementation into the Support library.
Reviewed by: lhames
Differential Revision: https://reviews.llvm.org/D49824
llvm-svn: 337995
Diffstat (limited to 'llvm/unittests/Support/ErrorTest.cpp')
-rw-r--r-- | llvm/unittests/Support/ErrorTest.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/llvm/unittests/Support/ErrorTest.cpp b/llvm/unittests/Support/ErrorTest.cpp index 2f9ce2d..66ffd23 100644 --- a/llvm/unittests/Support/ErrorTest.cpp +++ b/llvm/unittests/Support/ErrorTest.cpp @@ -443,6 +443,29 @@ TEST(Error, StringError) { << "Failed to convert StringError to error_code."; } +TEST(Error, createStringError) { + static const char *Bar = "bar"; + static const std::error_code EC = errc::invalid_argument; + std::string Msg; + raw_string_ostream S(Msg); + logAllUnhandledErrors(createStringError(EC, "foo%s%d0x%" PRIx8, Bar, 1, 0xff), + S, ""); + EXPECT_EQ(S.str(), "foobar10xff\n") + << "Unexpected createStringError() log result"; + + S.flush(); + Msg.clear(); + logAllUnhandledErrors(createStringError(EC, Bar), S, ""); + EXPECT_EQ(S.str(), "bar\n") + << "Unexpected createStringError() (overloaded) log result"; + + S.flush(); + Msg.clear(); + auto Res = errorToErrorCode(createStringError(EC, "foo%s", Bar)); + EXPECT_EQ(Res, EC) + << "Failed to convert createStringError() result to error_code."; +} + // Test that the ExitOnError utility works as expected. TEST(Error, ExitOnError) { ExitOnError ExitOnErr; |