-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use new test structure for match and operation output checks
- Loading branch information
1 parent
f448819
commit 8203e85
Showing
2 changed files
with
59 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"))) | ||
} |