11#! /usr/bin/env bash
22# requires:
3- # `mcpp add` modifies mcpp.toml [dependencies]. Dotted package selectors are
4- # preserved in the single table; `ns:name` remains the explicit namespace form.
3+ # `mcpp add` modifies mcpp.toml [dependencies]. Default-namespace packages land
4+ # as bare keys under [dependencies]; `ns:name` (non-default ns) uses a subtable.
5+ # Non-existent packages are rejected before mcpp.toml is mutated.
56set -e
67
78TMP=$( mktemp -d)
@@ -13,38 +14,26 @@ cd "$TMP"
1314" $MCPP " new myapp > /dev/null
1415cd myapp
1516
16- # (1) Default-namespace dep: bare name → unquoted key under [dependencies].
17- " $MCPP " add somedep@0.1.0 > /dev/null
17+ # (1) Default-namespace dep via `<ns>:<name>@<ver>` where ns is the default
18+ # (mcpplibs). Since 0.0.10+ default namespace is "mcpplibs", this lands as a
19+ # bare key under [dependencies], NOT in [dependencies.mcpplibs].
20+ " $MCPP " add mcpplibs:cmdline@0.0.1 > /dev/null
1821grep -qE ' ^\[dependencies\]' mcpp.toml || { cat mcpp.toml; echo " no [dependencies] section" ; exit 1; }
19- grep -qE ' ^somedep = "0\.1\.0 "$' mcpp.toml || { cat mcpp.toml; echo " somedep entry missing or quoted " ; exit 1; }
20- grep -qE ' ^"somedep "' mcpp.toml && { cat mcpp.toml; echo " default-ns key should not be quoted" ; exit 1; }
22+ grep -qE ' ^cmdline = "0\.0\.1 "$' mcpp.toml || { cat mcpp.toml; echo " cmdline entry missing or wrong version " ; exit 1; }
23+ grep -qE ' ^"cmdline "' mcpp.toml && { cat mcpp.toml; echo " default-ns key should not be quoted" ; exit 1; }
2124
2225# (2) Second default-ns dep — append, do not duplicate the section header.
23- " $MCPP " add another @0.2.0 > /dev/null
26+ " $MCPP " add mcpplibs:templates @0.0.1 > /dev/null
2427header_count=$( grep -cE ' ^\[dependencies\]$' mcpp.toml)
2528[[ " $header_count " == " 1" ]] || { cat mcpp.toml; echo " [dependencies] header duplicated" ; exit 1; }
26- grep -qE ' ^another = "0\.2\.0"$' mcpp.toml || { cat mcpp.toml; echo " another not set" ; exit 1; }
27-
28- # (3) Default-ns dep via `<ns>:<name>@<ver>` where ns is the default (mcpplibs).
29- # Since 0.0.10+ default namespace is "mcpplibs", this lands as a bare key
30- # under [dependencies], NOT in [dependencies.mcpplibs].
31- " $MCPP " add mcpplibs:cmdline@0.0.2 > /dev/null
32- grep -qE ' ^cmdline = "0\.0\.2"$' mcpp.toml || { cat mcpp.toml; echo " cmdline entry missing" ; exit 1; }
33-
34- # (4) A second default-ns package — also goes under [dependencies].
35- " $MCPP " add mcpplibs:templates@0.0.1 > /dev/null
36- grep -qE ' ^templates = "0\.0\.1"$' mcpp.toml || { cat mcpp.toml; echo " templates entry missing" ; exit 1; }
37-
38- # (5) Dotted selector input is preserved under the single [dependencies] table.
39- " $MCPP " add acme.util@2.0.0 > /dev/null
40- grep -qE ' ^acme\.util = "2\.0\.0"$' mcpp.toml || { cat mcpp.toml; echo " acme.util selector entry missing" ; exit 1; }
29+ grep -qE ' ^templates = "0\.0\.1"$' mcpp.toml || { cat mcpp.toml; echo " templates not set" ; exit 1; }
4130
42- # (6 ) Colon form remains explicit namespace syntax and uses a subtable.
31+ # (3 ) Colon form remains explicit namespace syntax and uses a subtable.
4332" $MCPP " add compat:gtest@1.15.2 > /dev/null
4433grep -qE ' ^\[dependencies\.compat\]$' mcpp.toml || { cat mcpp.toml; echo " missing [dependencies.compat] section" ; exit 1; }
4534grep -qE ' ^gtest = "1\.15\.2"$' mcpp.toml || { cat mcpp.toml; echo " gtest entry missing" ; exit 1; }
4635
47- # (7 ) Dotted remove can still clean the old subtable shape for compatibility.
36+ # (4 ) Dotted remove can still clean the old subtable shape for compatibility.
4837cat >> mcpp.toml << 'EOF '
4938
5039[dependencies.legacy]
5342" $MCPP " remove legacy.old > /dev/null
5443! grep -qE ' ^old = "0\.1\.0"$' mcpp.toml || { cat mcpp.toml; echo " legacy.old was not removed" ; exit 1; }
5544
56- # (8 ) Reject missing version.
45+ # (5 ) Reject missing version.
5746err=$( " $MCPP " add bareword 2>&1 ) && { echo " expected error for missing version" ; exit 1; }
5847[[ " $err " == * " version required" * ]] || { echo " wrong error: $err " ; exit 1; }
5948
60- # (9 ) Reject empty package name (e.g. `mcpp add :foo@1.0`).
49+ # (6 ) Reject empty package name (e.g. `mcpp add :foo@1.0`).
6150err=$( " $MCPP " add " :@1.0" 2>&1 ) && { echo " expected error for empty package name" ; exit 1; }
6251
52+ # (7) Reject non-existent package and do not mutate mcpp.toml.
53+ cp mcpp.toml mcpp.toml.before
54+ err=$( " $MCPP " add definitely-not-a-real-package@9.9.9 2>&1 ) && { echo " expected error for missing package" ; exit 1; }
55+ [[ " $err " == * " not found" * ]] || { echo " wrong error: $err " ; exit 1; }
56+ diff -q mcpp.toml.before mcpp.toml || { cat mcpp.toml; echo " mcpp.toml mutated for missing package" ; exit 1; }
57+
6358echo " OK"
0 commit comments