printf-test: Add check that errno is preserved by fmt::sprintf

Since I accidentally added code to PrintfFormatter::format that modified
errno on mingw whilst adding support for '%m', it seems worth having a test
to make sure that can't happen again in the future.
This commit is contained in:
Mike Crowe 2017-07-22 14:42:37 +01:00
parent 0d46c7fb36
commit a5231b86df

View File

@ -476,6 +476,21 @@ TEST(PrintfTest, Enum) {
EXPECT_PRINTF("42", "%d", A);
}
TEST(PrintfTest, ErrnoPreserved) {
errno = ENOENT;
EXPECT_PRINTF_NO_ARG("testing 1 2 3", "testing 1 2 3");
EXPECT_EQ(errno, ENOENT);
EXPECT_PRINTF("42", "%d", 42);
EXPECT_EQ(errno, ENOENT);
EXPECT_PRINTF(" Hello", "%6s", "Hello");
EXPECT_EQ(errno, ENOENT);
EXPECT_PRINTF_NO_ARG("No such file or directory", "%m");
EXPECT_EQ(errno, ENOENT);
}
TEST(PrintfTest, ErrorMessage) {
errno = ENOENT;