From 6ec1389de245256ddf846bafa815f98c4b6e1fe1 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Thu, 1 May 2014 08:02:55 -0700 Subject: [PATCH] Test SystemErrorSink. --- format-test.cc | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/format-test.cc b/format-test.cc index 989b401e..f8987d62 100644 --- a/format-test.cc +++ b/format-test.cc @@ -310,6 +310,23 @@ TEST(UtilTest, SystemError) { EXPECT_EQ(42, e.error_code()); } +// TODO: test WinErrorSink, FormatSystemErrorMessage, FormatWinErrorMessage + +TEST(UtilTest, SystemErrorSink) { + const int TEST_ERROR = EDOM; + fmt::SystemError error("", 0); + fmt::SystemErrorSink sink(TEST_ERROR); + fmt::Writer w; + w << "test"; + try { + sink(w); + } catch (const fmt::SystemError &e) { + error = e; + } + EXPECT_EQ(str(fmt::Format("test: {}") << strerror(TEST_ERROR)), error.what()); + EXPECT_EQ(TEST_ERROR, error.error_code()); +} + TEST(UtilTest, ThrowSystemError) { const int TEST_ERROR = EDOM; fmt::SystemError error("", 0); @@ -1695,8 +1712,6 @@ TEST(FormatterTest, FileSinkWriteError) { std::fclose(f); } -// TODO: test SystemErrorSink, ThrowSystemError, CErrorSink, ThrowWinError. - // The test doesn't compile on older compilers which follow C++03 and // require an accessible copy constructor when binding a temporary to // a const reference.