-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathtest_p1689.cpp
More file actions
149 lines (132 loc) · 3.77 KB
/
Copy pathtest_p1689.cpp
File metadata and controls
149 lines (132 loc) · 3.77 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
#include <gtest/gtest.h>
import std;
import mcpp.modgraph.p1689;
using namespace mcpp::modgraph::p1689;
namespace {
constexpr const char* kSimpleProvider = R"({
"rules": [
{
"primary-output": "/tmp/foo.o",
"provides": [
{
"logical-name": "foo",
"is-interface": true
}
],
"requires": [
{
"logical-name": "std"
}
,
{
"logical-name": "foo:impl"
}
]
}
],
"version": 0,
"revision": 0
}
)";
constexpr const char* kPureConsumer = R"({
"rules": [
{
"primary-output": "/tmp/main.o",
"provides": [],
"requires": [
{ "logical-name": "std" },
{ "logical-name": "myapp.lib" }
]
}
]
})";
constexpr const char* kEmptyRequires = R"({
"rules": [
{
"primary-output": "/tmp/lone.o",
"provides": [{"logical-name": "lone", "is-interface": true}],
"requires": []
}
]
})";
} // namespace
TEST(P1689Parse, SimpleProvider) {
auto r = parse_ddi(kSimpleProvider);
ASSERT_TRUE(r) << r.error();
EXPECT_EQ(r->primaryOutput, "/tmp/foo.o");
ASSERT_EQ(r->provides.size(), 1u);
EXPECT_EQ(r->provides[0].logicalName, "foo");
// Not EXPECT_TRUE: on an optional that only asserts "the key was present",
// which stays green when the value parses as false.
EXPECT_EQ(r->provides[0].isInterface, std::optional<bool>{true});
ASSERT_EQ(r->requires_.size(), 2u);
EXPECT_EQ(r->requires_[0], "std");
EXPECT_EQ(r->requires_[1], "foo:impl");
}
TEST(P1689Parse, PureConsumer) {
auto r = parse_ddi(kPureConsumer);
ASSERT_TRUE(r) << r.error();
EXPECT_TRUE(r->provides.empty());
ASSERT_EQ(r->requires_.size(), 2u);
EXPECT_EQ(r->requires_[0], "std");
EXPECT_EQ(r->requires_[1], "myapp.lib");
}
TEST(P1689Parse, EmptyRequires) {
auto r = parse_ddi(kEmptyRequires);
ASSERT_TRUE(r) << r.error();
ASSERT_EQ(r->provides.size(), 1u);
EXPECT_EQ(r->provides[0].logicalName, "lone");
EXPECT_TRUE(r->requires_.empty());
}
// ─── is-interface decides whether a source may be published ────────────────
//
// `export module M:api;` and `module M:impl;` differ only in the keyword, and
// `mcpp pack` publishes the interface closure's SOURCE. The compiler is the one
// participant here that actually parsed the declaration, so its answer — and
// its silence — both have to survive the trip.
constexpr const char* kImplementationPartition = R"({
"rules": [
{
"primary-output": "/tmp/secret.o",
"provides": [{"logical-name": "mathkit:secret", "is-interface": false}],
"requires": []
}
]
})";
constexpr const char* kNoIsInterfaceKey = R"({
"rules": [
{
"primary-output": "/tmp/quiet.o",
"provides": [{"logical-name": "mathkit:quiet"}],
"requires": []
}
]
})";
TEST(P1689Parse, ImplementationPartitionIsNotAnInterface) {
auto r = parse_ddi(kImplementationPartition);
ASSERT_TRUE(r) << r.error();
ASSERT_EQ(r->provides.size(), 1u);
EXPECT_EQ(r->provides[0].logicalName, "mathkit:secret");
EXPECT_EQ(r->provides[0].isInterface, std::optional<bool>{false});
}
TEST(P1689Parse, AnAbsentIsInterfaceKeyStaysAbsent) {
// P1689 makes the key optional, so absence has to reach the packer as
// "nobody said" rather than as either answer. It used to arrive as `false`
// by struct default — which is the same value as an explicit
// implementation partition, i.e. the two became indistinguishable.
auto r = parse_ddi(kNoIsInterfaceKey);
ASSERT_TRUE(r) << r.error();
ASSERT_EQ(r->provides.size(), 1u);
EXPECT_EQ(r->provides[0].logicalName, "mathkit:quiet");
EXPECT_FALSE(r->provides[0].isInterface.has_value());
}
TEST(P1689Parse, RejectsNonObject) {
auto r = parse_ddi("[]");
EXPECT_FALSE(r);
EXPECT_NE(r.error().find("top-level"), std::string::npos);
}
TEST(P1689Parse, RejectsMissingRules) {
auto r = parse_ddi(R"({"version": 0})");
EXPECT_FALSE(r);
EXPECT_NE(r.error().find("rules"), std::string::npos);
}