From 8203e85853eb03ddb18d56c3e4aed7ce1189095f Mon Sep 17 00:00:00 2001 From: Joel Abrahams Date: Fri, 28 Jun 2019 15:52:12 +0200 Subject: [PATCH] Use new test structure for match and operation output checks --- tests/output/control_flow.rs | 20 +++++++---- tests/output/operation.rs | 65 +++++++++++++++++++++++++----------- 2 files changed, 59 insertions(+), 26 deletions(-) diff --git a/tests/output/control_flow.rs b/tests/output/control_flow.rs index b80fc850..6694ecdc 100644 --- a/tests/output/control_flow.rs +++ b/tests/output/control_flow.rs @@ -94,21 +94,29 @@ fn while_ast_verify() -> Result<(), String> { } #[test] -fn match_ast_verify() { - let mamba_path = resource_path(true, &["control_flow"], "match.mamba"); - let out_path = mamba_to_python_direct(Path::new(&mamba_path)).unwrap(); +fn match_ast_verify() -> Result<(), String> { + mamba_to_python( + &Path::new(&resource_path(true, &["control_flow"], "")), + Some("match.mamba"), + None + )?; - let cmd = Command::new(PYTHON).arg("-m").arg("py_compile").arg(out_path).output().unwrap(); + let cmd = Command::new(PYTHON) + .arg("-m") + .arg("py_compile") + .arg(resource_path(true, &["control_flow", "target"], "match.py")) + .output() + .unwrap(); if cmd.status.code().unwrap() != 0 { panic!("{}", String::from_utf8(cmd.stderr).unwrap()); } let python_src = resource_content(true, &["control_flow"], "match_check.py"); - let out_src = resource_content(true, &["control_flow"], "match.py"); + let out_src = resource_content(true, &["control_flow", "target"], "match.py"); let python_ast = python_src_to_stmts(&python_src); let out_ast = python_src_to_stmts(&out_src); assert_eq!(python_ast, out_ast); - check_exists_and_delete(true, &["control_flow"], "match.py"); + Ok(assert!(exists_and_delete(true, &["control_flow", "target"], "match.py"))) } diff --git a/tests/output/operation.rs b/tests/output/operation.rs index 6d648635..a99cd339 100644 --- a/tests/output/operation.rs +++ b/tests/output/operation.rs @@ -1,69 +1,94 @@ extern crate python_parser; -use crate::common::check_exists_and_delete; + +use crate::common::exists_and_delete; use crate::common::python_src_to_stmts; use crate::common::resource_content; use crate::common::resource_path; use crate::output::common::PYTHON; -use mamba::command::mamba_to_python_direct; +use mamba::pipeline::mamba_to_python; use std::path::Path; use std::process::Command; #[test] -fn arithmetic_ast_verify() { - let mamba_path = resource_path(true, &["operation"], "arithmetic.mamba"); - let out_path = mamba_to_python_direct(Path::new(&mamba_path)).unwrap(); +fn arithmetic_ast_verify() -> Result<(), String> { + mamba_to_python( + &Path::new(&resource_path(true, &["operation"], "")), + Some("arithmetic.mamba"), + None + )?; - let cmd = Command::new(PYTHON).arg("-m").arg("py_compile").arg(out_path).output().unwrap(); + let cmd = Command::new(PYTHON) + .arg("-m") + .arg("py_compile") + .arg(resource_path(true, &["operation", "target"], "arithmetic.py")) + .output() + .unwrap(); if cmd.status.code().unwrap() != 0 { panic!("{}", String::from_utf8(cmd.stderr).unwrap()); } let python_src = resource_content(true, &["operation"], "arithmetic_check.py"); - let out_src = resource_content(true, &["operation"], "arithmetic.py"); + let out_src = resource_content(true, &["operation", "target"], "arithmetic.py"); let python_ast = python_src_to_stmts(&python_src); let out_ast = python_src_to_stmts(&out_src); assert_eq!(python_ast, out_ast); - check_exists_and_delete(true, &["operation"], "arithmetic.py"); + Ok(assert!(exists_and_delete(true, &["operation", "target"], "arithmetic.py"))) } #[test] -fn bitwise_ast_verify() { - let mamba_path = resource_path(true, &["operation"], "bitwise.mamba"); - let out_path = mamba_to_python_direct(Path::new(&mamba_path)).unwrap(); +fn bitwise_ast_verify() -> Result<(), String> { + mamba_to_python( + &Path::new(&resource_path(true, &["operation"], "")), + Some("bitwise.mamba"), + None + )?; - let cmd = Command::new(PYTHON).arg("-m").arg("py_compile").arg(out_path).output().unwrap(); + let cmd = Command::new(PYTHON) + .arg("-m") + .arg("py_compile") + .arg(resource_path(true, &["operation", "target"], "bitwise.py")) + .output() + .unwrap(); if cmd.status.code().unwrap() != 0 { panic!("{}", String::from_utf8(cmd.stderr).unwrap()); } let python_src = resource_content(true, &["operation"], "bitwise_check.py"); - let out_src = resource_content(true, &["operation"], "bitwise.py"); + let out_src = resource_content(true, &["operation", "target"], "bitwise.py"); let python_ast = python_src_to_stmts(&python_src); let out_ast = python_src_to_stmts(&out_src); assert_eq!(python_ast, out_ast); - check_exists_and_delete(true, &["operation"], "bitwise.py"); + Ok(assert!(exists_and_delete(true, &["operation", "target"], "bitwise.py"))) } #[test] -fn boolean_ast_verify() { - let mamba_path = resource_path(true, &["operation"], "boolean.mamba"); - let out_path = mamba_to_python_direct(Path::new(&mamba_path)).unwrap(); +fn boolean_ast_verify() -> Result<(), String> { + mamba_to_python( + &Path::new(&resource_path(true, &["operation"], "")), + Some("boolean.mamba"), + None + )?; - let cmd = Command::new(PYTHON).arg("-m").arg("py_compile").arg(out_path).output().unwrap(); + let cmd = Command::new(PYTHON) + .arg("-m") + .arg("py_compile") + .arg(resource_path(true, &["operation", "target"], "boolean.py")) + .output() + .unwrap(); if cmd.status.code().unwrap() != 0 { panic!("{}", String::from_utf8(cmd.stderr).unwrap()); } let python_src = resource_content(true, &["operation"], "boolean_check.py"); - let out_src = resource_content(true, &["operation"], "boolean.py"); + let out_src = resource_content(true, &["operation", "target"], "boolean.py"); let python_ast = python_src_to_stmts(&python_src); let out_ast = python_src_to_stmts(&out_src); assert_eq!(python_ast, out_ast); - check_exists_and_delete(true, &["operation"], "boolean.py"); + Ok(assert!(exists_and_delete(true, &["operation", "target"], "boolean.py"))) }