Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Change order of tests #165

Merged
merged 1 commit into from
May 14, 2024
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
34 changes: 17 additions & 17 deletions src/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,19 @@ macro_rules! e2e {
let name = stringify!($name);
let dir = Path::new(file).parent().unwrap().join(name);

let res = $crate::e2e::internal::compile(&tmp, &dir);
if let Err(err) = res {
let hir = $crate::e2e::internal::hir(&tmp, name, &dir);
if let Err(err) = hir {
assert_snapshot!(concat!(stringify!($name), ".error"), err);
return;
}

let hir = $crate::e2e::internal::hir(&tmp, name, &dir);
let hir = hir.unwrap();
assert_snapshot!(concat!(stringify!($name), ".hir"), hir);

let ir = $crate::e2e::internal::ir(&tmp, name, &dir);
assert_snapshot!(concat!(stringify!($name), ".ir"), ir);

$crate::e2e::internal::compile(&tmp, &dir);

let (run_log, status) = $crate::e2e::internal::run(&tmp, name, &dir);
assert_snapshot!(concat!(stringify!($name), ".run"), run_log);
status.exit_ok().map_err(|e| miette!("{e}")).unwrap();
Expand Down Expand Up @@ -60,10 +61,20 @@ pub mod internal {

const PPL: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/target/debug/ppl");

pub fn compile(temp_dir: &Path, dir: &Path) -> Result<(), String> {
pub fn compile(temp_dir: &Path, dir: &Path) {
run_cmd! {
cd $dir;
$PPL build --output-dir $temp_dir
}
.map_err(|e| miette!("{e}"))
.unwrap();
}

pub fn hir(temp_dir: &Path, _name: &str, dir: &Path) -> Result<String, String> {
let output = std::process::Command::new(PPL)
.args(&["build"])
.args(&["--output-dir", temp_dir.to_str().unwrap()])
.args(&["--emit", "hir"])
.current_dir(dir)
.output()
.map_err(|e| miette!("{e}"))
Expand All @@ -74,23 +85,12 @@ pub mod internal {
return Err(stderr);
}

Ok(())
}

pub fn hir(temp_dir: &Path, _name: &str, dir: &Path) -> String {
run_cmd! {
cd $dir;
$PPL build --output-dir $temp_dir --emit hir
}
.map_err(|e| miette!("{e}"))
.unwrap();

let mut hir = temp_dir.join(OutputType::HIR.named("main"));
if !hir.exists() {
hir = temp_dir.join(OutputType::HIR.named("lib"));
}

std::fs::read_to_string(&hir).expect("failed to read HIR")
Ok(std::fs::read_to_string(&hir).expect("failed to read HIR"))
}

pub fn ir(temp_dir: &Path, name: &str, dir: &Path) -> String {
Expand Down
7 changes: 3 additions & 4 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,12 @@ fn ppl() {
let name = "ppl";
let dir = Path::new(concat!(env!("CARGO_MANIFEST_DIR"), "/ppl"));

let res = crate::e2e::internal::compile(&tmp, dir);
if let Err(err) = res {
let hir = crate::e2e::internal::hir(&tmp, name, &dir);
if let Err(err) = hir {
assert_snapshot!("ppl.error", err);
return;
}

let hir = crate::e2e::internal::hir(&tmp, name, &dir);
let hir = hir.unwrap();
assert_snapshot!("ppl.hir", hir);

let ir = crate::e2e::internal::ir(&tmp, name, &dir);
Expand Down
Loading