-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add snapshot test of macro expansion
- Loading branch information
Showing
4 changed files
with
2,475 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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use pyo3::{types::PyModule, PyResult, Python}; | ||
|
||
// The code being tested is in a separate module so it can be expanded (see | ||
// [`test_macro_expansion`]) without expanding the contents of the tests | ||
// themselves. This file must be in a subdirectory (`wrapper_tests/mod.rs` | ||
// instead of `wrapper_tests.rs`) because the generated `.expanded.rs` file | ||
// cannot be in the root `tests/` directory or `cargo test` will attempt to | ||
// build it as a test case as well. | ||
mod wrapper_tests; | ||
|
||
#[test] | ||
fn test_enum_as_data_struct_member() { | ||
wrapper_tests::append_to_inittab(); | ||
pyo3::prepare_freethreaded_python(); | ||
let result: PyResult<()> = Python::with_gil(|py| { | ||
let code = r#" | ||
from wrapper_tests import TestEnumUnaliased, TestEnumAliased, TestStruct, TestUnionEnum | ||
struct = TestStruct() | ||
assert struct.test_enum_unaliased == TestEnumUnaliased.One | ||
assert struct.test_enum_aliased == TestEnumAliased.NONE | ||
struct.test_enum_unaliased = TestEnumUnaliased.Two | ||
struct.test_enum_aliased = TestEnumAliased.Two | ||
assert struct.test_enum_unaliased == TestEnumUnaliased.Two | ||
assert struct.test_enum_aliased == TestEnumAliased.Two | ||
assert TestUnionEnum.new_unit().is_unit() | ||
"#; | ||
PyModule::from_code(py, code, "example.py", "example")?; | ||
|
||
Ok(()) | ||
}); | ||
|
||
result.expect("python code should execute without issue") | ||
} | ||
|
||
#[test] | ||
fn test_macro_expansion() { | ||
// To regenerate the snapshot, delete the generated | ||
// `tests/wrapper_tests/mod.expanded.rs` file and retun the test. | ||
macrotest::expand("tests/wrapper_tests/mod.rs") | ||
} |
Oops, something went wrong.