6e6b6a14fb
- Codegen: current_block-Tracking ersetzt die Heuristik im phi-Lowering; verschachtelte if-Ausdrücke produzieren jetzt korrekte LLVM IR. examples/max3.ail.json + Test schützt gegen Regression. - Strings: Lit::Str / Type Str / io/print_str Effekt-Op; Strings sind im MVP immutable Konstanten. examples/hello.ail.json als zweiter E2E-Test. - CLI: --json für manifest und builtins; neuer deps-Subcommand listet statische Symbol-Referenzen pro Definition. Effekt-Ops mit Prefix effect: markiert. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
59 lines
1.8 KiB
Rust
59 lines
1.8 KiB
Rust
//! End-to-End-Test: lade Beispielmodul, kompiliere zu Binary, führe es aus.
|
|
//!
|
|
//! Dieses Test schützt die wichtigste Eigenschaft der gesamten Pipeline:
|
|
//! AST → typecheck → LLVM IR → clang → Binary → korrekter stdout.
|
|
|
|
use std::path::Path;
|
|
use std::process::Command;
|
|
|
|
fn ail_bin() -> &'static str {
|
|
env!("CARGO_BIN_EXE_ail")
|
|
}
|
|
|
|
fn build_and_run(example: &str) -> String {
|
|
// Workspace-Root liegt zwei Ebenen über dem Crate-Manifest.
|
|
let manifest_dir = env!("CARGO_MANIFEST_DIR");
|
|
let workspace = Path::new(manifest_dir).parent().unwrap().parent().unwrap();
|
|
let src = workspace.join("examples").join(example);
|
|
let tmp = std::env::temp_dir().join(format!(
|
|
"ailang_e2e_{}_{}",
|
|
example.replace('.', "_"),
|
|
std::process::id()
|
|
));
|
|
std::fs::create_dir_all(&tmp).unwrap();
|
|
let out = tmp.join("bin");
|
|
let status = Command::new(ail_bin())
|
|
.args(["build", src.to_str().unwrap(), "-o"])
|
|
.arg(&out)
|
|
.status()
|
|
.expect("ail build failed to run");
|
|
assert!(status.success(), "ail build failed for {example}");
|
|
let output = Command::new(&out).output().expect("execute binary");
|
|
assert!(
|
|
output.status.success(),
|
|
"binary {} exited non-zero",
|
|
out.display()
|
|
);
|
|
String::from_utf8(output.stdout).expect("stdout utf8")
|
|
}
|
|
|
|
#[test]
|
|
fn sum_1_to_10_is_55() {
|
|
let stdout = build_and_run("sum.ail.json");
|
|
assert_eq!(stdout.trim(), "55");
|
|
}
|
|
|
|
/// Schützt das Block-Tracking im Codegen: max3 hat verschachtelte `if`s,
|
|
/// und falsches phi-Block-Tracking würde hier zu falschem Ergebnis führen.
|
|
#[test]
|
|
fn max3_picks_largest() {
|
|
let stdout = build_and_run("max3.ail.json");
|
|
assert_eq!(stdout.trim(), "17");
|
|
}
|
|
|
|
#[test]
|
|
fn hello_world_str_lit() {
|
|
let stdout = build_and_run("hello.ail.json");
|
|
assert_eq!(stdout.trim(), "Hallo, AILang.");
|
|
}
|