Merge topic 'ctest_preset_args_cli'

63b6e7d785 ctest: allow dashboard clients to specify presets via variables

Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Merge-request: !12109
This commit is contained in:
Brad King
2026-05-28 13:50:25 +00:00
committed by Kitware Robot
31 changed files with 513 additions and 26 deletions

View File

@@ -86,13 +86,20 @@ The options are:
argument will override the :preset:`buildPresets.targets` setting from
the chosen preset.
See also the :variable:`CTEST_BUILD_PRESET` and
:variable:`CTEST_PRESET` variables.
``PRESETS_FILE <file>``
.. versionadded:: 4.4
Specify a :manual:`presets <cmake-presets(7)>` file to use instead of the
default ``CMakePresets.json`` in the source directory.
A relative path is interpreted relative to the source directory.
Has no effect unless ``PRESET`` is also specified.
Has no effect unless a preset is selected via the ``PRESET`` argument
or the :variable:`CTEST_BUILD_PRESET` or :variable:`CTEST_PRESET`
variables.
See also the :variable:`CTEST_PRESETS_FILE` variable.
``RETURN_VALUE <result-var>``
Store the return value of the native build tool in the given variable.

View File

@@ -49,13 +49,20 @@ The options are:
This option is ignored when :variable:`CTEST_CONFIGURE_COMMAND`
is used.
See also the :variable:`CTEST_CONFIGURE_PRESET` and
:variable:`CTEST_PRESET` variables.
``PRESETS_FILE <file>``
.. versionadded:: 4.4
Specify a :manual:`presets <cmake-presets(7)>` file to use instead of the
default ``CMakePresets.json`` in the source directory.
A relative path is interpreted relative to the source directory.
Has no effect unless ``PRESET`` is also specified.
Has no effect unless a preset is selected via the ``PRESET`` argument
or the :variable:`CTEST_CONFIGURE_PRESET` or :variable:`CTEST_PRESET`
variables.
See also the :variable:`CTEST_PRESETS_FILE` variable.
``RETURN_VALUE <result-var>``
Store in the ``<result-var>`` variable the return value of the native

View File

@@ -201,13 +201,22 @@ The options are:
the :preset:`filter.include.name <testPresets.filter.include.name>` setting
from the chosen preset.
This option also applies to the :command:`ctest_memcheck` command.
See also the :variable:`CTEST_TEST_PRESET` and
:variable:`CTEST_PRESET` variables.
``PRESETS_FILE <file>``
.. versionadded:: 4.4
Specify a :manual:`presets <cmake-presets(7)>` file to use instead of the
default ``CMakePresets.json`` in the source directory.
A relative path is interpreted relative to the source directory.
Has no effect unless ``PRESET`` is also specified.
Has no effect unless a preset is selected via the ``PRESET`` argument
or the :variable:`CTEST_TEST_PRESET` or :variable:`CTEST_PRESET`
variables.
This option also applies to the :command:`ctest_memcheck` command.
See also the :variable:`CTEST_PRESETS_FILE` variable.
``QUIET``
.. versionadded:: 3.3

View File

@@ -739,12 +739,14 @@ Variables for CTest
/variable/CTEST_BINARY_DIRECTORY
/variable/CTEST_BUILD_COMMAND
/variable/CTEST_BUILD_NAME
/variable/CTEST_BUILD_PRESET
/variable/CTEST_BZR_COMMAND
/variable/CTEST_BZR_UPDATE_OPTIONS
/variable/CTEST_CHANGE_ID
/variable/CTEST_CHECKOUT_COMMAND
/variable/CTEST_CONFIGURATION_TYPE
/variable/CTEST_CONFIGURE_COMMAND
/variable/CTEST_CONFIGURE_PRESET
/variable/CTEST_COVERAGE_COMMAND
/variable/CTEST_COVERAGE_EXTRA_FLAGS
/variable/CTEST_CUSTOM_COVERAGE_EXCLUDE
@@ -793,6 +795,8 @@ Variables for CTest
/variable/CTEST_P4_COMMAND
/variable/CTEST_P4_OPTIONS
/variable/CTEST_P4_UPDATE_OPTIONS
/variable/CTEST_PRESET
/variable/CTEST_PRESETS_FILE
/variable/CTEST_RESOURCE_SPEC_FILE
/variable/CTEST_RUN_CURRENT_SCRIPT
/variable/CTEST_SCRIPT_DIRECTORY
@@ -804,6 +808,7 @@ Variables for CTest
/variable/CTEST_SVN_OPTIONS
/variable/CTEST_SVN_UPDATE_OPTIONS
/variable/CTEST_TEST_LOAD
/variable/CTEST_TEST_PRESET
/variable/CTEST_TEST_TIMEOUT
/variable/CTEST_TEST_COVERAGE_TOOL
/variable/CTEST_TLS_VERIFY

