Skip to content

Commit

Permalink
Use new test structure for match and operation output checks
Browse files Browse the repository at this point in the history
  • Loading branch information
JSAbrahams committed Jun 28, 2019
1 parent f448819 commit 8203e85
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 26 deletions.
20 changes: 14 additions & 6 deletions tests/output/control_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")))
}
65 changes: 45 additions & 20 deletions tests/output/operation.rs
Original file line number Diff line number Diff line change
@@ -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")))
}

0 comments on commit 8203e85

Please sign in to comment.