Skip to content

Commit

Permalink
add testmacro in workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
yogh333 committed Dec 6, 2023
1 parent 0a127e2 commit a2f23de
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
members = [
"ledger_device_sdk",
"ledger_secure_sdk_sys",
"include_gif"
"include_gif",
"testmacro"
]
resolver = "2"

Expand Down
4 changes: 2 additions & 2 deletions ledger_device_sdk/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"}
Expand Down
13 changes: 13 additions & 0 deletions testmacro/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "testmacro"
version = "0.1.0"
authors = ["yhql <[email protected]>"]
edition = "2018"
publish = false

[lib]
proc-macro = true

[dependencies]
syn = { version = "1.0", features = ["full"] }
quote = "1.0"
3 changes: 3 additions & 0 deletions testmacro/README.md
Original file line number Diff line number Diff line change
@@ -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.
23 changes: 23 additions & 0 deletions testmacro/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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()
}

0 comments on commit a2f23de

Please sign in to comment.