View File

@@ -1,7 +1,14 @@
ctest-script-preset-arg
------------------------
* The :command:`ctest_configure`, :command:`ctest_build`,
* The :command:`ctest_configure`, :command:`ctest_build`,
:command:`ctest_test`, and :command:`ctest_memcheck` commands gained
``PRESET`` and ``PRESETS_FILE`` arguments to support using
:manual:`presets <cmake-presets(7)>` for their :ref:`Dashboard Client` steps.
* The :variable:`CTEST_CONFIGURE_PRESET`, :variable:`CTEST_BUILD_PRESET`,
:variable:`CTEST_TEST_PRESET`, :variable:`CTEST_PRESET`, and
:variable:`CTEST_PRESETS_FILE` variables may be used to specify preset
arguments to the above commands in a :ref:`Dashboard Client` script or
on the :program:`ctest` command line via the
:ref:`-D <ctest-option-D-var>` option.

View File

@@ -0,0 +1,10 @@
CTEST_BUILD_PRESET
------------------
.. versionadded:: 4.4
Specify the ``PRESET`` option for the :command:`ctest_build` command
in a :manual:`ctest(1)` :ref:`Dashboard Client` script,
or on the :program:`ctest` command line via the :ref:`-D <ctest-option-D-var>` option.
See also :variable:`CTEST_PRESET` and :variable:`CTEST_PRESETS_FILE`.

View File

@@ -0,0 +1,10 @@
CTEST_CONFIGURE_PRESET
----------------------
.. versionadded:: 4.4
Specify the ``PRESET`` option for the :command:`ctest_configure` command
in a :manual:`ctest(1)` :ref:`Dashboard Client` script,
or on the :program:`ctest` command line via the :ref:`-D <ctest-option-D-var>` option.
See also :variable:`CTEST_PRESET` and :variable:`CTEST_PRESETS_FILE`.

View File

@@ -0,0 +1,22 @@
CTEST_PRESET
------------
.. versionadded:: 4.4
Specify a preset name to use for all relevant :manual:`ctest(1)`
:ref:`Dashboard Client` steps in a dashboard script,
or on the :program:`ctest` command line via the :ref:`-D <ctest-option-D-var>` option.
This variable sets the ``PRESET`` option for :command:`ctest_configure`,
:command:`ctest_build`, :command:`ctest_test`, and :command:`ctest_memcheck`
when those commands are not given an explicit ``PRESET`` argument and the
corresponding command-specific variable
(:variable:`CTEST_CONFIGURE_PRESET`, :variable:`CTEST_BUILD_PRESET`, or
:variable:`CTEST_TEST_PRESET`) is also unset.
For :command:`ctest_configure`, an error is raised if no configure preset
with this name exists. For :command:`ctest_build`, :command:`ctest_test`,
and :command:`ctest_memcheck`, a warning is emitted and the variable is
ignored if no preset of the matching type exists with this name.
See also :variable:`CTEST_PRESETS_FILE`.

View File

@@ -0,0 +1,16 @@
CTEST_PRESETS_FILE
------------------
.. versionadded:: 4.4
Specify the ``PRESETS_FILE`` option for all relevant :manual:`ctest(1)`
:ref:`Dashboard Client` step commands in a dashboard script,
or on the :program:`ctest` command line via the :ref:`-D <ctest-option-D-var>` option.
This variable sets the ``PRESETS_FILE`` option for
:command:`ctest_configure`, :command:`ctest_build`, :command:`ctest_test`,
and :command:`ctest_memcheck` when those commands are not given an explicit
``PRESETS_FILE`` argument.
See also :variable:`CTEST_PRESET`, :variable:`CTEST_CONFIGURE_PRESET`,
:variable:`CTEST_BUILD_PRESET`, and :variable:`CTEST_TEST_PRESET`.

View File

@@ -0,0 +1,11 @@
CTEST_TEST_PRESET
-----------------
.. versionadded:: 4.4
Specify the ``PRESET`` option for the :command:`ctest_test` and
:command:`ctest_memcheck` commands in a :manual:`ctest(1)`
:ref:`Dashboard Client` script,
or on the :program:`ctest` command line via the :ref:`-D <ctest-option-D-var>` option.
See also :variable:`CTEST_PRESET` and :variable:`CTEST_PRESETS_FILE`.

