use anyhow::Result;
use std::fs;
use std::path::{Path, PathBuf};
use std::process::Command;
use tempfile::tempdir;
fn vc_binary() -> PathBuf {
env!("CARGO_BIN_EXE_vc").into()
}
fn generate_compiler_output(build_dir: &Path) -> Result<()> {
let output = Command::new(vc_binary()).arg("demo").arg("--out").arg(build_dir).output()?;
assert!(output.status.success());
Ok(())
}
fn write_stub_config(config_path: &Path) -> Result<()> {
let content = r#"
[global]
[profiles.default]
backend_name = "stub"
[backends.stub]
enabled = true
[backends.stub.options]
kind = "dummy"
[backends.stub.options.options]
"#;
fs::write(config_path, content)?;
Ok(())
}
#[test]
fn cli_demo_and_run() -> Result<()> {
let temp = tempdir()?;
let build_dir = temp.path().join("build");
let run_dir = temp.path().join("run");
generate_compiler_output(&build_dir)?;
let config_path = temp.path().join("config.toml");
write_stub_config(&config_path)?;
let run_output = Command::new(vc_binary())
.arg("run")
.arg("--input")
.arg(&build_dir)
.arg("--out")
.arg(&run_dir)
.arg("--config")
.arg(&config_path)
.arg("--profile")
.arg("default")
.output()?;
assert!(run_output.status.success());
let runtime_path = run_dir.join("runtime.json");
assert!(runtime_path.exists());
Ok(())
}
#[test]
fn cli_run_fails_with_missing_config() -> Result<()> {
let temp = tempdir()?;
let build_dir = temp.path().join("build");
let run_dir = temp.path().join("run");
generate_compiler_output(&build_dir)?;
let missing_config = temp.path().join("missing.toml");
let run_output = Command::new(vc_binary())
.arg("run")
.arg("--input")
.arg(&build_dir)
.arg("--out")
.arg(&run_dir)
.arg("--config")
.arg(&missing_config)
.arg("--profile")
.arg("default")
.output()?;
assert!(!run_output.status.success());
Ok(())
}