@@ -158,4 +158,67 @@ grep -q "override" b5.log || { cat b5.log; echo "FAIL: the override was not repo
158158out=" $( " $MCPP " run 2>&1 | grep ' ^ANSWER=' | tail -1) "
159159[[ " $out " == " ANSWER=7" ]] || { echo " FAIL: the override was not actually used: $out " ; exit 1; }
160160
161+ # ── a NAMESPACED package is addressable by both spellings ──────────────────
162+ # `toolpkg` above has no namespace, so its canonical and short names are the
163+ # same string and only one env var is emitted — the two-spelling path is never
164+ # exercised. A consumer may write either `myns.tp` or `tp`, exactly as
165+ # mcpp::dep_dir() accepts both, and the tool lookup has to match.
166+ cd " $TMP "
167+ mkdir -p ns/src
168+ cat > ns/mcpp.toml << 'EOF '
169+ [package]
170+ name = "myns.tp"
171+ version = "0.1.0"
172+
173+ [build]
174+ sources = ["src/lib.cpp"]
175+
176+ [targets.gen]
177+ kind = "bin"
178+ main = "src/gen.cpp"
179+ EOF
180+ printf ' int tp_lib(){return 1;}\n' > ns/src/lib.cpp
181+ cat > ns/src/gen.cpp << 'EOF '
182+ #include <cstdio>
183+ int main(int c, char** v) {
184+ if (c < 2) return 2;
185+ FILE* f = std::fopen(v[1], "w");
186+ if (!f) return 3;
187+ std::fprintf(f, "int gv() { return 5; }\n");
188+ std::fclose(f);
189+ return 0;
190+ }
191+ EOF
192+ mkdir -p nsapp/src
193+ cat > nsapp/mcpp.toml << 'EOF '
194+ [package]
195+ name = "nsapp"
196+ version = "0.1.0"
197+
198+ [dependencies]
199+ "myns.tp" = { path = "../ns", tools = ["gen"] }
200+ EOF
201+ printf ' #include <cstdio>\nint gv();\nint main(){std::printf("G=%%d\\n",gv());}\n' > nsapp/src/main.cpp
202+ cat > nsapp/build.mcpp << 'EOF '
203+ #include <cstdio>
204+ #include <cstdlib>
205+ #include <string>
206+ import mcpp;
207+ int main() {
208+ // BOTH spellings must resolve to the same tool.
209+ const char* full = mcpp::dep_bin("myns.tp", "gen");
210+ const char* brief = mcpp::dep_bin("tp", "gen");
211+ if (!*full) { std::fprintf(stderr, "canonical spelling did not resolve\n"); return 1; }
212+ if (!*brief) { std::fprintf(stderr, "short spelling did not resolve\n"); return 1; }
213+ std::string out = std::string(mcpp::out_dir()) + "/g.cpp";
214+ std::string cmd = std::string("\"") + brief + "\" \"" + out + "\"";
215+ if (std::system(cmd.c_str()) != 0) return 1;
216+ mcpp::generated(out.c_str());
217+ }
218+ EOF
219+ cd nsapp
220+ " $MCPP " build > b6.log 2>&1 || { cat b6.log; echo " FAIL: namespaced tool lookup failed" ; exit 1; }
221+ out=" $( " $MCPP " run 2>&1 | grep ' ^G=' | tail -1) "
222+ [[ " $out " == " G=5" ]] || { echo " FAIL: namespaced tool did not generate: $out " ; exit 1; }
223+
161224echo " OK"
0 commit comments