-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScriptInfoTest.cpp
More file actions
623 lines (534 loc) · 25 KB
/
Copy pathScriptInfoTest.cpp
File metadata and controls
623 lines (534 loc) · 25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
#include "runcpp2/Data/ScriptInfo.hpp"
#include "runcpp2/LibYAML_Wrapper.hpp"
#include "runcpp2/runcpp2.hpp"
#include "runcpp2/DeferUtil.hpp"
#include "ssLogger/ssLog.hpp"
DS::Result<void> TestMain()
{
std::unordered_map<std::string, std::string> tempParameters;
//ScriptInfo Should Parse Valid YAML
{
//NOTE: This is just a test YAML for validating parsing, don't use it for actual config
const char* yamlStr = R"(
Language: C++
PassScriptPath: true
BuildType: Static
RequiredProfiles:
Windows: [MSVC]
Unix: [GCC]
Parameters:
Param1:
Optional: true
Default: "All"
Array: false
Constraint: ["A", "B", "C", "All:A,B,C"]
Param2:
Optional: true
Default: "123"
Array: false
Constraint: "Int"
Variables:
VarName1: "Some string {Param1} substitution"
OverrideCompileFlags:
Windows:
MSVC:
Remove: /W4
Append: /W3
Unix:
GCC:
Append: -g
OverrideLinkFlags:
Windows:
MSVC:
Remove: /SUBSYSTEM:CONSOLE
Append: /SUBSYSTEM:WINDOWS
OtherFilesToBeCompiled:
Windows:
MSVC:
- src/extra.cpp
- src/debug.cpp
Linux:
GCC:
- src/extra.cpp
- src/optimized.cpp
IncludePaths:
Windows:
MSVC:
- include
Defines:
Windows:
MSVC:
- _DEBUG
- VERSION=1.0.0
GCC:
- NDEBUG
Setup:
Windows:
MSVC:
- echo 1
- echo 2
Unix:
GCC:
- echo 3
- echo 4
PreBuild:
Windows:
MSVC:
- echo 2
- echo 3
Unix:
GCC:
- echo 4
- echo 5
PostBuild:
Windows:
MSVC:
- echo 3
- echo 4
Unix:
GCC:
- echo 5
- echo 6
Cleanup:
Windows:
MSVC:
- echo 4
- echo 5
Unix:
GCC:
- echo 6
- echo 7
Dependencies:
- Name: MyLib
Platforms:
- MSVC
- GCC
Source:
Git:
URL: https://github.com/user/mylib.git
LibraryType: Shared
IncludePaths:
- include
LinkProperties:
Windows:
MSVC:
SearchLibraryNames:
- mylib
SearchDirectories:
- lib/Debug
)";
runcpp2::YAML::ResourceHandle resource;
std::vector<runcpp2::YAML::NodePtr> roots = runcpp2::YAML::ParseYAML( yamlStr,
resource).DS_TRY();
DEFER { FreeYAMLResource(resource); };
DS_ASSERT_EQ(roots.size(), 1);
runcpp2::YAML::NodePtr root = roots.front();
runcpp2::Data::ScriptInfo scriptInfo;
scriptInfo.ParseYAML_Node(root, tempParameters).DS_TRY();
//Verify basic fields
DS_ASSERT_EQ(scriptInfo.Language, "C++");
DS_ASSERT_TRUE(scriptInfo.PassScriptPath);
DS_ASSERT_EQ((int)scriptInfo.CurrentBuildType, (int)runcpp2::Data::BuildType::STATIC);
//Verify RequiredProfiles
DS_ASSERT_EQ(scriptInfo.RequiredProfiles.at("Windows").size(), 1);
DS_ASSERT_EQ(scriptInfo.RequiredProfiles.at("Windows").at(0), "MSVC");
DS_ASSERT_EQ(scriptInfo.RequiredProfiles.at("Unix").size(), 1);
DS_ASSERT_EQ(scriptInfo.RequiredProfiles.at("Unix").at(0), "GCC");
//Verify Parameters
DS_ASSERT_EQ(scriptInfo.Parameters.count("Param1"), 1);
{
ParameterValue& paramVal = scriptInfo.Parameters["Param1"];
DS_ASSERT_TRUE(paramVal.Optional);
DS_ASSERT_EQ(paramVal.Default, "All");
DS_ASSERT_FALSE(paramVal.Array);
DS_ASSERT_TRUE( paramVal.CurrentConstraintType ==
runcpp2::Data::ParameterValue::ConstraintType::Choices);
DS_ASSERT_TRUE(mpark::is<std::vector<std::string>>(paramVal.ConstraintValue));
std::vector<std::string>& constraintVals =
mpark::get<std::vector<std::string>>(paramVal.ConstraintValue);
DS_ASSERT_EQ(constraintVals.size(), 4);
DS_ASSERT_EQ(constraintVals[2], "C");
}
DS_ASSERT_EQ(scriptInfo.Parameters.count("Param2"), 1);
{
ParameterValue& paramVal = scriptInfo.Parameters["Param2"];
DS_ASSERT_TRUE(paramVal.Optional);
DS_ASSERT_EQ(paramVal.Default, "123");
DS_ASSERT_FALSE(paramVal.Array);
DS_ASSERT_TRUE( paramVal.CurrentConstraintType ==
runcpp2::Data::ParameterValue::ConstraintType::Int);
//DS_ASSERT_TRUE(mpark::is<std::string>(paramVal.ConstraintValue));
}
//Verify Variables
DS_ASSERT_EQ(scriptInfo.Variables.count("VarName1"), 1);
DS_ASSERT_EQ(scriptInfo.Variables["VarName1"], "Some string {Param1} substitution");
//Verify OverrideCompileFlags
const runcpp2::Data::FlagsOverrideInfo& msvcCompileFlags =
scriptInfo.OverrideCompileFlags.at("Windows").FlagsOverrides.at("MSVC");
DS_ASSERT_EQ(msvcCompileFlags.Remove, "/W4");
DS_ASSERT_EQ(msvcCompileFlags.Append, "/W3");
//Verify OverrideLinkFlags
const runcpp2::Data::FlagsOverrideInfo& msvcLinkFlags =
scriptInfo.OverrideLinkFlags.at("Windows").FlagsOverrides.at("MSVC");
DS_ASSERT_EQ(msvcLinkFlags.Remove, "/SUBSYSTEM:CONSOLE");
DS_ASSERT_EQ(msvcLinkFlags.Append, "/SUBSYSTEM:WINDOWS");
//Verify OtherFilesToBeCompiled
const std::vector<ghc::filesystem::path>& msvcCompileFiles =
scriptInfo.OtherFilesToBeCompiled.at("Windows").Paths.at("MSVC");
DS_ASSERT_EQ(msvcCompileFiles.size(), 2);
DS_ASSERT_EQ(msvcCompileFiles.at(0), "src/extra.cpp");
const std::vector<ghc::filesystem::path>& gccCompileFiles =
scriptInfo.OtherFilesToBeCompiled.at("Linux").Paths.at("GCC");
DS_ASSERT_EQ(gccCompileFiles.size(), 2);
DS_ASSERT_EQ(gccCompileFiles.at(1), "src/optimized.cpp");
//Verify IncludePaths
const std::vector<ghc::filesystem::path>& msvcIncludeFiles =
scriptInfo.IncludePaths.at("Windows").Paths.at("MSVC");
DS_ASSERT_EQ(msvcIncludeFiles.size(), 1);
DS_ASSERT_EQ(msvcIncludeFiles.at(0), "include");
//Verify Defines
const std::vector<runcpp2::Data::Define>& msvcDefines =
scriptInfo.Defines.at("Windows").Defines.at("MSVC");
DS_ASSERT_EQ(msvcDefines.size(), 2);
DS_ASSERT_EQ(msvcDefines.at(0).Name, "_DEBUG");
DS_ASSERT_EQ(msvcDefines.at(1).Name, "VERSION");
DS_ASSERT_EQ(msvcDefines.at(1).Value, "1.0.0");
//Verify Setup
DS_ASSERT_EQ(scriptInfo.Setup.at("Windows").CommandSteps.at("MSVC").size(), 2);
DS_ASSERT_EQ(scriptInfo.Setup.at("Unix").CommandSteps.at("GCC").size(), 2);
const std::vector<std::string>& msvcSetupCommands =
scriptInfo.Setup.at("Windows").CommandSteps.at("MSVC");
const std::vector<std::string>& gccSetupCommands =
scriptInfo.Setup.at("Unix").CommandSteps.at("GCC");
DS_ASSERT_EQ(msvcSetupCommands.size(), 2);
DS_ASSERT_EQ(msvcSetupCommands.at(0), "echo 1");
DS_ASSERT_EQ(gccSetupCommands.size(), 2);
DS_ASSERT_EQ(gccSetupCommands.at(0), "echo 3");
//Verify PreBuild
DS_ASSERT_EQ(scriptInfo.PreBuild.at("Windows").CommandSteps.at("MSVC").size(), 2);
DS_ASSERT_EQ(scriptInfo.PreBuild.at("Unix").CommandSteps.at("GCC").size(), 2);
const std::vector<std::string>& msvcPreBuildCommands =
scriptInfo.PreBuild.at("Windows").CommandSteps.at("MSVC");
const std::vector<std::string>& gccPreBuildCommands =
scriptInfo.PreBuild.at("Unix").CommandSteps.at("GCC");
DS_ASSERT_EQ(msvcPreBuildCommands.size(), 2);
DS_ASSERT_EQ(msvcPreBuildCommands.at(0), "echo 2");
DS_ASSERT_EQ(gccPreBuildCommands.size(), 2);
DS_ASSERT_EQ(gccPreBuildCommands.at(1), "echo 5");
//Verify PostBuild
DS_ASSERT_EQ(scriptInfo.PostBuild.at("Unix").CommandSteps.at("GCC").size(), 2);
const std::vector<std::string>& gccPostBuildCommands =
scriptInfo.PostBuild.at("Unix").CommandSteps.at("GCC");
DS_ASSERT_EQ(gccPostBuildCommands.size(), 2);
DS_ASSERT_EQ(gccPostBuildCommands.at(1), "echo 6");
//Verify Cleanup
DS_ASSERT_EQ(scriptInfo.Cleanup.at("Windows").CommandSteps.at("MSVC").size(), 2);
const std::vector<std::string>& msvcCleanupCommands =
scriptInfo.Cleanup.at("Windows").CommandSteps.at("MSVC");
DS_ASSERT_EQ(msvcCleanupCommands.size(), 2);
DS_ASSERT_EQ(msvcCleanupCommands.at(0), "echo 4");
//Verify Dependencies
DS_ASSERT_EQ(scriptInfo.Dependencies.size(), 1);
DS_ASSERT_EQ(scriptInfo.Dependencies.at(0).Name, "MyLib");
DS_ASSERT_EQ( (int)scriptInfo.Dependencies.at(0).LibraryType,
(int)runcpp2::Data::DependencyLibraryType::SHARED);
//Test ToString() and Equals()
std::string yamlOutput = scriptInfo.ToString("").DS_TRY();
roots = runcpp2::YAML::ParseYAML(yamlOutput, resource).DS_TRY();
DS_ASSERT_EQ(roots.size(), 1);
runcpp2::Data::ScriptInfo parsedOutput;
parsedOutput.ParseYAML_Node(roots.front(), tempParameters).DS_TRY();
DS_ASSERT_TRUE(scriptInfo.Equals(parsedOutput));
}
//ScriptInfo Should Parse SourceFiles as OtherFilesToBeCompiled
{
//NOTE: This is just a test YAML for validating parsing, don't use it for actual config
const char* yamlStr = R"(
SourceFiles:
Windows:
MSVC:
- src/extra.cpp
- src/debug.cpp
)";
runcpp2::YAML::ResourceHandle resource;
std::vector<runcpp2::YAML::NodePtr> roots = runcpp2::YAML::ParseYAML( yamlStr,
resource).DS_TRY();
DEFER { FreeYAMLResource(resource); };
DS_ASSERT_EQ(roots.size(), 1);
runcpp2::YAML::NodePtr root = roots.front();
runcpp2::Data::ScriptInfo scriptInfo;
scriptInfo.ParseYAML_Node(root, tempParameters).DS_TRY();
//Verify SourceFiles
const std::vector<ghc::filesystem::path>& msvcCompileFiles =
scriptInfo.OtherFilesToBeCompiled.at("Windows").Paths.at("MSVC");
DS_ASSERT_EQ(msvcCompileFiles.size(), 2);
DS_ASSERT_EQ(msvcCompileFiles.at(0), "src/extra.cpp");
}
//ScriptInfo Should Parse Fields Without Platform And Profile As Default
{
//NOTE: This is just a test YAML for validating parsing, don't use it for actual config
const char* yamlStr = R"(
Language: C++
OverrideCompileFlags:
Remove: /W4
Append: /W3
OverrideLinkFlags:
Remove: /SUBSYSTEM:CONSOLE
Append: /SUBSYSTEM:WINDOWS
OtherFilesToBeCompiled:
- src/extra.cpp
- src/debug.cpp
IncludePaths:
- include
- src/include
Defines:
- _DEBUG
- VERSION=1.0.0
Setup:
- echo 1
- echo 2
PreBuild:
- echo 3
- echo 4
PostBuild:
- echo 5
- echo 6
Cleanup:
- echo 7
- echo 8
)";
runcpp2::YAML::ResourceHandle resource;
std::vector<runcpp2::YAML::NodePtr> roots = runcpp2::YAML::ParseYAML( yamlStr,
resource).DS_TRY();
DEFER { FreeYAMLResource(resource); };
DS_ASSERT_EQ(roots.size(), 1);
runcpp2::YAML::NodePtr root = roots.front();
runcpp2::Data::ScriptInfo scriptInfo;
scriptInfo.ParseYAML_Node(root, tempParameters).DS_TRY();
//Verify basic fields
DS_ASSERT_EQ(scriptInfo.Language, "C++");
//Verify OverrideCompileFlags with default platform and profile
const runcpp2::Data::FlagsOverrideInfo& defaultCompileFlags = scriptInfo.OverrideCompileFlags
.at("DefaultPlatform")
.FlagsOverrides
.at("DefaultProfile");
DS_ASSERT_EQ(defaultCompileFlags.Remove, "/W4");
DS_ASSERT_EQ(defaultCompileFlags.Append, "/W3");
//Verify OverrideLinkFlags with default platform and profile
const runcpp2::Data::FlagsOverrideInfo& defaultLinkFlags = scriptInfo .OverrideLinkFlags
.at("DefaultPlatform")
.FlagsOverrides
.at("DefaultProfile");
DS_ASSERT_EQ(defaultLinkFlags.Remove, "/SUBSYSTEM:CONSOLE");
DS_ASSERT_EQ(defaultLinkFlags.Append, "/SUBSYSTEM:WINDOWS");
//Verify OtherFilesToBeCompiled with default platform and profile
const std::vector<ghc::filesystem::path>& defaultCompileFiles =
scriptInfo.OtherFilesToBeCompiled.at("DefaultPlatform").Paths.at("DefaultProfile");
DS_ASSERT_EQ(defaultCompileFiles.size(), 2);
DS_ASSERT_EQ(defaultCompileFiles.at(0), "src/extra.cpp");
DS_ASSERT_EQ(defaultCompileFiles.at(1), "src/debug.cpp");
//Verify IncludePaths with default platform and profile
const std::vector<ghc::filesystem::path>& defaultIncludePaths =
scriptInfo.IncludePaths.at("DefaultPlatform").Paths.at("DefaultProfile");
DS_ASSERT_EQ(defaultIncludePaths.size(), 2);
DS_ASSERT_EQ(defaultIncludePaths.at(0), "include");
DS_ASSERT_EQ(defaultIncludePaths.at(1), "src/include");
//Verify Defines with default platform and profile
const std::vector<runcpp2::Data::Define>& defaultDefines =
scriptInfo.Defines.at("DefaultPlatform").Defines.at("DefaultProfile");
DS_ASSERT_EQ(defaultDefines.size(), 2);
DS_ASSERT_EQ(defaultDefines.at(0).Name, "_DEBUG");
DS_ASSERT_EQ(defaultDefines.at(1).Name, "VERSION");
DS_ASSERT_EQ(defaultDefines.at(1).Value, "1.0.0");
//Verify Setup with default platform and profile
const std::vector<std::string>& defaultSetupCommands =
scriptInfo.Setup.at("DefaultPlatform").CommandSteps.at("DefaultProfile");
DS_ASSERT_EQ(defaultSetupCommands.size(), 2);
DS_ASSERT_EQ(defaultSetupCommands.at(0), "echo 1");
DS_ASSERT_EQ(defaultSetupCommands.at(1), "echo 2");
//Verify PreBuild with default platform and profile
const std::vector<std::string>& defaultPreBuildCommands =
scriptInfo.PreBuild.at("DefaultPlatform").CommandSteps.at("DefaultProfile");
DS_ASSERT_EQ(defaultPreBuildCommands.size(), 2);
DS_ASSERT_EQ(defaultPreBuildCommands.at(0), "echo 3");
DS_ASSERT_EQ(defaultPreBuildCommands.at(1), "echo 4");
//Verify PostBuild with default platform and profile
const std::vector<std::string>& defaultPostBuildCommands =
scriptInfo.PostBuild.at("DefaultPlatform").CommandSteps.at("DefaultProfile");
DS_ASSERT_EQ(defaultPostBuildCommands.size(), 2);
DS_ASSERT_EQ(defaultPostBuildCommands.at(0), "echo 5");
DS_ASSERT_EQ(defaultPostBuildCommands.at(1), "echo 6");
//Verify Cleanup with default platform and profile
const std::vector<std::string>& defaultCleanupCommands =
scriptInfo.Cleanup.at("DefaultPlatform").CommandSteps.at("DefaultProfile");
DS_ASSERT_EQ(defaultCleanupCommands.size(), 2);
DS_ASSERT_EQ(defaultCleanupCommands.at(0), "echo 7");
DS_ASSERT_EQ(defaultCleanupCommands.at(1), "echo 8");
}
//ScriptInfo Should Perform Substitutions Correctly
{
std::unordered_map<std::string, std::string> parameters = {
{"ChoiceParam", "B"},
{"IntParam", "7"}
};
const char* yamlStr = R"(
Language: C++
Parameters:
ChoiceParam:
Optional: true
Array: false
Constraint: ["A", "B", "C", "All:A,B,C"]
IntParam:
Optional: true
Array: false
Constraint: "Int"
Variables:
Var1: "The choice is {ChoiceParam}"
Var2: "5+{IntParam}"
Defines:
- "TEST_DEFINE_1=\"{Var1}\""
- "TEST_DEFINE_2={Var2}"
)";
runcpp2::YAML::ResourceHandle resource;
std::vector<runcpp2::YAML::NodePtr> roots = runcpp2::YAML::ParseYAML( yamlStr,
resource).DS_TRY();
DEFER { FreeYAMLResource(resource); };
DS_ASSERT_EQ(roots.size(), 1);
runcpp2::YAML::NodePtr root = roots.front();
runcpp2::Data::ScriptInfo scriptInfo;
scriptInfo.ParseYAML_Node(root, parameters).DS_TRY();
const std::vector<runcpp2::Data::Define>& defaultDefines =
scriptInfo.Defines.at("DefaultPlatform").Defines.at("DefaultProfile");
DS_ASSERT_EQ(defaultDefines.size(), 2);
DS_ASSERT_EQ(defaultDefines[0].Value, std::string("\"The choice is B\""));
DS_ASSERT_EQ(defaultDefines[1].Value, std::string("5+7"));
}
//ScriptInfo Should Apply Parameters Substitutions Once, Everywhere
{
std::unordered_map<std::string, std::string> parameters;
const char* yamlStr = R"(
Language: C++
Parameters:
IntParam:
Optional: true
Array: false
Constraint: "Int"
Defines:
- "TEST_DEFINE_1={{{{Test}}}}"
Dependencies:
- Name: "{{{{MyLib}}}}"
Platforms: [GCC]
Source:
Git:
URL: https://github.com/user/mylib.git
LibraryType: Header
IncludePaths:
- include
)";
runcpp2::YAML::ResourceHandle resource;
std::vector<runcpp2::YAML::NodePtr> roots = runcpp2::YAML::ParseYAML( yamlStr,
resource).DS_TRY();
DEFER { FreeYAMLResource(resource); };
DS_ASSERT_EQ(roots.size(), 1);
runcpp2::YAML::NodePtr root = roots.front();
runcpp2::Data::ScriptInfo scriptInfo;
scriptInfo.ParseYAML_Node(root, parameters).DS_TRY();
{
const std::vector<runcpp2::Data::Define>& defaultDefines =
scriptInfo.Defines.at("DefaultPlatform").Defines.at("DefaultProfile");
DS_ASSERT_EQ(defaultDefines.size(), 1);
DS_ASSERT_EQ(defaultDefines[0].Name, std::string("TEST_DEFINE_1"));
DS_ASSERT_EQ(defaultDefines[0].Value, std::string("{{Test}}"));
DS_ASSERT_EQ(scriptInfo.Dependencies.size(), 1);
DS_ASSERT_EQ(scriptInfo.Dependencies[0].Name, std::string("{{MyLib}}"));
}
yamlStr = R"(
Language: C++
Parameters:
IntParam:
Optional: true
Array: false
Constraint: "Int"
Defines:
- "TEST_DEFINE_1={{{{Test}}}}"
Dependencies:
- Name: "{{{{MyLib}}}}"
Platforms: [GCC]
Source:
Git:
URL: https://github.com/user/mylib.git
LibraryType: Header
Parameters:
IntParam2:
Optional: true
Array: false
Constraint: "Int"
IncludePaths:
- include
Setup: ["{IntParam}", "{IntParam2}"]
)";
parameters = { {"IntParam", "5"}, {"IntParam2", "6"} };
roots = runcpp2::YAML::ParseYAML(yamlStr, resource).DS_TRY();
DS_ASSERT_EQ(roots.size(), 1);
root = roots.front();
scriptInfo = {};
scriptInfo.ParseYAML_Node(root, parameters).DS_TRY();
{
const std::vector<runcpp2::Data::Define>& defaultDefines =
scriptInfo.Defines.at("DefaultPlatform").Defines.at("DefaultProfile");
DS_ASSERT_EQ(defaultDefines.size(), 1);
DS_ASSERT_EQ(defaultDefines[0].Name, std::string("TEST_DEFINE_1"));
DS_ASSERT_EQ(defaultDefines[0].Value, std::string("{{Test}}"));
DS_ASSERT_EQ(scriptInfo.Dependencies.size(), 1);
DS_ASSERT_EQ(scriptInfo.Dependencies[0].Name, std::string("{{MyLib}}"));
const std::vector<std::string>& defaultSetups = scriptInfo .Dependencies[0]
.Setup
.at("DefaultPlatform")
.CommandSteps
.at("DefaultProfile");
DS_ASSERT_EQ(defaultSetups.size(), 2);
DS_ASSERT_EQ(defaultSetups[0], parameters.at("IntParam"));
DS_ASSERT_EQ(defaultSetups[1], parameters.at("IntParam2"));
}
}
//ScriptInfo With Unsubstituted Params Should Fail Parsing
{
std::unordered_map<std::string, std::string> parameters;
const char* yamlStr = R"(
Language: C++
Parameters:
IntParam:
Optional: true
Array: false
Constraint: "Int"
Defines:
- "TEST_DEFINE_1={UnexpectedParameter}"
)";
runcpp2::YAML::ResourceHandle resource;
std::vector<runcpp2::YAML::NodePtr> roots = runcpp2::YAML::ParseYAML( yamlStr,
resource).DS_TRY();
DEFER { FreeYAMLResource(resource); };
DS_ASSERT_EQ(roots.size(), 1);
runcpp2::YAML::NodePtr root = roots.front();
runcpp2::Data::ScriptInfo scriptInfo;
DS::Result<void> res = scriptInfo.ParseYAML_Node(root, parameters);
DS_ASSERT_FALSE(res.HasValue());
DS_ASSERT_EQ( res.Error().Message,
"Parameter {UnexpectedParameter} is expected but nothing is supplied");
}
return {};
}
int main(int argc, char** argv)
{
try
{
TestMain().DS_TRY_ACT(ssLOG_LINE(DS_TMP_ERROR.ToString()); return 1);
return 0;
}
catch(std::exception& ex)
{
ssLOG_LINE(ex.what());
return 1;
}
return 1;
}