diff --git a/src/main.rs b/src/main.rs index dd7e0663..9e172c4b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -318,7 +318,7 @@ fn compile_executable(file_name: &str, host: &host::Host) -> Result<(), io::Erro } let output = process::Command::new("cargo") - .current_dir("./.hvm") + .current_dir(".hvm") .arg("build") .arg("--release") .stderr(Stdio::inherit()) @@ -327,8 +327,9 @@ fn compile_executable(file_name: &str, host: &host::Host) -> Result<(), io::Erro process::exit(1); } - let target = format!("./{}", file_name.strip_suffix(".hvmc").unwrap_or(file_name)); - fs::copy("./.hvm/target/release/hvmc", target)?; + let target = format!("{}", file_name.strip_suffix(".hvmc").unwrap_or(file_name)); + + fs::copy(".hvm/target/release/hvmc", target)?; Ok(()) } diff --git a/tests/cli.rs b/tests/cli.rs index 40bf8c67..9c3a6798 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -3,6 +3,7 @@ use std::{ error::Error, io::Read, + path::PathBuf, process::{Command, ExitStatus, Stdio}, }; @@ -183,3 +184,36 @@ fn test_apply_tree() { @"(<2* a> a)" ); } + +#[test] +fn test_cli_compile() { + // Test normal-form expressions + + if !Command::new(env!("CARGO_BIN_EXE_hvmc")) + .args(&["compile", &get_arithmetic_program_path()]) + .stdout(Stdio::inherit()) + .stderr(Stdio::inherit()) + .spawn() + .unwrap() + .wait() + .unwrap() + .success() + { + panic!("{:?}", "compilation failed"); + }; + + let mut output_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + output_path.push("examples/arithmetic"); + let mut child = Command::new(&output_path).args(&["#40", "#3"]).stdout(Stdio::piped()).spawn().unwrap(); + + let mut stdout = child.stdout.take().ok_or("Couldn't capture stdout!").unwrap(); + child.wait().unwrap(); + let mut output = String::new(); + stdout.read_to_string(&mut output).unwrap(); + + assert_display_snapshot!(output, @r###" + [#13 #1] + "###); + + std::fs::remove_file(&output_path).unwrap(); +}