View File

@@ -73,18 +73,54 @@ std::unique_ptr<cmCTestGenericHandler> cmCTestBuildCommand::InitializeHandler(
? args.Target
: mf.GetSafeDefinition("CTEST_BUILD_TARGET");
// Preset name is set according to the following priority order:
// 1) The PRESET option to ctest_build()
// 2) CTEST_BUILD_PRESET script variable
// 3) CTEST_PRESET script variable (a warning is emitted if no build preset
// exists with this name)
std::string const sourceDirectory =
mf.GetSafeDefinition("CTEST_SOURCE_DIRECTORY");
// Presets file is set according to the following priority order:
// 1) The PRESETS_FILE option to ctest_build()
// 2) CTEST_PRESETS_FILE script variable
std::string const rawPresetsFile = !args.PresetsFile.empty()
? args.PresetsFile
: mf.GetSafeDefinition("CTEST_PRESETS_FILE");
std::string const presetsFile = rawPresetsFile.empty()
? ""
: cmSystemTools::CollapseFullPath(rawPresetsFile, sourceDirectory);
std::string effectivePreset = !args.Preset.empty() ? args.Preset
: cmNonempty(mf.GetDefinition("CTEST_BUILD_PRESET"))
? *mf.GetDefinition("CTEST_BUILD_PRESET")
: "";
if (effectivePreset.empty()) {
cmValue v = mf.GetDefinition("CTEST_PRESET");
if (cmNonempty(v)) {
std::string presetError;
auto presetCheck =
BuildPresetExists(*v, sourceDirectory, presetsFile, presetError);
if (presetCheck == PresetCheckResult::ReadError) {
status.SetError(cmStrCat('\n', presetError));
return nullptr;
}
if (presetCheck == PresetCheckResult::Found) {
effectivePreset = *v;
} else {
cmCTestLog(this->CTest, WARNING,
"No build preset named \""
<< *v << "\" found, ignoring CTEST_PRESET." << std::endl);
}
}
}
cmValue ctestBuildCommand = mf.GetDefinition("CTEST_BUILD_COMMAND");
if (cmNonempty(ctestBuildCommand)) {
this->CTest->SetCTestConfiguration("MakeCommand", *ctestBuildCommand,
args.Quiet);
} else if (!args.Preset.empty()) {
std::string const sourceDirectory =
mf.GetSafeDefinition("CTEST_SOURCE_DIRECTORY");
std::string const presetsFile = args.PresetsFile.empty()
? ""
: cmSystemTools::CollapseFullPath(args.PresetsFile, sourceDirectory);
} else if (!effectivePreset.empty()) {
cmCMakePresetsGraph presetsGraph;
if (!presetsGraph.ReadProjectPresets(sourceDirectory, presetsFile)) {
status.SetError(cmStrCat("\n Could not read presets from \"",
@@ -94,7 +130,7 @@ std::unique_ptr<cmCTestGenericHandler> cmCTestBuildCommand::InitializeHandler(
}
auto resolveResult =
presetsGraph.ResolvePreset(args.Preset, presetsGraph.BuildPresets);
presetsGraph.ResolvePreset(effectivePreset, presetsGraph.BuildPresets);
auto resolveError = cmCMakePresetsGraph::FormatPresetError<BuildPreset>(
resolveResult.StatusCode, resolveResult.ErrorPresetName,
sourceDirectory);
@@ -106,7 +142,7 @@ std::unique_ptr<cmCTestGenericHandler> cmCTestBuildCommand::InitializeHandler(
std::string buildCommand =
cmStrCat('"', cmSystemTools::GetCMakeCommand(), '"');
buildCommand += " --build . --preset \"";
buildCommand += args.Preset;
buildCommand += effectivePreset;
buildCommand += "\"";
if (!presetsFile.empty()) {

View File

@@ -191,14 +191,30 @@ bool cmCTestConfigureCommand::ExecuteConfigure(ConfigureArguments const& args,
return false;
}
std::string const presetsFile = args.PresetsFile.empty()
// Preset name is set according to the following priority order:
// 1) The PRESET option to ctest_configure()
// 2) CTEST_CONFIGURE_PRESET script variable
// 3) CTEST_PRESET script variable (error if no such configure preset exists)
std::string const presetName = !args.Preset.empty() ? args.Preset
: cmNonempty(mf.GetDefinition("CTEST_CONFIGURE_PRESET"))
? *mf.GetDefinition("CTEST_CONFIGURE_PRESET")
: mf.GetSafeDefinition("CTEST_PRESET");
// Presets file is set according to the following priority order:
// 1) The PRESETS_FILE option to ctest_configure()
// 2) CTEST_PRESETS_FILE script variable
std::string const rawPresetsFile = !args.PresetsFile.empty()
? args.PresetsFile
: mf.GetSafeDefinition("CTEST_PRESETS_FILE");
std::string const presetsFile = rawPresetsFile.empty()
? ""
: cmSystemTools::CollapseFullPath(args.PresetsFile, sourceDirectory);
: cmSystemTools::CollapseFullPath(rawPresetsFile, sourceDirectory);
std::string configureCommand = mf.GetDefinition("CTEST_CONFIGURE_COMMAND");
if (configureCommand.empty() &&
!ConstructConfigureCommand(status, mf, sourceDirectory, buildDirectory,
args.Options, args.Preset, presetsFile,
args.Options, presetName, presetsFile,
configureCommand)) {
return false;
}

View File

@@ -8,9 +8,11 @@
#include <cm/string_view>
#include "cmCMakePresetsGraph.h"
#include "cmCTest.h"
#include "cmCTestGenericHandler.h"
#include "cmExecutionStatus.h"
#include "cmJSONState.h"
#include "cmMakefile.h"
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
@@ -216,3 +218,55 @@ void cmCTestHandlerCommand::ProcessAdditionalValues(cmCTestGenericHandler*,
cmExecutionStatus&) const
{
}
namespace {
enum class PresetType
{
Build,
Test,
};
cmCTestHandlerCommand::PresetCheckResult PresetExistsInGraph(
cmCMakePresetsGraph& graph, std::string const& name,
std::string const& sourceDir, std::string const& presetsFile,
PresetType presetType, std::string& errorMessage)
{
using Result = cmCTestHandlerCommand::PresetCheckResult;
if (!graph.ReadProjectPresets(sourceDir, presetsFile)) {
errorMessage = cmStrCat("Could not read presets from \"", sourceDir,
"\":\n ", graph.parseState.GetErrorMessage());
return Result::ReadError;
}
using Status = cmCMakePresetsGraph::PresetResolveStatus;
if (presetType == PresetType::Build) {
auto result = graph.ResolvePreset(name, graph.BuildPresets);
return result.StatusCode == Status::Success ? Result::Found
: Result::NotFound;
}
auto result = graph.ResolvePreset(name, graph.TestPresets);
return result.StatusCode == Status::Success ? Result::Found
: Result::NotFound;
}
}
cmCTestHandlerCommand::PresetCheckResult
cmCTestHandlerCommand::BuildPresetExists(std::string const& name,
std::string const& sourceDir,
std::string const& presetsFile,
std::string& errorMessage)
{
cmCMakePresetsGraph graph;
return PresetExistsInGraph(graph, name, sourceDir, presetsFile,
PresetType::Build, errorMessage);
}
cmCTestHandlerCommand::PresetCheckResult
cmCTestHandlerCommand::TestPresetExists(std::string const& name,
std::string const& sourceDir,
std::string const& presetsFile,
std::string& errorMessage)
{
cmCMakePresetsGraph graph;
return PresetExistsInGraph(graph, name, sourceDir, presetsFile,
PresetType::Test, errorMessage);
}

View File

@@ -24,6 +24,13 @@ class cmCTestHandlerCommand : public cmCTestCommand
public:
using cmCTestCommand::cmCTestCommand;
enum class PresetCheckResult
{
Found,
NotFound,
ReadError,
};
protected:
struct BasicArguments : ArgumentParser::ParseResult
{
@@ -78,6 +85,15 @@ protected:
bool ExecuteHandlerCommand(HandlerArguments& args,
cmExecutionStatus& status) const;
static PresetCheckResult BuildPresetExists(std::string const& name,
std::string const& sourceDir,
std::string const& presetsFile,
std::string& errorMessage);
static PresetCheckResult TestPresetExists(std::string const& name,
std::string const& sourceDir,
std::string const& presetsFile,
std::string& errorMessage);
private:
bool InvokeImpl(BasicArguments& args,
std::vector<std::string> const& unparsed,

View File

@@ -34,16 +34,52 @@ std::unique_ptr<cmCTestGenericHandler> cmCTestTestCommand::InitializeHandler(
cmMakefile& mf = status.GetMakefile();
auto& args = static_cast<TestArguments&>(arguments);
std::string const sourceDirectory =
mf.GetSafeDefinition("CTEST_SOURCE_DIRECTORY");
// Presets file is set according to the following priority order:
// 1) The PRESETS_FILE option to ctest_test()
// 2) CTEST_PRESETS_FILE script variable
std::string const rawPresetsFile = !args.PresetsFile.empty()
? args.PresetsFile
: mf.GetSafeDefinition("CTEST_PRESETS_FILE");
std::string const presetsFile = rawPresetsFile.empty()
? ""
: cmSystemTools::CollapseFullPath(rawPresetsFile, sourceDirectory);
// Preset name is set according to the following priority order:
// 1) The PRESET option to ctest_test()
// 2) CTEST_TEST_PRESET script variable
// 3) CTEST_PRESET script variable (a warning is emitted if no test preset
// exists with this name)
std::string effectivePreset = !args.Preset.empty() ? args.Preset
: cmNonempty(mf.GetDefinition("CTEST_TEST_PRESET"))
? *mf.GetDefinition("CTEST_TEST_PRESET")
: "";
if (effectivePreset.empty()) {
cmValue v = mf.GetDefinition("CTEST_PRESET");
if (cmNonempty(v)) {
std::string presetError;
auto presetCheck =
TestPresetExists(*v, sourceDirectory, presetsFile, presetError);
if (presetCheck == PresetCheckResult::ReadError) {
status.SetError(cmStrCat('\n', presetError));
return nullptr;
}
if (presetCheck == PresetCheckResult::Found) {
effectivePreset = *v;
} else {
cmCTestLog(this->CTest, WARNING,
"No test preset named \""
<< *v << "\" found, ignoring CTEST_PRESET." << std::endl);
}
}
}
std::unique_ptr<cmCMakePresetsGraph> presetsGraph;
TestPreset const* expandedPreset = nullptr;
if (!args.Preset.empty()) {
std::string const sourceDirectory =
mf.GetSafeDefinition("CTEST_SOURCE_DIRECTORY");
std::string const presetsFile = args.PresetsFile.empty()
? ""
: cmSystemTools::CollapseFullPath(args.PresetsFile, sourceDirectory);
if (!effectivePreset.empty()) {
presetsGraph = cm::make_unique<cmCMakePresetsGraph>();
if (!presetsGraph->ReadProjectPresets(sourceDirectory, presetsFile)) {
status.SetError(cmStrCat("\n Could not read presets from \"",
@@ -53,7 +89,7 @@ std::unique_ptr<cmCTestGenericHandler> cmCTestTestCommand::InitializeHandler(
}
auto resolveResult =
presetsGraph->ResolvePreset(args.Preset, presetsGraph->TestPresets);
presetsGraph->ResolvePreset(effectivePreset, presetsGraph->TestPresets);
auto resolveError = cmCMakePresetsGraph::FormatPresetError<TestPreset>(
resolveResult.StatusCode, resolveResult.ErrorPresetName,
sourceDirectory);

View File

@@ -0,0 +1,14 @@
file(GLOB build_xml_file "${RunCMake_TEST_BINARY_DIR}/Testing/*/Build.xml")
if(build_xml_file)
file(READ "${build_xml_file}" build_xml)
if(NOT build_xml MATCHES "--preset.*my-build-preset")
set(RunCMake_TEST_FAILED
"Build.xml does not contain the expected --preset argument")
endif()
if(NOT build_xml MATCHES "--presets-file")
set(RunCMake_TEST_FAILED
"Build.xml does not contain the expected --presets-file argument")
endif()
else()
set(RunCMake_TEST_FAILED "Build.xml not found")
endif()

View File

@@ -0,0 +1,10 @@
file(GLOB build_xml_file "${RunCMake_TEST_BINARY_DIR}/Testing/*/Build.xml")
if(build_xml_file)
file(READ "${build_xml_file}" build_xml)
if(NOT build_xml MATCHES "--preset.*my-build-preset")
set(RunCMake_TEST_FAILED
"Build.xml does not contain the expected --preset argument")
endif()
else()
set(RunCMake_TEST_FAILED "Build.xml not found")
endif()

View File

@@ -0,0 +1,10 @@
file(GLOB build_xml_file "${RunCMake_TEST_BINARY_DIR}/Testing/*/Build.xml")
if(build_xml_file)
file(READ "${build_xml_file}" build_xml)
if(NOT build_xml MATCHES "--preset.*my-build-preset")
set(RunCMake_TEST_FAILED
"Build.xml does not contain the expected --preset argument")
endif()
else()
set(RunCMake_TEST_FAILED "Build.xml not found")
endif()

View File

@@ -10,6 +10,10 @@
"name": "my-configure-preset",
"generator": "@RunCMake_GENERATOR@",
"binaryDir": "${sourceDir}/../BuildPreset-build"
},
{
"name": "my-build-preset",
"inherits": "my-configure-preset"
}
],
"buildPresets": [

View File

@@ -80,6 +80,26 @@ configure_file(
run_ctest_build(BuildPreset PRESET my-build-preset)
unset(RunCMake_TEST_SOURCE_DIR)
set(RunCMake_TEST_SOURCE_DIR "${RunCMake_BINARY_DIR}/BuildPresetVar")
configure_file(
"${RunCMake_SOURCE_DIR}/CMakePresets.json.in"
"${RunCMake_TEST_SOURCE_DIR}/CMakePresets.json"
@ONLY)
set(CASE_TEST_PREFIX_CODE [[set(CTEST_BUILD_PRESET "my-build-preset")]])
run_ctest(BuildPresetVar)
unset(CASE_TEST_PREFIX_CODE)
unset(RunCMake_TEST_SOURCE_DIR)
set(RunCMake_TEST_SOURCE_DIR "${RunCMake_BINARY_DIR}/BuildPresetGenericVar")
configure_file(
"${RunCMake_SOURCE_DIR}/CMakePresets.json.in"
"${RunCMake_TEST_SOURCE_DIR}/CMakePresets.json"
@ONLY)
set(CASE_TEST_PREFIX_CODE [[set(CTEST_PRESET "my-build-preset")]])
run_ctest(BuildPresetGenericVar)
unset(CASE_TEST_PREFIX_CODE)
unset(RunCMake_TEST_SOURCE_DIR)
set(RunCMake_TEST_SOURCE_DIR "${RunCMake_BINARY_DIR}/BuildPresetFromFile")
set(custom_presets_file
"${RunCMake_BINARY_DIR}/BuildPresetFromFile/custom-presets.json")
@@ -93,6 +113,21 @@ run_ctest_build(BuildPresetFromFile
unset(RunCMake_TEST_SOURCE_DIR)
unset(custom_presets_file)
set(RunCMake_TEST_SOURCE_DIR "${RunCMake_BINARY_DIR}/BuildPresetFromFileVar")
set(custom_presets_file
"${RunCMake_BINARY_DIR}/BuildPresetFromFileVar/custom-presets.json")
configure_file(
"${RunCMake_SOURCE_DIR}/CMakePresets.json.in"
"${custom_presets_file}"
@ONLY)
set(CASE_TEST_PREFIX_CODE
"set(CTEST_BUILD_PRESET \"my-build-preset\")
set(CTEST_PRESETS_FILE \"${custom_presets_file}\")")
run_ctest(BuildPresetFromFileVar)
unset(CASE_TEST_PREFIX_CODE)
unset(RunCMake_TEST_SOURCE_DIR)
unset(custom_presets_file)
run_ctest_build(BuildPresetBadFile
PRESET my-build-preset
PRESETS_FILE /nonexistent/path/presets.json)

View File

@@ -0,0 +1,29 @@
if(IS_DIRECTORY "${RunCMake_TEST_SOURCE_DIR}/build")
set(RunCMake_TEST_FAILED
"CTEST_BINARY_DIRECTORY did not override buildDir from preset")
endif()
file(GLOB configure_xml_file "${RunCMake_TEST_BINARY_DIR}/Testing/*/Configure.xml")
if(configure_xml_file)
file(READ "${configure_xml_file}" configure_xml)
if(NOT configure_xml MATCHES "\"--preset\" \"my-preset\"")
set(RunCMake_TEST_FAILED
"Configure.xml does not contain the expected --preset argument")
endif()
if(NOT configure_xml MATCHES "\"--presets-file\"")
set(RunCMake_TEST_FAILED
"Configure.xml does not contain the expected --presets-file argument")
endif()
else()
set(RunCMake_TEST_FAILED "Configure.xml not found")
endif()
set(cmakecache_file "${RunCMake_TEST_BINARY_DIR}/CMakeCache.txt")
if(EXISTS "${cmakecache_file}")
file(READ "${cmakecache_file}" cmakecache_txt)
if(NOT cmakecache_txt MATCHES "MY_CUSTOM_VAR:STRING=this-gets-set")
set(RunCMake_TEST_FAILED "CMakeCache.txt does not contain MY_CUSTOM_VAR")
endif()
else()
set(RunCMake_TEST_FAILED "CMakeCache.txt not found")
endif()

View File

@@ -0,0 +1,25 @@
if(IS_DIRECTORY "${RunCMake_TEST_SOURCE_DIR}/build")
set(RunCMake_TEST_FAILED
"CTEST_BINARY_DIRECTORY did not override buildDir from preset")
endif()
file(GLOB configure_xml_file "${RunCMake_TEST_BINARY_DIR}/Testing/*/Configure.xml")
if(configure_xml_file)
file(READ "${configure_xml_file}" configure_xml)
if(NOT configure_xml MATCHES "\"--preset\" \"my-preset\"")
set(RunCMake_TEST_FAILED
"Configure.xml does not contain the expected --preset argument")
endif()
else()
set(RunCMake_TEST_FAILED "Configure.xml not found")
endif()
set(cmakecache_file "${RunCMake_TEST_BINARY_DIR}/CMakeCache.txt")
if(EXISTS "${cmakecache_file}")
file(READ "${cmakecache_file}" cmakecache_txt)
if(NOT cmakecache_txt MATCHES "MY_CUSTOM_VAR:STRING=this-gets-set")
set(RunCMake_TEST_FAILED "CMakeCache.txt does not contain MY_CUSTOM_VAR")
endif()
else()
set(RunCMake_TEST_FAILED "CMakeCache.txt not found")
endif()

View File

@@ -0,0 +1,25 @@
if(IS_DIRECTORY "${RunCMake_TEST_SOURCE_DIR}/build")
set(RunCMake_TEST_FAILED
"CTEST_BINARY_DIRECTORY did not override buildDir from preset")
endif()
file(GLOB configure_xml_file "${RunCMake_TEST_BINARY_DIR}/Testing/*/Configure.xml")
if(configure_xml_file)
file(READ "${configure_xml_file}" configure_xml)
if(NOT configure_xml MATCHES "\"--preset\" \"my-preset\"")
set(RunCMake_TEST_FAILED
"Configure.xml does not contain the expected --preset argument")
endif()
else()
set(RunCMake_TEST_FAILED "Configure.xml not found")
endif()
set(cmakecache_file "${RunCMake_TEST_BINARY_DIR}/CMakeCache.txt")
if(EXISTS "${cmakecache_file}")
file(READ "${cmakecache_file}" cmakecache_txt)
if(NOT cmakecache_txt MATCHES "MY_CUSTOM_VAR:STRING=this-gets-set")
set(RunCMake_TEST_FAILED "CMakeCache.txt does not contain MY_CUSTOM_VAR")
endif()
else()
set(RunCMake_TEST_FAILED "CMakeCache.txt not found")
endif()

View File

@@ -16,6 +16,24 @@ configure_file(
@ONLY)
run_ctest_configure(ConfigurePreset PRESET my-preset)
set(RunCMake_TEST_SOURCE_DIR "${RunCMake_BINARY_DIR}/ConfigurePresetVar")
configure_file(
"${RunCMake_SOURCE_DIR}/CMakePresets.json.in"
"${RunCMake_TEST_SOURCE_DIR}/CMakePresets.json"
@ONLY)
set(CASE_TEST_PREFIX_CODE [[set(CTEST_CONFIGURE_PRESET "my-preset")]])
run_ctest(ConfigurePresetVar)
unset(CASE_TEST_PREFIX_CODE)
set(RunCMake_TEST_SOURCE_DIR "${RunCMake_BINARY_DIR}/ConfigurePresetGenericVar")
configure_file(
"${RunCMake_SOURCE_DIR}/CMakePresets.json.in"
"${RunCMake_TEST_SOURCE_DIR}/CMakePresets.json"
@ONLY)
set(CASE_TEST_PREFIX_CODE [[set(CTEST_PRESET "my-preset")]])
run_ctest(ConfigurePresetGenericVar)
unset(CASE_TEST_PREFIX_CODE)
set(RunCMake_TEST_SOURCE_DIR "${RunCMake_BINARY_DIR}/ConfigurePresetFromFile")
set(custom_presets_file "${RunCMake_BINARY_DIR}/ConfigurePresetFromFile/custom-presets.json")
configure_file(
@@ -24,3 +42,17 @@ configure_file(
@ONLY)
run_ctest_configure(ConfigurePresetFromFile PRESET my-preset PRESETS_FILE "${custom_presets_file}")
unset(custom_presets_file)
set(RunCMake_TEST_SOURCE_DIR "${RunCMake_BINARY_DIR}/ConfigurePresetFromFileVar")
set(custom_presets_file "${RunCMake_BINARY_DIR}/ConfigurePresetFromFileVar/custom-presets.json")
configure_file(
"${RunCMake_SOURCE_DIR}/CMakePresets.json.in"
"${custom_presets_file}"
@ONLY)
set(CASE_TEST_PREFIX_CODE
"set(CTEST_CONFIGURE_PRESET \"my-preset\")
set(CTEST_PRESETS_FILE \"${custom_presets_file}\")")
run_ctest(ConfigurePresetFromFileVar)
unset(CASE_TEST_PREFIX_CODE)
unset(custom_presets_file)
unset(RunCMake_TEST_SOURCE_DIR)

View File

@@ -1,4 +1,5 @@
cmake_minimum_required(VERSION 3.10)
@CASE_TEST_PREFIX_CODE@
set(CTEST_SITE "test-site")
set(CTEST_BUILD_NAME "test-build-name")

View File

@@ -10,6 +10,10 @@
"name": "my-configure-preset",
"generator": "@RunCMake_GENERATOR@",
"binaryDir": "${sourceDir}/build"
},
{
"name": "my-include-preset",
"inherits": "my-configure-preset"
}
],
"testPresets": [

View File

@@ -24,6 +24,8 @@ endforeach()
TestPresetExclude
TestPresetInclude
TestPresetOverride
TestPresetVar
TestPresetGenericVar
)
configure_file(
"${RunCMake_SOURCE_DIR}/CMakePresets.json.in"
@@ -35,6 +37,14 @@ endforeach()
run_ctest_test(TestPresetInclude PRESET my-include-preset)
run_ctest_test(TestPresetOverride PRESET my-include-preset INCLUDE test2)
set(CASE_TEST_PREFIX_CODE [[set(CTEST_TEST_PRESET "my-include-preset")]])
run_ctest(TestPresetVar)
unset(CASE_TEST_PREFIX_CODE)
set(CASE_TEST_PREFIX_CODE [[set(CTEST_PRESET "my-include-preset")]])
run_ctest(TestPresetGenericVar)
unset(CASE_TEST_PREFIX_CODE)
set(custom_presets_file
"${RunCMake_BINARY_DIR}/TestPresetFileInclude/custom-presets.json")
configure_file(
@@ -47,6 +57,19 @@ endforeach()
unset(CASE_CTEST_TEST_RAW_ARGS)
unset(custom_presets_file)
set(custom_presets_file
"${RunCMake_BINARY_DIR}/TestPresetFromFileVar/custom-presets.json")
configure_file(
"${RunCMake_SOURCE_DIR}/CMakePresets.json.in"
"${custom_presets_file}"
@ONLY)
set(CASE_TEST_PREFIX_CODE
"set(CTEST_TEST_PRESET \"my-include-preset\")
set(CTEST_PRESETS_FILE \"${custom_presets_file}\")")
run_ctest(TestPresetFromFileVar)
unset(CASE_TEST_PREFIX_CODE)
unset(custom_presets_file)
set(CASE_CTEST_TEST_RAW_ARGS
"PRESET my-include-preset PRESETS_FILE /nonexistent/path/presets.json")
run_ctest(TestPresetBadFile)

View File

@@ -0,0 +1,4 @@
Start [0-9]+: test1
1/1 Test #[0-9]+: test1 \.+ Passed +[0-9\.]+ sec
+
100% tests passed out of 1

View File

@@ -0,0 +1 @@
No build preset named "my-include-preset" found, ignoring CTEST_PRESET\.

View File

@@ -0,0 +1,4 @@
Start [0-9]+: test1
1/1 Test #[0-9]+: test1 \.+ Passed +[0-9\.]+ sec
+
100% tests passed out of 1

View File

@@ -0,0 +1,4 @@
Start [0-9]+: test1
1/1 Test #[0-9]+: test1 \.+ Passed +[0-9\.]+ sec
+
100% tests passed out of 1