-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a
generate_python_tests!
macro (#91)
The macro generates tests for Python scripts found next to the integration test. This saves a bit of boiler-plate code at the point where the test is created. It also allows us to quickly see if there are gaps in the test coverage between the sync and async code. This comes at the expense of more “magic” in the form of the macro.
- Loading branch information
Showing
6 changed files
with
50 additions
and
52 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
This file was deleted.
Oops, something went wrong.
File renamed without changes.
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,50 @@ | ||
/// Run sync and async Python scenarios. | ||
/// | ||
/// The Python scripts are given as identifiers, relative to this | ||
/// file. They can be `None` if the sync or async test variant does | ||
/// not exist. | ||
/// | ||
/// The test script can use `import mls_rs_uniffi` to get access to | ||
/// the Python bindings. | ||
macro_rules! generate_python_tests { | ||
($sync_scenario:ident, None) => { | ||
#[cfg(not(mls_build_async))] | ||
generate_python_tests!($sync_scenario); | ||
}; | ||
|
||
(None, $async_scenario:ident) => { | ||
#[cfg(mls_build_async)] | ||
generate_python_tests!($async_scenario); | ||
}; | ||
|
||
($sync_scenario:ident, $async_scenario:ident) => { | ||
#[cfg(not(mls_build_async))] | ||
generate_python_tests!($sync_scenario); | ||
|
||
#[cfg(mls_build_async)] | ||
generate_python_tests!($async_scenario); | ||
}; | ||
|
||
($scenario:ident) => { | ||
#[test] | ||
fn $scenario() -> Result<(), Box<dyn std::error::Error>> { | ||
let target_dir = env!("CARGO_TARGET_TMPDIR"); | ||
let script_path = format!("tests/{}.py", stringify!($scenario)); | ||
uniffi_bindgen::bindings::python::run_script( | ||
&target_dir, | ||
"mls-rs-uniffi", | ||
&script_path, | ||
vec![], | ||
&uniffi_bindgen::bindings::RunScriptOptions::default(), | ||
) | ||
.map_err(Into::into) | ||
} | ||
}; | ||
} | ||
|
||
generate_python_tests!(generate_signature_keypair, None); | ||
|
||
// TODO(mulmarta): it'll break if we use async trait which will be | ||
// supported in the next UniFFI release | ||
// TODO(mgeisler): add back simple_scenario_async | ||
generate_python_tests!(simple_scenario_sync, None); |
File renamed without changes.