CTest Error: Unable to find test executable on MacOS
On MacOS, CTest fails to find the test executable, even when it is there. I run the following:
ctest -C $(BuildConfiguration) --output-on-failure
where BuildConfiguration
is a variable that we use for managing our build configuration (Debug or RelWithDebInfo).
On MacOS, ctest
fails to find the test executable even when it is there. This runs fine on Windows and Linux.
In the Test stage on MacOS, I am getting the error:
Test project /home/vsts/work/1/s/Debug
Start 1: StringOperations_CaseIgnore Could not find executable /Users/runner/work/1/s/Debug/Tests/StringOperations/TestStringOperations
Looked in the following places:
/Users/runner/work/1/s/Debug/Tests/StringOperations/TestStringOperations
/Users/runner/work/1/s/Debug/Tests/StringOperations/TestStringOperations
/Users/runner/work/1/s/Debug/Tests/StringOperations/Debug/TestStringOperations
/Users/runner/work/1/s/Debug/Tests/StringOperations/Debug/TestStringOperations
Debug//Users/runner/work/1/s/Debug/Tests/StringOperations/TestStringOperations
Debug//Users/runner/work/1/s/Debug/Tests/StringOperations/TestStringOperations
Users/runner/work/1/s/Debug/Tests/StringOperations/TestStringOperations
Users/runner/work/1/s/Debug/Tests/StringOperations/TestStringOperations
Users/runner/work/1/s/Debug/Tests/StringOperations/Debug/TestStringOperations
Users/runner/work/1/s/Debug/Tests/StringOperations/Debug/TestStringOperations
Debug/Users/runner/work/1/s/Debug/Tests/StringOperations/TestStringOperations
Debug/Users/runner/work/1/s/Debug/Tests/StringOperations/TestStringOperations
1/1 Test #1: StringOperations_CaseIgnore ......***Not Run 0.00 sec
0% tests passed, 1 tests failed out of 1
Total Test time (real) = 0.00 sec
The following tests FAILED: 1 - StringOperations_CaseIgnore (Not
Run) Unable to find executable:
/Users/runner/work/1/s/Debug/Tests/StringOperations/TestStringOperations
Errors while running CTest
I have tried to check whether the test executable is actually there or not by using:
ls -l Debug/Tests/StringOperations
And here's the output:
drwxr-xr-x 3 vsts docker 4096 Aug 6 15:05 CMakeFiles
-rw-r--r-- 1 vsts docker 1208 Aug 6 15:05 cmake_install.cmake
-rw-r--r-- 1 vsts docker 642 Aug 6 15:05 CTestTestfile.cmake
-rw-r--r-- 1 vsts docker 9838 Aug 6 15:05 Makefile
-rwxr--r-- 1 vsts docker 1715072 Aug 6 15:05 TestStringOperations
This confirms that the test executable (TestStringOperations) is there at the same place where it was for Windows and Linux, but still the process fails.
Here is the CMakeLists.txt for this executable should you need it:
Set(SRC StringOperations.cpp)
Add_Executable(TestStringOperations ${SRC})
Target_Include_Directories(TestStringOperations PUBLIC
${HEADER_PATH}/StringOperations
)
Target_Link_Libraries(TestStringOperations
PRIVATE ${GTEST_LIBS}
PRIVATE StringOperations
)
Add_Test(NAME StringOperations_CaseIgnore COMMAND TestStringOperations)
I have also tried replacing the last command in my CMakeLists.txt file with the following:
GTest_Discover_Tests(TestStringOperations)
But this time, I get the error:
Test project /home/vsts/work/1/s/Debug
CMake Error at /home/vsts/work/1/s/Debug/test/StringOperations/CTestTestfile.cmake:7 (include):
include could not find load file:
/Users/runner/work/1/s/Debug/test/StringOperations/TestStringOperations[1]_include.cmake
Call Stack (most recent call first):
/home/vsts/work/1/s/Debug/test/CTestTestfile.cmake:7 (subdirs)
CTestTestfile.cmake:9 (subdirs)
No tests were found!!!
I think that this issue has lasted from a long time in CTest. Many people have asked about this issue before.
See this for example.