Tests: Forward tested CMake generator to more cases

This commit is contained in:
Brad King 2025-01-13 14:49:55 -05:00
parent 8913b83d7f
commit a02b70a23f
6 changed files with 37 additions and 30 deletions

View File

@ -111,10 +111,20 @@ if(CMake_ENABLE_DEBUGGER)
add_executable(testDebuggerNamedPipe testDebuggerNamedPipe.cxx)
target_link_libraries(testDebuggerNamedPipe PRIVATE CMakeLib)
set(testDebuggerNamedPipe_Project_ARGS
"$<TARGET_FILE:cmake>" ${CMAKE_CURRENT_SOURCE_DIR}/DebuggerSample ${CMAKE_CURRENT_BINARY_DIR}/DebuggerSample
"$<TARGET_FILE:cmake>" -S ${CMAKE_CURRENT_SOURCE_DIR}/DebuggerSample -B ${CMAKE_CURRENT_BINARY_DIR}/DebuggerSample
--fresh -G ${CMAKE_GENERATOR}
)
if(CMAKE_GENERATOR_PLATFORM)
list(APPEND testDebuggerNamedPipe_Project_ARGS -A "${CMAKE_GENERATOR_PLATFORM}")
endif()
if(CMAKE_GENERATOR_TOOLSET)
list(APPEND testDebuggerNamedPipe_Project_ARGS -T "${CMAKE_GENERATOR_TOOLSET}")
endif()
if(CMAKE_GENERATOR_INSTANCE)
list(APPEND testDebuggerNamedPipe_Project_ARGS "-DCMAKE_GENERATOR_INSTANCE=${CMAKE_GENERATOR_INSTANCE}")
endif()
set(testDebuggerNamedPipe_Script_ARGS
"$<TARGET_FILE:cmake>" ${CMAKE_CURRENT_SOURCE_DIR}/DebuggerSample/script.cmake
"$<TARGET_FILE:cmake>" -P ${CMAKE_CURRENT_SOURCE_DIR}/DebuggerSample/script.cmake
)
foreach(case Project Script)
add_test(NAME CMakeLib.testDebuggerNamedPipe-${case} COMMAND testDebuggerNamedPipe ${testDebuggerNamedPipe_${case}_ARGS})

View File

@ -12,6 +12,9 @@
#include <thread>
#include <vector>
#include <cm/string_view>
#include <cmext/string_view>
#include <cm3p/cppdap/io.h>
#include "cmsys/RegularExpression.hxx"
@ -60,22 +63,20 @@ static void sendCommands(std::shared_ptr<dap::ReaderWriter> const& debugger,
*/
int runTest(int argc, char* argv[])
{
if (argc < 3) {
if (argc < 4) {
std::cout << "Usage:\n";
std::cout << "\t(project mode) TestDebuggerNamedPipe <CMakePath> "
"<SourceFolder> <OutputFolder>\n";
std::cout << "\t(script mode) TestDebuggerNamedPipe <CMakePath> "
std::cout << "\t(project mode) TestDebuggerNamedPipe <CMakePath> -S "
"<SourceFolder> -B <OutputFolder> ...\n";
std::cout << "\t(script mode) TestDebuggerNamedPipe <CMakePath> -P "
"<ScriptPath>\n";
return 1;
}
bool scriptMode = argc == 3;
#ifdef _WIN32
std::string namedPipe = R"(\\.\pipe\LOCAL\CMakeDebuggerPipe_)" +
cmCryptoHash(cmCryptoHash::AlgoSHA256)
.HashString(scriptMode ? argv[2] : argv[3]);
cmCryptoHash(cmCryptoHash::AlgoSHA256).HashString(argv[2]);
#else
bool const scriptMode = argv[2] == "-P"_s;
std::string namedPipe =
std::string("CMakeDebuggerPipe") + (scriptMode ? "Script" : "Project");
#endif
@ -85,16 +86,7 @@ int runTest(int argc, char* argv[])
cmakeCommand.emplace_back("--debugger");
cmakeCommand.emplace_back("--debugger-pipe");
cmakeCommand.emplace_back(namedPipe);
if (scriptMode) {
cmakeCommand.emplace_back("-P");
cmakeCommand.emplace_back(argv[2]);
} else {
cmakeCommand.emplace_back("-S");
cmakeCommand.emplace_back(argv[2]);
cmakeCommand.emplace_back("-B");
cmakeCommand.emplace_back(argv[3]);
}
cmakeCommand.insert(cmakeCommand.end(), argv + 2, argv + argc);
// Capture debugger response stream.
std::stringstream debuggerResponseStream;

View File

@ -1,15 +1,17 @@
include(RunCMake)
block()
set(RunCMake_TEST_NO_SOURCE_DIR 1)
set(source ${RunCMake_SOURCE_DIR}/project)
run_cmake_command(dont-set-file ${CMAKE_COMMAND} -S ${source})
run_cmake_command(set-file-dne ${CMAKE_COMMAND} -S ${source} --project-file dne.cmake)
run_cmake_command(set-file-multi ${CMAKE_COMMAND} -S ${source} --project-file 1 --project-file 2)
run_cmake_command(set-file-none ${CMAKE_COMMAND} -S ${source} --project-file)
run_cmake_with_options(dont-set-file -S ${source})
run_cmake_with_options(set-file-dne -S ${source} --project-file dne.cmake)
run_cmake_with_options(set-file-multi -S ${source} --project-file 1 --project-file 2)
run_cmake_with_options(set-file-none -S ${source} --project-file)
set(RunCMake_TEST_NO_CLEAN 1)
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/other)
run_cmake_command(set-file ${CMAKE_COMMAND} -S ${source} --project-file other.cmake)
run_cmake_command(remembers-file ${CMAKE_COMMAND} -S ${source})
run_cmake_command(cant-change-file ${CMAKE_COMMAND} -S ${source} --project-file another.cmake)
file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
run_cmake_with_options(set-file -S ${source} --project-file other.cmake)
run_cmake_with_options(remembers-file -S ${source})
run_cmake_with_options(cant-change-file -S ${source} --project-file another.cmake)
endblock()

View File

@ -5,7 +5,8 @@
],
"configurePresets": [
{
"name": "IncludeOutsideProject"
"name": "IncludeOutsideProject",
"generator": "@RunCMake_GENERATOR@"
}
]
}

View File

@ -5,7 +5,8 @@
],
"configurePresets": [
{
"name": "IncludeUserOutsideProject"
"name": "IncludeUserOutsideProject",
"generator": "@RunCMake_GENERATOR@"
}
]
}

View File

@ -2,7 +2,8 @@
"version": 6,
"configurePresets": [
{
"name": "default"
"name": "default",
"generator": "@RunCMake_GENERATOR@"
}
],
"packagePresets": [