Print the error code when unable to create a temporary file on Windows

Help root cause a sporadic error seen when running gtest applications
This commit is contained in:
Sluis, Benjamin 2024-06-25 11:52:15 -07:00
parent f8d7d77c06
commit 08b0797178
2 changed files with 2 additions and 1 deletions

View File

@ -76,6 +76,7 @@ namespace {
TEST(FactorialTest, Negative) { TEST(FactorialTest, Negative) {
// This test is named "Negative", and belongs to the "FactorialTest" // This test is named "Negative", and belongs to the "FactorialTest"
// test case. // test case.
testing::internal::CaptureStdout();
EXPECT_EQ(1, Factorial(-5)); EXPECT_EQ(1, Factorial(-5));
EXPECT_EQ(1, Factorial(-1)); EXPECT_EQ(1, Factorial(-1));
EXPECT_GT(Factorial(-10), 0); EXPECT_GT(Factorial(-10), 0);

View File

@ -1042,7 +1042,7 @@ class CapturedStream {
0, // Generate unique file name. 0, // Generate unique file name.
temp_file_path); temp_file_path);
GTEST_CHECK_(success != 0) GTEST_CHECK_(success != 0)
<< "Unable to create a temporary file in " << temp_dir_path; << "Unable to create a temporary file in " << temp_dir_path << ". Error message: " << ::GetLastError();
const int captured_fd = creat(temp_file_path, _S_IREAD | _S_IWRITE); const int captured_fd = creat(temp_file_path, _S_IREAD | _S_IWRITE);
GTEST_CHECK_(captured_fd != -1) GTEST_CHECK_(captured_fd != -1)
<< "Unable to open temporary file " << temp_file_path; << "Unable to open temporary file " << temp_file_path;