From a2f23de6652bdb32882b6c63d75c177bce3333d3 Mon Sep 17 00:00:00 2001 From: GroM Date: Wed, 6 Dec 2023 10:26:44 +0100 Subject: [PATCH] add testmacro in workspace --- Cargo.toml | 3 ++- ledger_device_sdk/Cargo.toml | 4 ++-- testmacro/Cargo.toml | 13 +++++++++++++ testmacro/README.md | 3 +++ testmacro/src/lib.rs | 23 +++++++++++++++++++++++ 5 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 testmacro/Cargo.toml create mode 100644 testmacro/README.md create mode 100644 testmacro/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index c9d01b18..5edd93bb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,8 @@ members = [ "ledger_device_sdk", "ledger_secure_sdk_sys", - "include_gif" + "include_gif", + "testmacro" ] resolver = "2" diff --git a/ledger_device_sdk/Cargo.toml b/ledger_device_sdk/Cargo.toml index 0aa53415..f1a9e5f7 100644 --- a/ledger_device_sdk/Cargo.toml +++ b/ledger_device_sdk/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ledger_device_sdk" -version = "1.2.0" +version = "1.2.1" authors = ["yhql", "yogh333"] edition = "2021" license.workspace = true @@ -11,7 +11,7 @@ description = "Ledger device Rust SDK" # https://github.com/rust-lang/cargo/issues/2911#issuecomment-749580481 ledger_device_sdk = { path = ".", features = ["speculos"] } -testmacro = { git = "https://github.com/yhql/testmacro", version = "0.1.0"} +testmacro = { path = "../testmacro", version = "0.1.0"} [dependencies] ledger_secure_sdk_sys = {path = "../ledger_secure_sdk_sys", version = "1.0.2"} diff --git a/testmacro/Cargo.toml b/testmacro/Cargo.toml new file mode 100644 index 00000000..6055e35e --- /dev/null +++ b/testmacro/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "testmacro" +version = "0.1.0" +authors = ["yhql "] +edition = "2018" +publish = false + +[lib] +proc-macro = true + +[dependencies] +syn = { version = "1.0", features = ["full"] } +quote = "1.0" \ No newline at end of file diff --git a/testmacro/README.md b/testmacro/README.md new file mode 100644 index 00000000..cc7c0d93 --- /dev/null +++ b/testmacro/README.md @@ -0,0 +1,3 @@ +# testmacro + +A macro inspired from [Writing an OS in Rust](https://os.phil-opp.com/testing/) and [Rust Raspberry OS tutorials](https://github.com/rust-embedded/rust-raspberrypi-OS-tutorials/tree/master/13_integrated_testing) that helps building `#![no_std]` tests in some other projects. diff --git a/testmacro/src/lib.rs b/testmacro/src/lib.rs new file mode 100644 index 00000000..6d0f8a0c --- /dev/null +++ b/testmacro/src/lib.rs @@ -0,0 +1,23 @@ +extern crate proc_macro; +use proc_macro::TokenStream; +use quote::quote; + +#[proc_macro_attribute] +pub fn test_item(_attr: TokenStream, item: TokenStream) -> TokenStream { + let input = syn::parse_macro_input!(item as syn::ItemFn); + let name = &input.sig.ident.to_string(); + let func = &input.block; + + let r = quote! { + #[test_case] + const t: TestType = TestType { + modname: module_path!(), + name: #name, + f: || -> Result<(),()> { + #func + Ok(()) + } + }; + }; + r.into() +} \ No newline at end of file