Skip to content

Commit 2344269

Browse files
committed
test(e2e 328): 补上依赖那一条腿 —— 它才是这个特性的动机
自审读出:328 此前每一条断言都能被一个只给 packages[0] 打补丁的实现满足。而 docs/14 是为「供给某一层、并支持其下方多个实现的包」写的这个特性 —— 那是一个**库**, 以别人的依赖身份被走到。与本 pass 共用同一段窗口的 build.mcpp tail 只打补丁给根包 (对它自己的用途是对的),照抄那个形状会让这个特性唯一存在的对象没被服务,而所有 只看根包的断言照样全绿。 新增的这条带否定对照:依赖里不匹配的那一段必须不生效。
1 parent 9bfe0d7 commit 2344269

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

‎tests/e2e/328_layer_predicates_apply_and_unknown_ones_say_so.sh‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,53 @@ n=$(grep -o '\-DPROBE_ONCE=1' once/compile_commands.json | wc -l | tr -d ' ')
106106
exit 1; }
107107
echo " ok a predicate naming both a triple key and a layer applies exactly once"
108108

109+
# ── (2b) …and it reaches a DEPENDENCY, which is the motivating case ─────────
110+
#
111+
# ⚠️ EVERY LEG ABOVE IS SATISFIED BY A PASS THAT ONLY PATCHES packages[0].
112+
# docs/14 writes this feature for "a package supplying a layer [that] frequently
113+
# supports several implementations of the layer beneath it" — a LIBRARY, reached
114+
# as someone's dependency. The build.mcpp tail that shares this pass's window
115+
# patches the root alone, correctly for its own purpose, so copying that shape
116+
# would have left the one package this feature exists for unserved and every
117+
# root-only assertion still green.
118+
mkdir -p dep/app/src dep/lib/src
119+
cat > dep/lib/mcpp.toml <<EOF
120+
[package]
121+
name = "layerlib"
122+
version = "0.1.0"
123+
124+
[target.'cfg(c-abi = "$CABI")'.build]
125+
defines = ["LIB_MATCHED=1"]
126+
127+
[target.'cfg(c-abi = "$NOTCABI")'.build]
128+
defines = ["LIB_MUST_NOT_APPLY=1"]
129+
EOF
130+
cat > dep/lib/src/layerlib.cppm <<'EOF'
131+
export module layerlib;
132+
#ifndef LIB_MATCHED
133+
#error "a DEPENDENCY's matching cfg(c-abi = ...) section did not apply"
134+
#endif
135+
#ifdef LIB_MUST_NOT_APPLY
136+
#error "a DEPENDENCY's non-matching cfg(c-abi = ...) section applied"
137+
#endif
138+
export int lib_answer() { return 42; }
139+
EOF
140+
cat > dep/app/mcpp.toml <<'EOF'
141+
[package]
142+
name = "app"
143+
version = "0.1.0"
144+
145+
[dependencies]
146+
layerlib = { path = "../lib" }
147+
EOF
148+
cat > dep/app/src/main.cpp <<'EOF'
149+
import layerlib;
150+
int main() { return lib_answer() == 42 ? 0 : 1; }
151+
EOF
152+
( cd dep/app && "$MCPP" build > b.log 2>&1 ) || {
153+
cat dep/app/b.log; echo "FAIL: layer predicates did not reach a dependency"; exit 1; }
154+
echo " ok a layer predicate reaches a dependency, and its negative leg holds"
155+
109156
# ── (3) an unknown key is reported, and --strict makes it an error ──────────
110157
mkdir -p unknown/src
111158
cat > unknown/mcpp.toml <<'EOF'

0 commit comments

Comments
 (0)