Skip to content

Commit 3d7c984

Browse files
committed
test(e2e): c++fly hard/soft paths + c++latest spelling regression
1 parent ee88c32 commit 3d7c984

2 files changed

Lines changed: 229 additions & 0 deletions

File tree

tests/e2e/100_cppfly_reflection.sh

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
#!/usr/bin/env bash
2+
# requires: gcc
3+
# 100_cppfly_reflection.sh — standard = "c++fly" (design 2026-07-14): ONE
4+
# manifest line gives the toolchain's latest -std= level + every experimental
5+
# gate it supports. On gcc >= 16 that means -std=c++26 -freflection with zero
6+
# hand-written flags, reaching every TU, the scan and the std BMI prebuild.
7+
# Tail section: standard = "c++latest" regression — it used to reach the GNU
8+
# driver as the invalid spelling -std=c++latest (design §11-Q5).
9+
set -e
10+
11+
TMP=$(mktemp -d)
12+
trap "rm -rf $TMP" EXIT
13+
14+
# Capability probe (mirrors 98): newest gcc payload must accept -freflection.
15+
USER_MCPP="${MCPP_HOME:-$HOME/.mcpp}"
16+
GXX=$(find "$USER_MCPP/registry/data/xpkgs/xim-x-gcc" -name "g++" -path "*/bin/*" 2>/dev/null | sort | tail -1)
17+
if [[ -z "$GXX" ]] || ! echo 'int main(){}' | "$GXX" -freflection -std=c++26 -x c++ - -fsyntax-only -o /dev/null 2>/dev/null; then
18+
echo "SKIP-INLINE: no -freflection-capable gcc payload available"
19+
exit 0
20+
fi
21+
GCC_VER=$(basename "$(dirname "$(dirname "$GXX")")")
22+
23+
export MCPP_HOME="$TMP/mcpp-home"
24+
source "$(dirname "$0")/_inherit_toolchain.sh"
25+
26+
mkdir -p "$TMP/proj/src"
27+
cd "$TMP/proj"
28+
29+
cat > mcpp.toml <<EOF
30+
[package]
31+
name = "flydemo"
32+
version = "0.1.0"
33+
standard = "c++fly"
34+
35+
[toolchain]
36+
default = "gcc@${GCC_VER}"
37+
EOF
38+
39+
cat > src/main.cpp <<'EOF'
40+
import std;
41+
42+
void print_struct(auto &&value) {
43+
constexpr auto info = std::meta::remove_cvref(^^decltype(value));
44+
constexpr auto no_check = std::meta::access_context::unchecked();
45+
static constexpr auto members = std::define_static_array(
46+
std::meta::nonstatic_data_members_of(info, no_check));
47+
template for (constexpr auto e : members) {
48+
auto &&member = value.[:e:];
49+
std::println("{} {}", identifier_of(e), member);
50+
}
51+
}
52+
53+
struct Point { double x{}; double y{}; };
54+
int main() {
55+
print_struct(Point{2, 3});
56+
}
57+
EOF
58+
59+
"$MCPP" build --no-cache > "$TMP/build.log" 2>&1 || {
60+
cat "$TMP/build.log"
61+
echo "FAIL: c++fly build failed"
62+
exit 1
63+
}
64+
65+
# The c++fly summary: the value's contract is saying what was enabled/skipped.
66+
grep -q 'c++fly on gcc' "$TMP/build.log" || {
67+
cat "$TMP/build.log"
68+
echo "FAIL: build log missing c++fly summary line"
69+
exit 1
70+
}
71+
grep -q 'reflection (-freflection)' "$TMP/build.log" || {
72+
cat "$TMP/build.log"
73+
echo "FAIL: summary missing enabled reflection gate"
74+
exit 1
75+
}
76+
grep -q 'enabled: .*contracts' "$TMP/build.log" || {
77+
cat "$TMP/build.log"
78+
echo "FAIL: summary missing enabled contracts (on by -std=c++26 on gcc16)"
79+
exit 1
80+
}
81+
82+
# Latest level + gate flags reach the global cxxflags (every TU, deps incl.).
83+
build_ninja="$(find target -name build.ninja | head -1)"
84+
grep -qE '^cxxflags = -std=c\+\+26 -freflection' "$build_ninja" || {
85+
grep '^cxxflags' "$build_ninja" || true
86+
echo "FAIL: build.ninja cxxflags lacks -std=c++26 -freflection"
87+
exit 1
88+
}
89+
if grep -q -- '-std=c++fly' "$build_ninja" compile_commands.json; then
90+
echo "FAIL: raw c++fly canonical leaked into a command line"
91+
exit 1
92+
fi
93+
grep -q '"-freflection"' compile_commands.json || {
94+
echo "FAIL: compile_commands.json missing -freflection"
95+
exit 1
96+
}
97+
98+
# Reflection actually works at runtime (std::meta over struct members).
99+
binary=$(find target -type f -path '*/bin/flydemo' | head -1)
100+
out=$("$binary")
101+
[[ "$out" == *"x 2"* && "$out" == *"y 3"* ]] || {
102+
echo "FAIL: reflection output: $out"
103+
exit 1
104+
}
105+
106+
# The std BMI prebuild carries the same dialect (scan/prebuild/compile agree).
107+
metadata="$(find "$MCPP_HOME/bmi" -name std-module.json | head -1)"
108+
grep -q '"std_flag": "-std=c++26 -freflection' "$metadata" || {
109+
cat "$metadata"
110+
echo "FAIL: std-module.json std_flag lacks -std=c++26 -freflection"
111+
exit 1
112+
}
113+
114+
# ── c++latest regression (design §11-Q5) ────────────────────────────────
115+
# Used to emit the invalid GNU spelling -std=c++latest; must now resolve to
116+
# the family latest level.
117+
mkdir -p "$TMP/latest/src"
118+
cd "$TMP/latest"
119+
cat > mcpp.toml <<EOF
120+
[package]
121+
name = "latestdemo"
122+
version = "0.1.0"
123+
standard = "c++latest"
124+
125+
[toolchain]
126+
default = "gcc@${GCC_VER}"
127+
EOF
128+
cat > src/main.cpp <<'EOF'
129+
import std;
130+
int main() { std::println("latest ok"); }
131+
EOF
132+
133+
"$MCPP" build --no-cache > "$TMP/latest-build.log" 2>&1 || {
134+
cat "$TMP/latest-build.log"
135+
echo "FAIL: c++latest build failed"
136+
exit 1
137+
}
138+
latest_ninja="$(find target -name build.ninja | head -1)"
139+
grep -qE '^cxxflags = -std=c\+\+26' "$latest_ninja" || {
140+
grep '^cxxflags' "$latest_ninja" || true
141+
echo "FAIL: c++latest did not resolve to -std=c++26"
142+
exit 1
143+
}
144+
if grep -q -- '-std=c++latest' "$latest_ninja" compile_commands.json; then
145+
echo "FAIL: invalid -std=c++latest spelling reached a command line"
146+
exit 1
147+
fi
148+
149+
echo "PASS: c++fly = latest std + experimental gates; c++latest spelling fixed"

