/src/CMake/Source/cmCMakePresetsGraphReadJSONTestPresets.cxx
Line | Count | Source |
1 | | /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying |
2 | | file LICENSE.rst or https://cmake.org/licensing for details. */ |
3 | | #include <cstddef> |
4 | | #include <functional> |
5 | | #include <map> |
6 | | #include <memory> |
7 | | #include <string> |
8 | | #include <vector> |
9 | | |
10 | | #include <cm/optional> |
11 | | #include <cmext/string_view> |
12 | | |
13 | | #include <cm3p/json/value.h> |
14 | | |
15 | | #include "cmCMakePresetsErrors.h" |
16 | | #include "cmCMakePresetsGraph.h" |
17 | | #include "cmCMakePresetsGraphInternal.h" |
18 | | #include "cmJSONHelpers.h" |
19 | | |
20 | | #include "CTest/cmCTestTypes.h" |
21 | | |
22 | | class cmJSONState; |
23 | | |
24 | | namespace { |
25 | | using TestPreset = cmCMakePresetsGraph::TestPreset; |
26 | | using JSONHelperBuilder = cmJSONHelperBuilder; |
27 | | |
28 | | bool TestPresetOutputVerbosityHelper( |
29 | | TestPreset::OutputOptions::VerbosityEnum& out, Json::Value const* value, |
30 | | cmJSONState* state) |
31 | 0 | { |
32 | 0 | if (!value) { |
33 | 0 | out = TestPreset::OutputOptions::VerbosityEnum::Default; |
34 | 0 | return true; |
35 | 0 | } |
36 | | |
37 | 0 | if (!value->isString()) { |
38 | 0 | cmCMakePresetsErrors::INVALID_PRESET(value, state); |
39 | 0 | return false; |
40 | 0 | } |
41 | | |
42 | 0 | if (value->asString() == "default") { |
43 | 0 | out = TestPreset::OutputOptions::VerbosityEnum::Default; |
44 | 0 | return true; |
45 | 0 | } |
46 | | |
47 | 0 | if (value->asString() == "verbose") { |
48 | 0 | out = TestPreset::OutputOptions::VerbosityEnum::Verbose; |
49 | 0 | return true; |
50 | 0 | } |
51 | | |
52 | 0 | if (value->asString() == "extra") { |
53 | 0 | out = TestPreset::OutputOptions::VerbosityEnum::Extra; |
54 | 0 | return true; |
55 | 0 | } |
56 | | |
57 | 0 | cmCMakePresetsErrors::INVALID_PRESET(value, state); |
58 | 0 | return false; |
59 | 0 | } |
60 | | |
61 | | auto const TestPresetOptionalOutputVerbosityHelper = |
62 | | JSONHelperBuilder::Optional<TestPreset::OutputOptions::VerbosityEnum>( |
63 | | TestPresetOutputVerbosityHelper); |
64 | | |
65 | | bool TestPresetOutputTruncationHelper( |
66 | | cm::optional<cmCTestTypes::TruncationMode>& out, Json::Value const* value, |
67 | | cmJSONState* state) |
68 | 0 | { |
69 | 0 | if (!value) { |
70 | 0 | out = cm::nullopt; |
71 | 0 | return true; |
72 | 0 | } |
73 | | |
74 | 0 | if (!value->isString()) { |
75 | 0 | cmCMakePresetsErrors::INVALID_PRESET(value, state); |
76 | 0 | return false; |
77 | 0 | } |
78 | | |
79 | 0 | if (value->asString() == "tail") { |
80 | 0 | out = cmCTestTypes::TruncationMode::Tail; |
81 | 0 | return true; |
82 | 0 | } |
83 | | |
84 | 0 | if (value->asString() == "middle") { |
85 | 0 | out = cmCTestTypes::TruncationMode::Middle; |
86 | 0 | return true; |
87 | 0 | } |
88 | | |
89 | 0 | if (value->asString() == "head") { |
90 | 0 | out = cmCTestTypes::TruncationMode::Head; |
91 | 0 | return true; |
92 | 0 | } |
93 | | |
94 | 0 | cmCMakePresetsErrors::INVALID_PRESET(value, state); |
95 | 0 | return false; |
96 | 0 | } |
97 | | |
98 | | auto const TestPresetOptionalOutputHelper = |
99 | | JSONHelperBuilder::Optional<TestPreset::OutputOptions>( |
100 | | JSONHelperBuilder::Object<TestPreset::OutputOptions>( |
101 | | JsonErrors::INVALID_OBJECT, false) |
102 | | .Bind("shortProgress"_s, &TestPreset::OutputOptions::ShortProgress, |
103 | | cmCMakePresetsGraphInternal::PresetOptionalBoolHelper, false) |
104 | | .Bind("verbosity"_s, &TestPreset::OutputOptions::Verbosity, |
105 | | TestPresetOptionalOutputVerbosityHelper, false) |
106 | | .Bind("debug"_s, &TestPreset::OutputOptions::Debug, |
107 | | cmCMakePresetsGraphInternal::PresetOptionalBoolHelper, false) |
108 | | .Bind("outputOnFailure"_s, &TestPreset::OutputOptions::OutputOnFailure, |
109 | | cmCMakePresetsGraphInternal::PresetOptionalBoolHelper, false) |
110 | | .Bind("quiet"_s, &TestPreset::OutputOptions::Quiet, |
111 | | cmCMakePresetsGraphInternal::PresetOptionalBoolHelper, false) |
112 | | .Bind("outputLogFile"_s, &TestPreset::OutputOptions::OutputLogFile, |
113 | | cmCMakePresetsGraphInternal::PresetStringHelper, false) |
114 | | .Bind("outputJUnitFile"_s, &TestPreset::OutputOptions::OutputJUnitFile, |
115 | | cmCMakePresetsGraphInternal::PresetStringHelper, false) |
116 | | .Bind("labelSummary"_s, &TestPreset::OutputOptions::LabelSummary, |
117 | | cmCMakePresetsGraphInternal::PresetOptionalBoolHelper, false) |
118 | | .Bind("subprojectSummary"_s, |
119 | | &TestPreset::OutputOptions::SubprojectSummary, |
120 | | cmCMakePresetsGraphInternal::PresetOptionalBoolHelper, false) |
121 | | .Bind("maxPassedTestOutputSize"_s, |
122 | | &TestPreset::OutputOptions::MaxPassedTestOutputSize, |
123 | | cmCMakePresetsGraphInternal::PresetOptionalIntHelper, false) |
124 | | .Bind("maxFailedTestOutputSize"_s, |
125 | | &TestPreset::OutputOptions::MaxFailedTestOutputSize, |
126 | | cmCMakePresetsGraphInternal::PresetOptionalIntHelper, false) |
127 | | .Bind("testOutputTruncation"_s, |
128 | | &TestPreset::OutputOptions::TestOutputTruncation, |
129 | | TestPresetOutputTruncationHelper, false) |
130 | | .Bind("maxTestNameWidth"_s, &TestPreset::OutputOptions::MaxTestNameWidth, |
131 | | cmCMakePresetsGraphInternal::PresetOptionalIntHelper, false)); |
132 | | |
133 | | auto const TestPresetOptionalFilterIncludeIndexObjectHelper = |
134 | | JSONHelperBuilder::Optional<TestPreset::IncludeOptions::IndexOptions>( |
135 | | JSONHelperBuilder::Object<TestPreset::IncludeOptions::IndexOptions>() |
136 | | .Bind("start"_s, &TestPreset::IncludeOptions::IndexOptions::Start, |
137 | | cmCMakePresetsGraphInternal::PresetOptionalIntHelper, false) |
138 | | .Bind("end"_s, &TestPreset::IncludeOptions::IndexOptions::End, |
139 | | cmCMakePresetsGraphInternal::PresetOptionalIntHelper, false) |
140 | | .Bind("stride"_s, &TestPreset::IncludeOptions::IndexOptions::Stride, |
141 | | cmCMakePresetsGraphInternal::PresetOptionalIntHelper, false) |
142 | | .Bind("specificTests"_s, |
143 | | &TestPreset::IncludeOptions::IndexOptions::SpecificTests, |
144 | | cmCMakePresetsGraphInternal::PresetVectorIntHelper, false)); |
145 | | |
146 | | bool TestPresetOptionalFilterIncludeIndexHelper( |
147 | | cm::optional<TestPreset::IncludeOptions::IndexOptions>& out, |
148 | | Json::Value const* value, cmJSONState* state) |
149 | 0 | { |
150 | 0 | if (!value) { |
151 | 0 | out = cm::nullopt; |
152 | 0 | return true; |
153 | 0 | } |
154 | | |
155 | 0 | if (value->isString()) { |
156 | 0 | out.emplace(); |
157 | 0 | out->IndexFile = value->asString(); |
158 | 0 | return true; |
159 | 0 | } |
160 | | |
161 | 0 | if (value->isObject()) { |
162 | 0 | return TestPresetOptionalFilterIncludeIndexObjectHelper(out, value, state); |
163 | 0 | } |
164 | | |
165 | 0 | return false; |
166 | 0 | } |
167 | | |
168 | | auto const TestPresetOptionalFilterIncludeHelper = |
169 | | JSONHelperBuilder::Optional<TestPreset::IncludeOptions>( |
170 | | JSONHelperBuilder::Object<TestPreset::IncludeOptions>() |
171 | | .Bind("name"_s, &TestPreset::IncludeOptions::Name, |
172 | | cmCMakePresetsGraphInternal::PresetStringHelper, false) |
173 | | .Bind("label"_s, &TestPreset::IncludeOptions::Label, |
174 | | cmCMakePresetsGraphInternal::PresetStringHelper, false) |
175 | | .Bind("index"_s, &TestPreset::IncludeOptions::Index, |
176 | | TestPresetOptionalFilterIncludeIndexHelper, false) |
177 | | .Bind("useUnion"_s, &TestPreset::IncludeOptions::UseUnion, |
178 | | cmCMakePresetsGraphInternal::PresetOptionalBoolHelper, false)); |
179 | | |
180 | | auto const TestPresetOptionalFilterExcludeFixturesHelper = |
181 | | JSONHelperBuilder::Optional<TestPreset::ExcludeOptions::FixturesOptions>( |
182 | | JSONHelperBuilder::Object<TestPreset::ExcludeOptions::FixturesOptions>() |
183 | | .Bind("any"_s, &TestPreset::ExcludeOptions::FixturesOptions::Any, |
184 | | cmCMakePresetsGraphInternal::PresetStringHelper, false) |
185 | | .Bind("setup"_s, &TestPreset::ExcludeOptions::FixturesOptions::Setup, |
186 | | cmCMakePresetsGraphInternal::PresetStringHelper, false) |
187 | | .Bind("cleanup"_s, &TestPreset::ExcludeOptions::FixturesOptions::Cleanup, |
188 | | cmCMakePresetsGraphInternal::PresetStringHelper, false)); |
189 | | |
190 | | auto const TestPresetOptionalFilterExcludeHelper = |
191 | | JSONHelperBuilder::Optional<TestPreset::ExcludeOptions>( |
192 | | JSONHelperBuilder::Object<TestPreset::ExcludeOptions>() |
193 | | .Bind("name"_s, &TestPreset::ExcludeOptions::Name, |
194 | | cmCMakePresetsGraphInternal::PresetStringHelper, false) |
195 | | .Bind("label"_s, &TestPreset::ExcludeOptions::Label, |
196 | | cmCMakePresetsGraphInternal::PresetStringHelper, false) |
197 | | .Bind("fixtures"_s, &TestPreset::ExcludeOptions::Fixtures, |
198 | | TestPresetOptionalFilterExcludeFixturesHelper, false)); |
199 | | |
200 | | bool TestPresetExecutionShowOnlyHelper( |
201 | | TestPreset::ExecutionOptions::ShowOnlyEnum& out, Json::Value const* value, |
202 | | cmJSONState* state) |
203 | 0 | { |
204 | 0 | if (!value || !value->isString()) { |
205 | 0 | cmCMakePresetsErrors::INVALID_PRESET(value, state); |
206 | 0 | return false; |
207 | 0 | } |
208 | | |
209 | 0 | if (value->asString() == "human") { |
210 | 0 | out = TestPreset::ExecutionOptions::ShowOnlyEnum::Human; |
211 | 0 | return true; |
212 | 0 | } |
213 | | |
214 | 0 | if (value->asString() == "json-v1") { |
215 | 0 | out = TestPreset::ExecutionOptions::ShowOnlyEnum::JsonV1; |
216 | 0 | return true; |
217 | 0 | } |
218 | | |
219 | 0 | cmCMakePresetsErrors::INVALID_PRESET(value, state); |
220 | 0 | return false; |
221 | 0 | } |
222 | | |
223 | | auto const TestPresetOptionalExecutionShowOnlyHelper = |
224 | | JSONHelperBuilder::Optional<TestPreset::ExecutionOptions::ShowOnlyEnum>( |
225 | | TestPresetExecutionShowOnlyHelper); |
226 | | |
227 | | bool TestPresetExecutionModeHelper( |
228 | | TestPreset::ExecutionOptions::RepeatOptions::ModeEnum& out, |
229 | | Json::Value const* value, cmJSONState* state) |
230 | 0 | { |
231 | 0 | if (!value) { |
232 | 0 | return true; |
233 | 0 | } |
234 | | |
235 | 0 | if (!value->isString()) { |
236 | 0 | cmCMakePresetsErrors::INVALID_PRESET(value, state); |
237 | 0 | return false; |
238 | 0 | } |
239 | | |
240 | 0 | if (value->asString() == "until-fail") { |
241 | 0 | out = TestPreset::ExecutionOptions::RepeatOptions::ModeEnum::UntilFail; |
242 | 0 | return true; |
243 | 0 | } |
244 | | |
245 | 0 | if (value->asString() == "until-pass") { |
246 | 0 | out = TestPreset::ExecutionOptions::RepeatOptions::ModeEnum::UntilPass; |
247 | 0 | return true; |
248 | 0 | } |
249 | | |
250 | 0 | if (value->asString() == "after-timeout") { |
251 | 0 | out = TestPreset::ExecutionOptions::RepeatOptions::ModeEnum::AfterTimeout; |
252 | 0 | return true; |
253 | 0 | } |
254 | | |
255 | 0 | cmCMakePresetsErrors::INVALID_PRESET(value, state); |
256 | 0 | return false; |
257 | 0 | } |
258 | | |
259 | | auto const TestPresetOptionalExecutionRepeatHelper = |
260 | | JSONHelperBuilder::Optional<TestPreset::ExecutionOptions::RepeatOptions>( |
261 | | JSONHelperBuilder::Object<TestPreset::ExecutionOptions::RepeatOptions>() |
262 | | .Bind("mode"_s, &TestPreset::ExecutionOptions::RepeatOptions::Mode, |
263 | | TestPresetExecutionModeHelper, true) |
264 | | .Bind("count"_s, &TestPreset::ExecutionOptions::RepeatOptions::Count, |
265 | | cmCMakePresetsGraphInternal::PresetIntHelper, true)); |
266 | | |
267 | | bool TestPresetExecutionNoTestsActionHelper( |
268 | | TestPreset::ExecutionOptions::NoTestsActionEnum& out, |
269 | | Json::Value const* value, cmJSONState* state) |
270 | 0 | { |
271 | 0 | if (!value) { |
272 | 0 | out = TestPreset::ExecutionOptions::NoTestsActionEnum::Default; |
273 | 0 | return true; |
274 | 0 | } |
275 | | |
276 | 0 | if (!value->isString()) { |
277 | 0 | cmCMakePresetsErrors::INVALID_PRESET(value, state); |
278 | 0 | return false; |
279 | 0 | } |
280 | | |
281 | 0 | if (value->asString() == "default") { |
282 | 0 | out = TestPreset::ExecutionOptions::NoTestsActionEnum::Default; |
283 | 0 | return true; |
284 | 0 | } |
285 | | |
286 | 0 | if (value->asString() == "error") { |
287 | 0 | out = TestPreset::ExecutionOptions::NoTestsActionEnum::Error; |
288 | 0 | return true; |
289 | 0 | } |
290 | | |
291 | 0 | if (value->asString() == "ignore") { |
292 | 0 | out = TestPreset::ExecutionOptions::NoTestsActionEnum::Ignore; |
293 | 0 | return true; |
294 | 0 | } |
295 | | |
296 | 0 | cmCMakePresetsErrors::INVALID_PRESET(value, state); |
297 | 0 | return false; |
298 | 0 | } |
299 | | |
300 | | auto const TestPresetOptionalExecutionNoTestsActionHelper = |
301 | | JSONHelperBuilder::Optional<TestPreset::ExecutionOptions::NoTestsActionEnum>( |
302 | | TestPresetExecutionNoTestsActionHelper); |
303 | | |
304 | | bool TestPresetExecutionJobsHelper(cm::optional<unsigned int>& out, |
305 | | Json::Value const* value, |
306 | | cmJSONState* state) |
307 | 0 | { |
308 | 0 | if (value->isString()) { |
309 | 0 | if (!value->asString().empty()) { |
310 | 0 | cmCMakePresetsErrors::INVALID_PRESET(value, state); |
311 | 0 | return false; |
312 | 0 | } |
313 | 0 | out.reset(); |
314 | 0 | return true; |
315 | 0 | } |
316 | | |
317 | 0 | if (value->isUInt()) { |
318 | 0 | out.emplace(value->asUInt()); |
319 | 0 | return true; |
320 | 0 | } |
321 | | |
322 | 0 | cmCMakePresetsErrors::INVALID_PRESET(value, state); |
323 | 0 | return false; |
324 | 0 | } |
325 | | |
326 | | auto const TestPresetOptionalExecutionJobsHelper = |
327 | | JSONHelperBuilder::Optional<cm::optional<unsigned int>>( |
328 | | TestPresetExecutionJobsHelper); |
329 | | |
330 | | auto const TestPresetExecutionHelper = |
331 | | JSONHelperBuilder::Optional<TestPreset::ExecutionOptions>( |
332 | | JSONHelperBuilder::Object<TestPreset::ExecutionOptions>() |
333 | | .Bind("stopOnFailure"_s, &TestPreset::ExecutionOptions::StopOnFailure, |
334 | | cmCMakePresetsGraphInternal::PresetOptionalBoolHelper, false) |
335 | | .Bind("enableFailover"_s, &TestPreset::ExecutionOptions::EnableFailover, |
336 | | cmCMakePresetsGraphInternal::PresetOptionalBoolHelper, false) |
337 | | .Bind("jobs"_s, &TestPreset::ExecutionOptions::Jobs, |
338 | | TestPresetOptionalExecutionJobsHelper, false) |
339 | | .Bind("resourceSpecFile"_s, |
340 | | &TestPreset::ExecutionOptions::ResourceSpecFile, |
341 | | cmCMakePresetsGraphInternal::PresetStringHelper, false) |
342 | | .Bind("testLoad"_s, &TestPreset::ExecutionOptions::TestLoad, |
343 | | cmCMakePresetsGraphInternal::PresetOptionalIntHelper, false) |
344 | | .Bind("showOnly"_s, &TestPreset::ExecutionOptions::ShowOnly, |
345 | | TestPresetOptionalExecutionShowOnlyHelper, false) |
346 | | .Bind("repeat"_s, &TestPreset::ExecutionOptions::Repeat, |
347 | | TestPresetOptionalExecutionRepeatHelper, false) |
348 | | .Bind("interactiveDebugging"_s, |
349 | | &TestPreset::ExecutionOptions::InteractiveDebugging, |
350 | | cmCMakePresetsGraphInternal::PresetOptionalBoolHelper, false) |
351 | | .Bind("scheduleRandom"_s, &TestPreset::ExecutionOptions::ScheduleRandom, |
352 | | cmCMakePresetsGraphInternal::PresetOptionalBoolHelper, false) |
353 | | .Bind("timeout"_s, &TestPreset::ExecutionOptions::Timeout, |
354 | | cmCMakePresetsGraphInternal::PresetOptionalIntHelper, false) |
355 | | .Bind("noTestsAction"_s, &TestPreset::ExecutionOptions::NoTestsAction, |
356 | | TestPresetOptionalExecutionNoTestsActionHelper, false)); |
357 | | |
358 | | auto const TestPresetFilterHelper = |
359 | | JSONHelperBuilder::Optional<TestPreset::FilterOptions>( |
360 | | JSONHelperBuilder::Object<TestPreset::FilterOptions>() |
361 | | .Bind("include"_s, &TestPreset::FilterOptions::Include, |
362 | | TestPresetOptionalFilterIncludeHelper, false) |
363 | | .Bind("exclude"_s, &TestPreset::FilterOptions::Exclude, |
364 | | TestPresetOptionalFilterExcludeHelper, false)); |
365 | | |
366 | | auto const TestPresetHelper = |
367 | | JSONHelperBuilder::Object<TestPreset>( |
368 | | cmCMakePresetsErrors::INVALID_PRESET_OBJECT, false) |
369 | | .Bind("name"_s, &TestPreset::Name, |
370 | | cmCMakePresetsGraphInternal::PresetNameHelper) |
371 | | .Bind("inherits"_s, &TestPreset::Inherits, |
372 | | cmCMakePresetsGraphInternal::PresetVectorOneOrMoreStringHelper, |
373 | | false) |
374 | | .Bind("hidden"_s, &TestPreset::Hidden, |
375 | | cmCMakePresetsGraphInternal::PresetBoolHelper, false) |
376 | | .Bind<std::nullptr_t>("vendor"_s, nullptr, |
377 | | cmCMakePresetsGraphInternal::VendorHelper( |
378 | | cmCMakePresetsErrors::INVALID_PRESET), |
379 | | false) |
380 | | .Bind("displayName"_s, &TestPreset::DisplayName, |
381 | | cmCMakePresetsGraphInternal::PresetStringHelper, false) |
382 | | .Bind("description"_s, &TestPreset::Description, |
383 | | cmCMakePresetsGraphInternal::PresetStringHelper, false) |
384 | | .Bind("environment"_s, &TestPreset::Environment, |
385 | | cmCMakePresetsGraphInternal::EnvironmentMapHelper, false) |
386 | | .Bind("configurePreset"_s, &TestPreset::ConfigurePreset, |
387 | | cmCMakePresetsGraphInternal::PresetStringHelper, false) |
388 | | .Bind("inheritConfigureEnvironment"_s, |
389 | | &TestPreset::InheritConfigureEnvironment, |
390 | | cmCMakePresetsGraphInternal::PresetOptionalBoolHelper, false) |
391 | | .Bind("configuration"_s, &TestPreset::Configuration, |
392 | | cmCMakePresetsGraphInternal::PresetStringHelper, false) |
393 | | .Bind("overwriteConfigurationFile"_s, |
394 | | &TestPreset::OverwriteConfigurationFile, |
395 | | cmCMakePresetsGraphInternal::PresetVectorStringHelper, false) |
396 | | .Bind("output"_s, &TestPreset::Output, TestPresetOptionalOutputHelper, |
397 | | false) |
398 | | .Bind("filter"_s, &TestPreset::Filter, TestPresetFilterHelper, false) |
399 | | .Bind("execution"_s, &TestPreset::Execution, TestPresetExecutionHelper, |
400 | | false) |
401 | | .Bind("condition"_s, &TestPreset::ConditionEvaluator, |
402 | | cmCMakePresetsGraphInternal::PresetConditionHelper, false); |
403 | | } |
404 | | |
405 | | namespace cmCMakePresetsGraphInternal { |
406 | | bool TestPresetsHelper(std::vector<cmCMakePresetsGraph::TestPreset>& out, |
407 | | Json::Value const* value, cmJSONState* state) |
408 | 0 | { |
409 | 0 | static auto const helper = JSONHelperBuilder::Vector<TestPreset>( |
410 | 0 | cmCMakePresetsErrors::INVALID_PRESETS, TestPresetHelper); |
411 | |
|
412 | 0 | return helper(out, value, state); |
413 | 0 | } |
414 | | } |