Skip to content

Commit

Permalink
[sc-487] Add test for hvmc compile (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
FranchuFranchu authored Mar 4, 2024
1 parent 741ebe5 commit 2a338a9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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(())
}
34 changes: 34 additions & 0 deletions tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use std::{
error::Error,
io::Read,
path::PathBuf,
process::{Command, ExitStatus, Stdio},
};

Expand Down Expand Up @@ -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();
}

0 comments on commit 2a338a9

Please sign in to comment.