use assert_cmd::Command;
use predicates::prelude::*;
use std::io::Write;
#[test]
fn build_writes_a_bytecode_artifact() {
let dir = tempfile::tempdir().unwrap();
let src_path = dir.path().join("prog.qala");
std::fs::write(&src_path, "fn main() is io {\n println(\"hi\")\n}").unwrap();
let out_path = dir.path().join("prog.qbc");
Command::cargo_bin("qala")
.unwrap()
.args(["build"])
.arg(&src_path)
.arg("-o")
.arg(&out_path)
.assert()
.success();
let listing = std::fs::read_to_string(&out_path).unwrap();
assert!(!listing.is_empty());
assert!(listing.contains("chunk")); }
#[test]
fn build_target_arm64_writes_an_assembly_file() {
let dir = tempfile::tempdir().unwrap();
let src_path = dir.path().join("prog.qala");
std::fs::write(&src_path, "fn main() {\n let x = 2 + 3\n}\n").unwrap();
let out_path = dir.path().join("prog.s");
Command::cargo_bin("qala")
.unwrap()
.args(["build"])
.arg(&src_path)
.args(["--target", "arm64"])
.arg("-o")
.arg(&out_path)
.assert()
.success();
let assembly = std::fs::read_to_string(&out_path).unwrap();
assert!(!assembly.is_empty());
assert!(assembly.contains(".text")); assert!(assembly.contains("main:")); }
#[test]
fn build_target_arm64_emits_printf_for_a_printing_program() {
let dir = tempfile::tempdir().unwrap();
let src_path = dir.path().join("prog.qala");
std::fs::write(
&src_path,
"fn main() is io {\n let n = 7\n println(\"n = {n}\")\n}\n",
)
.unwrap();
let out_path = dir.path().join("prog.s");
Command::cargo_bin("qala")
.unwrap()
.args(["build"])
.arg(&src_path)
.args(["--target", "arm64"])
.arg("-o")
.arg(&out_path)
.assert()
.success();
let assembly = std::fs::read_to_string(&out_path).unwrap();
assert!(assembly.contains(".data")); assert!(assembly.contains("%lld")); assert!(assembly.contains("bl printf")); }
#[test]
fn build_target_arm64_rejects_an_unsupported_construct() {
let mut src = tempfile::Builder::new().suffix(".qala").tempfile().unwrap();
write!(src, "fn main() {{\n let x = 1.5\n}}").unwrap();
Command::cargo_bin("qala")
.unwrap()
.arg("build")
.arg(src.path())
.args(["--target", "arm64"])
.assert()
.failure()
.stderr(predicate::str::contains("does not yet support"));
}