Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sc-487] Add test for hvmc compile #76

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
Loading