-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathtest_manifest.cpp
More file actions
4745 lines (4403 loc) · 174 KB
/
Copy pathtest_manifest.cpp
File metadata and controls
4745 lines (4403 loc) · 174 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
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <gtest/gtest.h>
import std;
import mcpp.manifest;
import mcpp.libs.toml;
import mcpp.pm.dep_spec;
import mcpp.platform.axis;
import mcpp.platform;
TEST(Manifest, CppFlyStandard) {
// standard = "c++fly": latest level + all experimental gates (design
// 2026-07-14-std-features-experimental-gate-design.md §5.1).
auto cfg = mcpp::manifest::normalize_cpp_standard("c++fly");
ASSERT_TRUE(cfg.has_value());
EXPECT_EQ(cfg->canonical, "c++fly");
EXPECT_EQ(cfg->level, 1000); // above c++latest's 999
EXPECT_TRUE(cfg->experimental);
EXPECT_FALSE(mcpp::manifest::normalize_cpp_standard("c++latest")->experimental);
EXPECT_FALSE(mcpp::manifest::normalize_cpp_standard("c++26")->experimental);
auto bad = mcpp::manifest::normalize_cpp_standard("c++flyy");
ASSERT_FALSE(bad.has_value());
EXPECT_NE(bad.error().find("c++fly"), std::string::npos); // listed in the allow-list message
}
TEST(Manifest, Cpp20Standard) {
// C++20 is the floor of the allow-list: named modules are a C++20 feature,
// so nothing below it exists for this build model
// (.agents/docs/2026-07-31-cpp20-standard-support-design.md).
auto cfg = mcpp::manifest::normalize_cpp_standard("c++20");
ASSERT_TRUE(cfg.has_value());
EXPECT_EQ(cfg->canonical, "c++20");
EXPECT_EQ(cfg->flag, "-std=c++20");
EXPECT_EQ(cfg->level, 20);
EXPECT_FALSE(cfg->gnuDialect);
EXPECT_FALSE(cfg->experimental);
// Aliases, symmetric with the existing c++2b / c++2c handling.
auto alias = mcpp::manifest::normalize_cpp_standard("C++2a"); // also case-folded
ASSERT_TRUE(alias.has_value());
EXPECT_EQ(alias->canonical, "c++20");
EXPECT_EQ(alias->level, 20);
auto gnu = mcpp::manifest::normalize_cpp_standard("gnu++20");
ASSERT_TRUE(gnu.has_value());
EXPECT_EQ(gnu->canonical, "gnu++20");
EXPECT_EQ(gnu->flag, "-std=gnu++20");
EXPECT_EQ(gnu->level, 20);
EXPECT_TRUE(gnu->gnuDialect);
EXPECT_EQ(mcpp::manifest::normalize_cpp_standard("gnu++2a")->canonical, "gnu++20");
// Below the floor stays rejected, and the message advertises the floor.
auto bad = mcpp::manifest::normalize_cpp_standard("c++17");
ASSERT_FALSE(bad.has_value());
EXPECT_NE(bad.error().find("c++20"), std::string::npos) << bad.error();
}
TEST(Manifest, CppStandardLevelName) {
EXPECT_EQ(mcpp::manifest::cpp_standard_level_name(20), "c++20");
EXPECT_EQ(mcpp::manifest::cpp_standard_level_name(23), "c++23");
EXPECT_EQ(mcpp::manifest::cpp_standard_level_name(26), "c++26");
}
TEST(Manifest, MinimalValid) {
constexpr auto src = R"(
[package]
name = "hello"
version = "0.1.0"
[language]
standard = "c++23"
[modules]
sources = ["src/**/*.cppm"]
[targets.hello]
kind = "bin"
main = "src/main.cpp"
)";
auto m = mcpp::manifest::parse_string(src);
ASSERT_TRUE(m.has_value()) << m.error().format();
EXPECT_EQ(m->package.name, "hello");
EXPECT_EQ(m->package.version, "0.1.0");
EXPECT_EQ(m->language.standard, "c++23");
EXPECT_TRUE(m->language.modules);
ASSERT_EQ(m->targets.size(), 1u);
EXPECT_EQ(m->targets[0].name, "hello");
EXPECT_EQ(m->targets[0].kind, mcpp::manifest::Target::Binary);
}
TEST(Manifest, XlingsSubosPreservesDeclarationPresence) {
auto absent = mcpp::manifest::parse_string(R"(
[package]
name = "absent"
version = "0.1.0"
)");
ASSERT_TRUE(absent.has_value()) << absent.error().format();
EXPECT_FALSE(absent->xlings.subosDeclared);
auto explicitDefault = mcpp::manifest::parse_string(R"(
[package]
name = "explicit"
version = "0.1.0"
[xlings]
subos = "default"
)");
ASSERT_TRUE(explicitDefault.has_value()) << explicitDefault.error().format();
EXPECT_TRUE(explicitDefault->xlings.subosDeclared);
EXPECT_EQ(explicitDefault->xlings.subos, "default");
auto empty = mcpp::manifest::parse_string(R"(
[package]
name = "bad"
version = "0.1.0"
[xlings]
subos = ""
)");
ASSERT_TRUE(empty.has_value()) << empty.error().format();
EXPECT_TRUE(empty->xlings.subosDeclared);
EXPECT_TRUE(empty->xlings.subos.empty());
}
TEST(Manifest, SharedTargetSoname) {
constexpr auto src = R"(
[package]
name = "dep"
version = "0.1.0"
[build]
sources = ["src/*.c"]
[targets.dep]
kind = "shared"
soname = "libdep.so.1"
)";
auto m = mcpp::manifest::parse_string(src);
ASSERT_TRUE(m.has_value()) << m.error().format();
ASSERT_EQ(m->targets.size(), 1u);
EXPECT_EQ(m->targets[0].kind, mcpp::manifest::Target::SharedLibrary);
EXPECT_EQ(m->targets[0].soname, "libdep.so.1");
}
TEST(Manifest, RejectsSonameOnANonLibraryTarget) {
// ⚠️ NARROWED from "non-shared" to "non-library" (#519). A soname is the
// name a library is FOUND by, and a package needs to be able to state it
// while still being consumed as a static library — otherwise two copies
// of one library can never resolve to a single file. An EXECUTABLE still
// has no business declaring one.
constexpr auto src = R"(
[package]
name = "app"
version = "0.1.0"
[targets.app]
kind = "bin"
main = "src/main.cpp"
soname = "libapp.so.1"
)";
auto m = mcpp::manifest::parse_string(src);
ASSERT_FALSE(m.has_value());
EXPECT_NE(m.error().message.find("soname is only valid for library targets"),
std::string::npos);
}
TEST(Manifest, PackageStandardCpp26AcceptedAndMirrored) {
constexpr auto src = R"(
[package]
name = "hello26"
version = "0.1.0"
standard = "c++26"
[modules]
sources = ["src/**/*.cppm"]
[targets.hello26]
kind = "bin"
main = "src/main.cpp"
)";
auto m = mcpp::manifest::parse_string(src);
ASSERT_TRUE(m.has_value()) << m.error().format();
EXPECT_EQ(m->package.standard, "c++26");
EXPECT_EQ(m->language.standard, "c++26");
}
TEST(Manifest, LegacyLanguageCpp2cNormalizesToCpp26) {
constexpr auto src = R"(
[package]
name = "hello26"
version = "0.1.0"
[language]
standard = "c++2c"
[modules]
sources = ["src/**/*.cppm"]
[targets.hello26]
kind = "bin"
main = "src/main.cpp"
)";
auto m = mcpp::manifest::parse_string(src);
ASSERT_TRUE(m.has_value()) << m.error().format();
EXPECT_EQ(m->package.standard, "c++26");
EXPECT_EQ(m->language.standard, "c++26");
}
TEST(Manifest, RejectsStdFlagInCxxflags) {
auto m = mcpp::manifest::parse_string(R"(
[package]
name = "x"
version = "0.1.0"
[build]
cxxflags = ["-std=c++26"]
[modules]
sources = ["src/**/*.cppm"]
[targets.x]
kind = "bin"
main = "src/main.cpp"
)");
ASSERT_FALSE(m.has_value());
EXPECT_NE(m.error().message.find("[package].standard"), std::string::npos)
<< m.error().message;
}
TEST(Manifest, RejectMissingVersion) {
auto m = mcpp::manifest::parse_string(R"(
[package]
name = "x"
[modules]
sources = ["src/**/*.cppm"]
[targets.x]
kind = "bin"
main = "src/main.cpp"
)");
ASSERT_FALSE(m.has_value());
EXPECT_NE(m.error().message.find("package.version"), std::string::npos);
}
TEST(Manifest, AcceptsCpp20WithImportStd) {
// Was RejectImportStdWithoutCpp23: it asserted this manifest is rejected,
// but the only thing rejecting it was the standard allow-list (there has
// never been an import_std-specific rule) — so the test's name described
// coverage it did not have. C++20 is legal now, and `import std;` is
// available there on every toolchain mcpp ships, so the same manifest must
// parse, with the legacy [language] section still mirroring to the new home.
auto m = mcpp::manifest::parse_string(R"(
[package]
name = "x"
version = "0.1.0"
[language]
standard = "c++20"
import_std = true
[modules]
sources = ["src/**/*.cppm"]
[targets.x]
kind = "bin"
main = "src/main.cpp"
)");
ASSERT_TRUE(m.has_value()) << m.error().message;
EXPECT_EQ(m->package.standard, "c++20"); // canonical, mirrored from [language]
EXPECT_EQ(m->language.standard, "c++20");
EXPECT_EQ(m->cppStandard.level, 20);
EXPECT_EQ(m->cppStandard.flag, "-std=c++20");
}
TEST(Manifest, RejectsStandardBelowCpp20) {
auto m = mcpp::manifest::parse_string(R"(
[package]
name = "x"
version = "0.1.0"
standard = "c++17"
[targets.x]
kind = "bin"
main = "src/main.cpp"
)");
ASSERT_FALSE(m.has_value());
EXPECT_NE(m.error().message.find("c++17"), std::string::npos)
<< m.error().message;
}
TEST(Manifest, RejectModulesFalse) {
auto m = mcpp::manifest::parse_string(R"(
[package]
name = "x"
version = "0.1.0"
[language]
standard = "c++23"
modules = false
[modules]
sources = ["src/**/*.cppm"]
[targets.x]
kind = "bin"
main = "src/main.cpp"
)");
ASSERT_FALSE(m.has_value());
}
TEST(Manifest, ParsesDependencies) {
auto m = mcpp::manifest::parse_string(R"(
[package]
name = "x"
version = "0.1.0"
[modules]
sources = ["src/**/*.cppm"]
[targets.x]
kind = "bin"
main = "src/main.cpp"
[dependencies]
"mcpplibs.primitives" = "0.0.1"
[dev-dependencies]
"gtest" = "1.15.2"
)");
ASSERT_TRUE(m.has_value()) << m.error().format();
EXPECT_EQ(m->dependencies.size(), 1u);
EXPECT_EQ(m->dependencies.at("mcpplibs.primitives").version, "0.0.1");
EXPECT_EQ(m->devDependencies.at("gtest").version, "1.15.2");
}
TEST(Manifest, ParsesDependencyVisibility) {
auto m = mcpp::manifest::parse_string(R"(
[package]
name = "x"
version = "0.1.0"
[modules]
sources = ["src/**/*.cppm"]
[targets.x]
kind = "bin"
main = "src/main.cpp"
[dependencies.compat]
imgui = { version = "1.92.8", visibility = "private" }
glfw = { version = "3.4", visibility = "interface" }
opengl = "2026.05.31"
)");
ASSERT_TRUE(m.has_value()) << m.error().format();
ASSERT_EQ(m->dependencies.size(), 3u);
EXPECT_EQ(m->dependencies.at("compat.imgui").visibility, "private");
EXPECT_EQ(m->dependencies.at("compat.glfw").visibility, "interface");
EXPECT_EQ(m->dependencies.at("compat.opengl").visibility, "public");
}
// #242 — consumer-side `default-features = false`: a consumer opts out of a
// dependency's own [features].default set (Cargo parity). The flag parses into
// DependencySpec.defaultFeatures; explicitly requested `features = [...]` still
// come through. Default (omitted) stays true.
TEST(Manifest, ParsesDependencyDefaultFeaturesOptOut) {
auto m = mcpp::manifest::parse_string(R"(
[package]
name = "x"
version = "0.1.0"
[modules]
sources = ["src/**/*.cppm"]
[targets.x]
kind = "bin"
main = "src/main.cpp"
[dependencies.compat]
ffmpeg = { version = "6.1", default-features = false, features = ["avcodec"] }
zlib = "1.3"
)");
ASSERT_TRUE(m.has_value()) << m.error().format();
ASSERT_EQ(m->dependencies.size(), 2u);
// Opt-out dependency: flag is false, but the explicit feature still parses.
const auto& ff = m->dependencies.at("compat.ffmpeg");
EXPECT_FALSE(ff.defaultFeatures);
ASSERT_EQ(ff.features.size(), 1u);
EXPECT_EQ(ff.features[0], "avcodec");
EXPECT_EQ(ff.version, "6.1");
// Bare-string dependency: defaultFeatures defaults to true.
EXPECT_TRUE(m->dependencies.at("compat.zlib").defaultFeatures);
}
TEST(Manifest, RejectsInvalidDependencyVisibility) {
auto m = mcpp::manifest::parse_string(R"(
[package]
name = "x"
version = "0.1.0"
[dependencies.compat]
imgui = { version = "1.92.8", visibility = "implementation" }
)");
ASSERT_FALSE(m.has_value());
EXPECT_NE(m.error().message.find("visibility"), std::string::npos);
}
TEST(Manifest, DefaultTemplateRoundTrip) {
auto src = mcpp::manifest::default_template("hello");
auto m = mcpp::manifest::parse_string(src);
ASSERT_TRUE(m.has_value()) << m.error().format();
EXPECT_EQ(m->package.name, "hello");
}
TEST(ManifestEditor, UpsertsCanonicalDependencyByExactPackageId) {
constexpr std::string_view source = R"([package]
name = "app"
version = "0.1.0"
[dependencies.compat]
widget = "1.0.0"
)";
auto edited = mcpp::manifest::upsert_dependency_text(source, {
.namespace_ = "acme",
.shortName = "widget",
.version = "2.0.0",
.features = {"gui", "vulkan"},
});
ASSERT_TRUE(edited.has_value()) << edited.error();
EXPECT_NE(edited->find("[dependencies.acme]\nwidget = { version = \"2.0.0\", features = [\"gui\", \"vulkan\"] }"),
std::string::npos);
auto parsed = mcpp::manifest::parse_string(*edited);
ASSERT_TRUE(parsed.has_value()) << parsed.error().format();
ASSERT_EQ(parsed->dependencies.size(), 2u);
EXPECT_EQ(parsed->dependencies.at("acme.widget").namespace_, "acme");
EXPECT_EQ(parsed->dependencies.at("acme.widget").shortName, "widget");
EXPECT_EQ(parsed->dependencies.at("acme.widget").version, "2.0.0");
EXPECT_EQ(parsed->dependencies.at("acme.widget").features,
(std::vector<std::string>{"gui", "vulkan"}));
EXPECT_EQ(parsed->dependencies.at("compat.widget").version, "1.0.0");
}
TEST(ManifestEditor, ReplacesCanonicalEntryAndRejectsInvalidSource) {
constexpr std::string_view source = R"([package]
name = "app"
version = "0.1.0"
[dependencies.acme]
widget = "1.0.0"
)";
auto edited = mcpp::manifest::upsert_dependency_text(source, {
.namespace_ = "acme",
.shortName = "widget",
.version = "3.0.0",
});
ASSERT_TRUE(edited.has_value()) << edited.error();
auto parsed = mcpp::manifest::parse_string(*edited);
ASSERT_TRUE(parsed.has_value()) << parsed.error().format();
EXPECT_EQ(parsed->dependencies.at("acme.widget").version, "3.0.0");
EXPECT_EQ(std::ranges::count(*edited, '\n'),
std::ranges::count(source, '\n'));
auto invalid = mcpp::manifest::upsert_dependency_text(
"[package\nname = \"broken\"", {
.namespace_ = "acme",
.shortName = "widget",
.version = "1.0.0",
});
ASSERT_FALSE(invalid.has_value());
EXPECT_NE(invalid.error().find("invalid manifest"), std::string::npos);
}
TEST(ListXpkgVersions, MultipleEntriesAcrossPlatforms) {
constexpr auto src = R"(
package = {
name = "foo",
xpm = {
linux = {
["0.1.0"] = { url = "u1", sha256 = "x" },
["0.2.0"] = { url = "u2", sha256 = "y" },
["1.0.0"] = { url = "u3", sha256 = "z" },
},
macosx = {
["0.1.0"] = { url = "u1m", sha256 = "x" },
},
},
}
)";
auto linux = mcpp::manifest::list_xpkg_versions(src, mcpp::platform::TargetPlatform::for_lint_of("linux"));
ASSERT_EQ(linux.size(), 3u);
EXPECT_EQ(linux[0], "0.1.0");
EXPECT_EQ(linux[1], "0.2.0");
EXPECT_EQ(linux[2], "1.0.0");
auto mac = mcpp::manifest::list_xpkg_versions(src, mcpp::platform::TargetPlatform::for_lint_of("macosx"));
ASSERT_EQ(mac.size(), 1u);
EXPECT_EQ(mac[0], "0.1.0");
auto win = mcpp::manifest::list_xpkg_versions(src, mcpp::platform::TargetPlatform::for_lint_of("windows"));
EXPECT_TRUE(win.empty());
}
TEST(ListXpkgVersions, MissingXpmReturnsEmpty) {
constexpr auto src = R"(package = { name = "foo" })";
EXPECT_TRUE(mcpp::manifest::list_xpkg_versions(src, mcpp::platform::TargetPlatform::for_lint_of("linux")).empty());
}
// #363: `["25.0.4"] = { ref = "25.0.4.7.1" }` is a POINTER at another entry,
// not a release. Shape copied from the real jdk-corretto / jdk-temurin
// descriptors. Treating it as a version gave range resolution a candidate that
// ties with (or truncates to something other than) its own target.
TEST(ListXpkgVersions, AliasEntriesAreFlagged) {
constexpr auto src = R"(
package = {
name = "jdk",
xpm = {
linux = {
["latest"] = { ref = "25.0.4.7.1" },
["25.0.4"] = { ref = "25.0.4.7.1" },
["25.0.4.7.1"] = { url = "u", sha256 = "z" },
},
},
}
)";
auto e = mcpp::manifest::list_xpkg_version_entries(
src, mcpp::platform::TargetPlatform::for_lint_of("linux"));
ASSERT_EQ(e.size(), 3u);
EXPECT_EQ(e[0].version, "latest"); EXPECT_TRUE (e[0].alias);
EXPECT_EQ(e[1].version, "25.0.4"); EXPECT_TRUE (e[1].alias);
EXPECT_EQ(e[2].version, "25.0.4.7.1"); EXPECT_FALSE(e[2].alias);
EXPECT_TRUE(e[0].sha256.empty());
EXPECT_TRUE(e[1].sha256.empty());
EXPECT_EQ(e[2].sha256, "z");
// The keys-only view is unchanged for every existing caller.
auto keys = mcpp::manifest::list_xpkg_versions(
src, mcpp::platform::TargetPlatform::for_lint_of("linux"));
ASSERT_EQ(keys.size(), 3u);
EXPECT_EQ(keys[2], "25.0.4.7.1");
}
// The scanner used to walk the platform table character by character, so a
// bracket key nested inside a version's own body (mirror tables write
// `["GLOBAL"] = "https://..."`) counted as a published version.
TEST(ListXpkgVersions, NestedBracketKeysAreNotVersions) {
constexpr auto src = R"(
package = {
name = "foo",
xpm = {
linux = {
["1.0.0"] = {
url = { ["GLOBAL"] = "u-global", ["CN"] = "u-cn" },
sha256 = "z",
},
["1.1.0"] = { url = "u", sha256 = "z" },
},
},
}
)";
auto keys = mcpp::manifest::list_xpkg_versions(
src, mcpp::platform::TargetPlatform::for_lint_of("linux"));
ASSERT_EQ(keys.size(), 2u);
EXPECT_EQ(keys[0], "1.0.0");
EXPECT_EQ(keys[1], "1.1.0");
}
TEST(Manifest, BuildCflagsCxxflagsAndCStandard) {
constexpr auto src = R"(
[package]
name = "x"
version = "0.1.0"
[build]
sources = ["src/**/*.{cppm,c}"]
cflags = ["-Wall", "-DFOO=1"]
cxxflags = ["-Wextra"]
ldflags = ["-lfoo", "-Wl,--as-needed"]
c_standard = "c11"
[targets.x]
kind = "lib"
)";
auto m = mcpp::manifest::parse_string(src);
ASSERT_TRUE(m.has_value()) << m.error().format();
ASSERT_EQ(m->buildConfig.cflags.size(), 2u);
EXPECT_EQ(m->buildConfig.cflags[0], "-Wall");
EXPECT_EQ(m->buildConfig.cflags[1], "-DFOO=1");
ASSERT_EQ(m->buildConfig.cxxflags.size(), 1u);
EXPECT_EQ(m->buildConfig.cxxflags[0], "-Wextra");
ASSERT_EQ(m->buildConfig.ldflags.size(), 2u);
EXPECT_EQ(m->buildConfig.ldflags[0], "-lfoo");
EXPECT_EQ(m->buildConfig.ldflags[1], "-Wl,--as-needed");
EXPECT_EQ(m->buildConfig.cStandard, "c11");
}
// #296: [build].defines is sugar for `-D<x>` on both C and C++ channels; it
// must parse into buildConfig.defines so prepare_build can fold it into flags
// before the P1689 scan and fingerprint. Order is preserved because the fold
// appends in declaration order and "last flag wins" is the override semantics.
TEST(Manifest, BuildDefinesParsesIntoSeparateVector) {
constexpr auto src = R"(
[package]
name = "x"
version = "0.1.0"
[build]
defines = ["TEST_USE_MODULES", "VALUE=42"]
)";
auto m = mcpp::manifest::parse_string(src);
ASSERT_TRUE(m.has_value()) << m.error().format();
ASSERT_EQ(m->buildConfig.defines.size(), 2u);
EXPECT_EQ(m->buildConfig.defines[0], "TEST_USE_MODULES");
EXPECT_EQ(m->buildConfig.defines[1], "VALUE=42");
// A well-formed [build] must not warn — the unknown-key guard below is
// only allowed to fire on keys the parser genuinely does not read.
EXPECT_TRUE(m->schemaWarnings.empty())
<< (m->schemaWarnings.empty() ? "" : m->schemaWarnings[0]);
}
// ── #540: the three vocabularies, and the drift that keeps happening ────────
//
// `kKnownBuildKeys`, `kKnownConditionalBuildKeys` and the xpkg `target_cfg`
// list are hand-written transcriptions of sets that exist elsewhere in
// machine-readable form — the `doc->get_*()` reads immediately above them, and
// `BuildInputs`'s member list. All three had drifted, in different directions,
// and `kKnownBuildKeys` had drifted TWICE: the comment beside it narrates the
// `bmi_schedule` occurrence in detail while three keys eight lines above it
// were in the same state.
//
// The user-visible cost is not a missing warning. It is a warning that is
// FALSE — "[build] has unsupported key 'std-module' (ignored)" for a key read
// a few hundred lines above and taking full effect — which is worse than
// silence, because the only sentence mcpp offers about the key says the
// opposite of what happens.
//
// ⚠️ THE LIST BELOW IS ANOTHER COPY, AND THAT IS THE POINT. A copy that fails
// loudly when it disagrees is the whole difference from the arrangement that
// let this happen twice. Add a key to the parser, add it here; if you forget,
// the negative control at the bottom of each test still passes and this one
// goes red.
TEST(Manifest, EveryBuildKeyTheParserReadsIsAccepted) {
constexpr auto src = R"(
[package]
name = "x"
version = "0.1.0"
[build]
allow_host_libs = false
bmi_schedule = "auto"
build_program_timeout = 120
c_standard = "c17"
cache = "local"
cflags = ["-Wall"]
cxxflags = ["-Wall"]
cxx_runtime = "self-contained"
default-profile = "release"
defines = ["A=1"]
dependency_linkage = "static"
dialect_cxxflags = ["-fno-rtti"]
include_dirs = ["include"]
include_dirs_after = ["compat"]
private_include_dirs = ["internal"]
jobs = 4
ldflags = ["-Wl,--as-needed"]
macos_deployment_target = "14.0"
module_extensions = [".ixx"]
flags = []
profile = "release"
target = "x86_64-linux-gnu"
sources = ["src/**/*.cpp"]
static_stdlib = false
std-module = "gen/std.cppm"
std-compat-module = "gen/std.compat.cppm"
std-module-flags = ["-D_GNU_SOURCE"]
)";
auto m = mcpp::manifest::parse_string(src);
ASSERT_TRUE(m.has_value()) << m.error().format();
std::string all;
for (auto const& w : m->schemaWarnings) { all += w; all += '\n'; }
EXPECT_TRUE(m->schemaWarnings.empty())
<< "a key the parser reads was reported as unsupported:\n" << all;
// The three that were absent, asserted individually so a regression names
// itself rather than arriving as "some warning appeared".
EXPECT_EQ(m->stdModule, "gen/std.cppm");
EXPECT_EQ(m->stdCompatModule, "gen/std.compat.cppm");
ASSERT_EQ(m->buildConfig.stdModuleFlags.size(), 1u);
EXPECT_EQ(m->buildConfig.stdModuleFlags[0], "-D_GNU_SOURCE");
}
// The negative control. Without it the test above passes against a parser whose
// unknown-key check has been deleted outright, which is the failure mode a
// "no warnings" assertion invites.
TEST(Manifest, AnUnknownBuildKeyIsStillReported) {
constexpr auto src = R"(
[package]
name = "x"
version = "0.1.0"
[build]
std_module = "gen/std.cppm"
)";
auto m = mcpp::manifest::parse_string(src);
ASSERT_TRUE(m.has_value()) << m.error().format();
ASSERT_EQ(m->schemaWarnings.size(), 1u);
// The underscore spelling is the plausible typo for the hyphenated key, so
// it is the one worth holding: accepting it silently is how `schedule` got
// in while `bmi_schedule` was being reported as unsupported.
EXPECT_NE(m->schemaWarnings[0].find("std_module"), std::string::npos)
<< m->schemaWarnings[0];
// The message must carry the SAME list the check uses — it used to be a
// third hand-written copy and had drifted from both others.
EXPECT_NE(m->schemaWarnings[0].find("std-module"), std::string::npos)
<< "the message must name the supported keys it actually checks against";
}
// `kKnownConditionalBuildKeys`' own comment says its vocabulary "is exactly
// that struct's members" and "MUST stay in sync with the reads above and with
// types.cppm's BuildInputs". It was two members short of that claim, and one of
// the two — `private_include_dirs` — is ACCEPTED by the xpkg descriptor's
// `target_cfg` block, the other grammar for this same axis. So one spelling of
// a conditional private include directory worked and the other reported the
// key as unsupported.
TEST(Manifest, EveryConditionalBuildKeyTheAxisCarriesIsAccepted) {
constexpr auto src = R"(
[package]
name = "x"
version = "0.1.0"
[target.'cfg(linux)'.build]
cflags = ["-Wall"]
cxxflags = ["-Wall"]
defines = ["A=1"]
include_dirs = ["include"]
include_dirs_after = ["compat"]
ldflags = ["-Wl,--as-needed"]
private_include_dirs = ["internal"]
sources = ["src/extra.cpp"]
std-module-flags = ["-D_GNU_SOURCE"]
)";
auto m = mcpp::manifest::parse_string(src);
ASSERT_TRUE(m.has_value()) << m.error().format();
std::string all;
for (auto const& w : m->schemaWarnings) { all += w; all += '\n'; }
EXPECT_TRUE(m->schemaWarnings.empty())
<< "a BuildInputs member the axis carries was reported unsupported:\n" << all;
ASSERT_EQ(m->conditionalConfigs.size(), 1u);
auto const& in = m->conditionalConfigs[0].inputs;
// #494 moved `std-module-flags` onto BuildInputs specifically so this axis
// could carry it — "membership here is what makes the cfg axis carry it",
// with -D_GNU_SOURCE right for musl and glibc and wrong for picolibc as the
// stated case. The member and the merge landed; the READ did not.
ASSERT_EQ(in.stdModuleFlags.size(), 1u);
EXPECT_EQ(in.stdModuleFlags[0], "-D_GNU_SOURCE");
ASSERT_EQ(in.privateIncludeDirs.size(), 1u);
EXPECT_EQ(in.privateIncludeDirs[0].generic_string(), "internal");
}
TEST(Manifest, AnUnknownConditionalBuildKeyIsStillReported) {
constexpr auto src = R"(
[package]
name = "x"
version = "0.1.0"
[target.'cfg(linux)'.build]
static_stdlib = true
)";
auto m = mcpp::manifest::parse_string(src);
ASSERT_TRUE(m.has_value()) << m.error().format();
ASSERT_EQ(m->schemaWarnings.size(), 1u);
EXPECT_NE(m->schemaWarnings[0].find("static_stdlib"), std::string::npos)
<< m->schemaWarnings[0];
// Built from the list, not written beside it: the prose form named eight
// keys and was two behind the check it was describing.
EXPECT_NE(m->schemaWarnings[0].find("std-module-flags"), std::string::npos)
<< "the message must be generated from the same list the check uses";
}
// #540: `[features]` was the one structured section with no schema check at
// all, so a misplaced `include_dirs` inside a feature built successfully with
// zero diagnostics — while the identical misplacement in `[build]` or
// `[target.<pred>.build]` is reported.
TEST(Manifest, EveryFeatureKeyTheParserReadsIsAccepted) {
constexpr auto src = R"(
[package]
name = "x"
version = "0.1.0"
[features]
full = { implies = ["fast"], forward = ["dep/feat"], defines = ["WITH_FULL"], sources = ["src/full.cpp"], requires = ["cap"], provides = ["cap2"], flags = [] }
fast = []
)";
auto m = mcpp::manifest::parse_string(src);
ASSERT_TRUE(m.has_value()) << m.error().format();
std::string all;
for (auto const& w : m->schemaWarnings) { all += w; all += '\n'; }
EXPECT_TRUE(m->schemaWarnings.empty())
<< "a feature key the parser reads was reported as unsupported:\n" << all;
}
TEST(Manifest, AnUnknownFeatureKeyIsReported) {
constexpr auto src = R"(
[package]
name = "x"
version = "0.1.0"
[features]
fast = { implies = [], include_dirs = ["nope"] }
)";
auto m = mcpp::manifest::parse_string(src);
ASSERT_TRUE(m.has_value()) << m.error().format();
ASSERT_EQ(m->schemaWarnings.size(), 1u);
EXPECT_NE(m->schemaWarnings[0].find("include_dirs"), std::string::npos)
<< m->schemaWarnings[0];
EXPECT_NE(m->schemaWarnings[0].find("fast"), std::string::npos)
<< "the message must name WHICH feature carries the key";
}
// `deps` is reserved rather than wrong — the parser's own comment has promised
// it since Feature System v2 — so it is reported as reserved. Saying
// "unsupported" would deny a documented plan; saying nothing is what let it
// look implemented.
TEST(Manifest, AReservedFeatureKeySaysItIsReserved) {
constexpr auto src = R"(
[package]
name = "x"
version = "0.1.0"
[features]
fast = { implies = [], deps = ["zlib"] }
)";
auto m = mcpp::manifest::parse_string(src);
ASSERT_TRUE(m.has_value()) << m.error().format();
ASSERT_EQ(m->schemaWarnings.size(), 1u);
EXPECT_NE(m->schemaWarnings[0].find("reserved"), std::string::npos)
<< m->schemaWarnings[0];
}
// #296: `defines` is a BuildInputs member, NOT a BuildConfig-only field — so
// the cfg axis carries it like any other build input. This is the regression
// that matters: a platform-only macro must be expressible, because a key that
// parses unconditionally but vanishes under `[target.'cfg(...)'.build]` is the
// exact silent-drop failure #296 was filed for, just one section over.
TEST(Manifest, ConditionalBuildDefinesAreCarriedByTheCfgAxis) {
constexpr auto src = R"(
[package]
name = "x"
version = "0.1.0"
[build]
defines = ["BASE"]
[target.'cfg(windows)'.build]
defines = ["USE_WIN32", "WINVER=0x0A00"]
)";
auto m = mcpp::manifest::parse_string(src);
ASSERT_TRUE(m.has_value()) << m.error().format();
ASSERT_EQ(m->conditionalConfigs.size(), 1u);
EXPECT_EQ(m->conditionalConfigs[0].predicate, "cfg(windows)");
ASSERT_EQ(m->conditionalConfigs[0].inputs.defines.size(), 2u);
EXPECT_EQ(m->conditionalConfigs[0].inputs.defines[0], "USE_WIN32");
EXPECT_EQ(m->conditionalConfigs[0].inputs.defines[1], "WINVER=0x0A00");
EXPECT_TRUE(m->schemaWarnings.empty())
<< (m->schemaWarnings.empty() ? "" : m->schemaWarnings[0]);
}
// A conditional section carrying ONLY `defines` must still be recorded — the
// emptiness gate that decides whether to push a ConditionalConfig has to know
// about every BuildInputs member, or the section is dropped before it is ever
// evaluated.
TEST(Manifest, ConditionalSectionWithOnlyDefinesIsRecorded) {
constexpr auto src = R"(
[package]
name = "x"
version = "0.1.0"
[target.'cfg(linux)'.build]
defines = ["ONLY_DEFINE"]
)";
auto m = mcpp::manifest::parse_string(src);
ASSERT_TRUE(m.has_value()) << m.error().format();
ASSERT_EQ(m->conditionalConfigs.size(), 1u);
ASSERT_EQ(m->conditionalConfigs[0].inputs.defines.size(), 1u);
EXPECT_EQ(m->conditionalConfigs[0].inputs.defines[0], "ONLY_DEFINE");
}
// The single additive merge must carry `defines` too — merge_conditional_
// build_inputs routes the cfg axis through append(), so a member missing here
// is a member that silently never reaches the build.
TEST(Manifest, AppendBuildInputsMergesDefines) {
mcpp::manifest::BuildInputs dst, src;
dst.defines = {"BASE"};
src.defines = {"COND"};
mcpp::manifest::append(dst, src);
ASSERT_EQ(dst.defines.size(), 2u);
EXPECT_EQ(dst.defines[0], "BASE");
// Conditional entries land AFTER the base ones so GNU last-wins gives the
// conditional rule precedence (an off-OS `-U` after the base `-D`).
EXPECT_EQ(dst.defines[1], "COND");
}
// #296 root cause: an unknown [build] key used to vanish without a word, and
// the build then failed much later with a module-graph divergence naming
// neither the key nor the manifest. Same policy as [targets.<name>]: a schema
// warning (an error under --strict).
TEST(Manifest, UnknownBuildKeyIsReportedNotSilentlyDropped) {
constexpr auto src = R"(
[package]
name = "x"
version = "0.1.0"
[build]
cxxflags = ["-Wall"]
defnes = ["TYPO"]
)";
auto m = mcpp::manifest::parse_string(src);
ASSERT_TRUE(m.has_value()) << m.error().format();
ASSERT_EQ(m->schemaWarnings.size(), 1u);
EXPECT_NE(m->schemaWarnings[0].find("defnes"), std::string::npos)
<< m->schemaWarnings[0];
EXPECT_NE(m->schemaWarnings[0].find("[build]"), std::string::npos)
<< m->schemaWarnings[0];
// The key is still ignored — this is a warning, not a parse failure.
EXPECT_EQ(m->buildConfig.cxxflags.size(), 1u);
}
// The conditional axis may only contribute build INPUTS, so a selection knob
// under it is inexpressible by construction. Say so rather than dropping it.
TEST(Manifest, UnknownConditionalBuildKeyIsReported) {
constexpr auto src = R"(
[package]
name = "x"
version = "0.1.0"
[target.'cfg(windows)'.build]
cxxflags = ["-DOK"]
static_stdlib = false
)";
auto m = mcpp::manifest::parse_string(src);
ASSERT_TRUE(m.has_value()) << m.error().format();
ASSERT_EQ(m->schemaWarnings.size(), 1u);
EXPECT_NE(m->schemaWarnings[0].find("static_stdlib"), std::string::npos)
<< m->schemaWarnings[0];
EXPECT_NE(m->schemaWarnings[0].find("cfg(windows)"), std::string::npos)
<< m->schemaWarnings[0];
}
// Every key the [build] parser actually reads must be absent from the
// unknown-key warning — a guard that fires on a supported key is worse than
// no guard, because --strict turns it into a build failure.
TEST(Manifest, EverySupportedBuildKeyPassesTheUnknownKeyGuard) {
constexpr auto src = R"(
[package]
name = "x"
version = "0.1.0"
[build]
sources = ["src/**/*.cpp"]
cflags = ["-O2"]
cxxflags = ["-Wall"]
ldflags = ["-lm"]
defines = ["A"]
flags = [{ glob = "src/*.c", defines = ["B"] }]
include_dirs = ["include"]
include_dirs_after = ["vendor"]
dialect_cxxflags = ["-fcontracts"]
c_standard = "c11"
target = "x86_64-linux-musl"
static_stdlib = true
allow_host_libs = false
profile = "dev"
macos_deployment_target = "14.0"
)";
auto m = mcpp::manifest::parse_string(src);
ASSERT_TRUE(m.has_value()) << m.error().format();
EXPECT_TRUE(m->schemaWarnings.empty())
<< (m->schemaWarnings.empty() ? "" : m->schemaWarnings[0]);
}
// `default-profile` is the canonical spelling of the `profile` alias; both
// must clear the guard.
TEST(Manifest, BuildDefaultProfileSpellingPassesTheUnknownKeyGuard) {
constexpr auto src = R"(
[package]
name = "x"
version = "0.1.0"
[build]
default-profile = "dev"
)";
auto m = mcpp::manifest::parse_string(src);
ASSERT_TRUE(m.has_value()) << m.error().format();
EXPECT_EQ(m->buildConfig.defaultProfile, "dev");
EXPECT_TRUE(m->schemaWarnings.empty())
<< (m->schemaWarnings.empty() ? "" : m->schemaWarnings[0]);
}
// #249: `[build] include_dirs_after` parses into buildConfig.includeDirsAfter
// — the -idirafter channel (searched AFTER the toolchain's system dirs), so
// an extracted-tarball root containing a file named like a standard header
// (ffmpeg's VERSION vs libc++'s <version> on case-insensitive macOS) can't
// shadow it while its real headers stay findable.
TEST(Manifest, BuildIncludeDirsAfterToml) {
constexpr auto src = R"(
[package]
name = "x"
version = "0.1.0"
[build]
sources = ["src/**/*.cpp"]
include_dirs = ["include"]
include_dirs_after = ["*", "vendor/include"]
[targets.x]
kind = "lib"
)";
auto m = mcpp::manifest::parse_string(src);
ASSERT_TRUE(m.has_value()) << m.error().format();
ASSERT_EQ(m->buildConfig.includeDirs.size(), 1u);
EXPECT_EQ(m->buildConfig.includeDirs[0], "include");
ASSERT_EQ(m->buildConfig.includeDirsAfter.size(), 2u);
EXPECT_EQ(m->buildConfig.includeDirsAfter[0], "*");
EXPECT_EQ(m->buildConfig.includeDirsAfter[1], "vendor/include");
}
// Feature System v2 Stage 1: a [features] entry may be a TABLE carrying
// package-owned `defines` (and `implies`), while the array shorthand keeps
// meaning "implied features". See
// .agents/docs/2026-06-29-feature-capability-model-design.md.
TEST(Manifest, FeatureTableFormDefinesAndImplies) {
constexpr auto src = R"(
[package]
name = "x"
version = "0.1.0"
[targets.x]
kind = "lib"
[features]
default = ["base"]
base = []
accel = { defines = ["APP_ACCEL=1", "APP_FAST"], implies = ["base"] }
)";
auto m = mcpp::manifest::parse_string(src);
ASSERT_TRUE(m.has_value()) << m.error().format();
// Array shorthand still registers an implied-feature list.
ASSERT_TRUE(m->featuresMap.contains("default"));
ASSERT_EQ(m->featuresMap["default"].size(), 1u);
EXPECT_EQ(m->featuresMap["default"][0], "base");
// Table form: `implies` flows into featuresMap, `defines` into featureDefines.
ASSERT_TRUE(m->featuresMap.contains("accel"));
ASSERT_EQ(m->featuresMap["accel"].size(), 1u);
EXPECT_EQ(m->featuresMap["accel"][0], "base");
ASSERT_TRUE(m->buildConfig.featureDefines.contains("accel"));
ASSERT_EQ(m->buildConfig.featureDefines["accel"].size(), 2u);
EXPECT_EQ(m->buildConfig.featureDefines["accel"][0], "APP_ACCEL=1");