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