Skip to content

Commit 49bbd2d

Browse files
committed
test(cli): lock C-generator entry/hoist/unknown-call sync
cli_c_backend_syncs_entry_hoist_and_unknown_calls compiles a program via the default C backend and asserts its native output matches xb --run: exercises the entry-point fallback (Entry, no Main), auto-vivified scalar hoisting (i/total), and unknown-callee stubbing (statement no-op + expression 0). Durable cargo-test lock for three of the five cgen sync fixes (dedup + computed-GOTO remain covered by the demo differential). Full suite 182/0.
1 parent 5cde1ce commit 49bbd2d

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

crates/xb-cli/tests/cli.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,49 @@ fn cli_compile_produces_native_executable() {
126126
let _ = std::fs::remove_file(&exe);
127127
}
128128

129+
#[test]
130+
fn cli_c_backend_syncs_entry_hoist_and_unknown_calls() {
131+
// Locks three C-generator sync fixes together (each a no-op on the self-host /
132+
// v0.1 corpus): the entry point runs the first function when there is no `Main`
133+
// (legacy `Entry`); auto-vivified scalars (`i`, `total`) are hoisted and declared;
134+
// and an unknown callee is stubbed to the zero-default (statement = no-op,
135+
// expression = 0) — matching `xb --run`. Output: total 1+2+3 = 6, then the stubbed
136+
// `XstUnknownVal` call = 0.
137+
let src = "VERSION \"0.1\"\n\
138+
FUNCTION Entry ()\n\
139+
FOR i = 1 TO 3\n\
140+
total = total + i\n\
141+
NEXT i\n\
142+
PRINT total\n\
143+
XstUnknownProc (total)\n\
144+
PRINT XstUnknownVal (total)\n\
145+
END FUNCTION\n";
146+
let tmp = std::env::temp_dir().join("xb_cli_cgen_sync");
147+
let _ = std::fs::create_dir_all(&tmp);
148+
let srcp = tmp.join("sync.x");
149+
std::fs::write(&srcp, src).unwrap();
150+
let exe = tmp.join("sync_exe");
151+
let _ = std::fs::remove_file(&exe);
152+
let output = Command::new(env!("CARGO_BIN_EXE_xb"))
153+
.args([
154+
"--compile",
155+
srcp.to_str().unwrap(),
156+
"-o",
157+
exe.to_str().unwrap(),
158+
])
159+
.output()
160+
.unwrap();
161+
assert!(
162+
output.status.success(),
163+
"compile stderr: {}",
164+
String::from_utf8_lossy(&output.stderr)
165+
);
166+
let run = Command::new(&exe).output().unwrap();
167+
assert_eq!(String::from_utf8(run.stdout).unwrap(), "6\n0\n");
168+
let _ = std::fs::remove_file(&exe);
169+
let _ = std::fs::remove_file(&srcp);
170+
}
171+
129172
#[cfg(feature = "llvm")]
130173
#[test]
131174
fn cli_compile_llvm_backend_produces_native_executable() {

0 commit comments

Comments
 (0)