gtest_discover_tests make a CMake Error: file failed to open for writing (Permission denied)
That issue is present in Cmake of Visual Studio 17.3 and 17.2 Here is the call stack of the error.
> MSBuild version 17.3.0+f67e3d35e for .NET Framework
Checking Build System
Scanning sources for module dependencies...
Core.vcxproj -> D:\_Dev\Projects\PersonalWorks\_Out\build\x64-debug\_lib\Core.lib
ApplicationCore.vcxproj -> D:\_Dev\Projects\PersonalWorks\_Out\build\x64-debug\_lib\ApplicationCore.lib
CoreTests.vcxproj -> D:\_Dev\Projects\PersonalWorks\_Out\build\x64-debug\_bin\CoreTests.exe
CMake Error at C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake3.23/Modules/GoogleTestAddTests.cmake:11 (file):
file failed to open for writing (Permission denied):
D:/_Dev/Projects/PersonalWorks/_Out/build/x64-debug/Projects/Core/CoreTests[1]_tests.cmake
Call Stack (most recent call first):
C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.23/Modules/GoogleTestAddTests.cmake:35 (flush_script)
C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.23/Modules/GoogleTestAddTests.cmake:175 (add_command)
C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.23/Modules/GoogleTestAddTests.cmake:225 (gtest_discover_tests_impl)
TestsUtilities.vcxproj -> D:\_Dev\Projects\PersonalWorks\_Out\build\x64-debug\_lib\TestsUtilities.lib
Every time I compile the file CoreTests[1]_tests.cmake doesn't have the same size, sometimes it is bigger and sometimes it is smaller.
On very rare occasionsBuildFaillure_CoreTests_1__tests.cmake the build will succeed. But most of the time (like 99%) the build fails. I have attached an example of success and failure. And this is on successive builds without any change to the code or make files.
It looks like a "data race" issue. It happens less often if I reduce the number of test files. It seems that generated test, like parametrized tests, makes it more likely. It also seems that it doesn't always fail on the same test as the last test in that file is not always the same.