googletest
googletest copied to clipboard
[Bug]: No details about why GetTempFileName fails
Describe the issue
When using gtest on Windows, I'm seeing sporadic messages saying "Unable to create a temporary file in " and the path to the temp folder. These messages are coming from third_party/gtest/src/gtest-port.cc, L1045. I would like this line to include a call to GetLastError so that I can get more information from the operating system about what exactly is going wrong so I can fix my sporadic error.
Requested addition:
GTEST_CHECK_(success != 0)
<< "Unable to create a temporary file in " << temp_dir_path << ". Error code: " << ::GetLastError();
Steps to reproduce the problem
Download the git repo at https://github.com/BenSluis/googletest, checkout the error_code_temp_file branch.
Build samples:
cd googletest
mkdir build
cd build
cmake.exe .. -Dgtest_build_samples=ON
cmake.exe --build . --config Debug
Run sample1 with the custom changes from https://github.com/BenSluis/googletest/tree/error_code_temp_file .
set TMP=E:\badtemppath
cd googletest\Debug
sample1_unittest.exe
It should show the last error message and exits with 3.
Running main() from E:\googletest\googletest\src\gtest_main.cc [==========] Running 6 tests from 2 test suites. [----------] Global test environment set-up. [----------] 3 tests from FactorialTest [ RUN ] FactorialTest.Negative
[ FATAL ] E:\googletest\googletest\src/gtest-port.cc(1044):: Condition success != 0 failed. Unable to create a temporary file in E:\badtemppath. Error code: 267
Without the GetLastError change, it shows the following and exits with 3.
Running main() from E:\googletest\googletest\src\gtest_main.cc [==========] Running 6 tests from 2 test suites. [----------] Global test environment set-up. [----------] 3 tests from FactorialTest [ RUN ] FactorialTest.Negative
[ FATAL ] E:\googletest\googletest\src/gtest-port.cc(1044):: Condition success != 0 failed. Unable to create a temporary file in E:\badtemppath\
What version of GoogleTest are you using?
v1.14.0
What operating system and version are you using?
- Windows Server 2022, 10.0.20348
- Windows 11, 10.0.22631
What compiler and version are you using?
MSVC 19.40.33811.0
What build system are you using?
cmake version 3.27.1
Additional context
No response