tests/e2e/101_cppfly_llvm_soft.sh

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/usr/bin/env bash
2+
# 101_cppfly_llvm_soft.sh — standard = "c++fly" soft path on Clang (design
3+
# §5.4): upstream Clang has no reflection/contracts, so the build must still
4+
# succeed at the family's latest level (-std=c++2c), with the skipped gates
5+
# reported in the summary — mcpp diagnostics instead of raw compiler errors.
6+
set -e
7+
8+
TMP=$(mktemp -d)
9+
trap "rm -rf $TMP" EXIT
10+
11+
source "$(dirname "$0")/_llvm_env.sh"
12+
if [[ ! -d "$LLVM_ROOT" ]]; then
13+
echo "SKIP: xlings llvm@${LLVM_VERSION:-none} is not installed"
14+
exit 0
15+
fi
16+
17+
export MCPP_HOME="$TMP/mcpp-home"
18+
source "$(dirname "$0")/_inherit_toolchain.sh"
19+
20+
mkdir -p "$TMP/proj/src"
21+
cd "$TMP/proj"
22+
23+
cat > mcpp.toml <<EOF
24+
[package]
25+
name = "flysoft"
26+
version = "0.1.0"
27+
standard = "c++fly"
28+
29+
[toolchain]
30+
default = "llvm@${LLVM_VERSION}"
31+
EOF
32+
33+
cat > src/main.cpp <<'EOF'
34+
import std;
35+
int main() { std::println("fly soft ok"); }
36+
EOF
37+
38+
"$MCPP" build --no-cache > "$TMP/build.log" 2>&1 || {
39+
cat "$TMP/build.log"
40+
echo "FAIL: c++fly soft-path build failed on llvm"
41+
exit 1
42+
}
43+
44+
grep -q 'c++fly on clang' "$TMP/build.log" || {
45+
cat "$TMP/build.log"
46+
echo "FAIL: build log missing c++fly summary line"
47+
exit 1
48+
}
49+
grep -q 'skipped: .*reflection' "$TMP/build.log" || {
50+
cat "$TMP/build.log"
51+
echo "FAIL: summary does not report reflection as skipped on clang"
52+
exit 1
53+
}
54+
55+
build_ninja="$(find target -name build.ninja | head -1)"
56+
grep -qE '^cxxflags = -std=c\+\+2c' "$build_ninja" || {
57+
grep '^cxxflags' "$build_ninja" || true
58+
echo "FAIL: clang c++fly did not resolve to -std=c++2c"
59+
exit 1
60+
}
61+
62+
# xim llvm payloads use libc++ → the stdlib experimental gate applies.
63+
grep -q 'experimental-library (-fexperimental-library)' "$TMP/build.log" || {
64+
cat "$TMP/build.log"
65+
echo "FAIL: summary missing libc++ experimental-library gate"
66+
exit 1
67+
}
68+
grep -q -- '-fexperimental-library' "$build_ninja" || {
69+
echo "FAIL: build.ninja missing -fexperimental-library"
70+
exit 1
71+
}
72+
73+
binary=$(find target -type f -path '*/bin/flysoft' | head -1)
74+
out=$("$binary")
75+
[[ "$out" == "fly soft ok" ]] || {
76+
echo "FAIL: runtime output: $out"
77+
exit 1
78+
}
79+
80+
echo "PASS: c++fly soft path on clang — latest level + skipped summary"

0 commit comments

Comments
 (0)