test-harness

this proc macro wraps your tests with any function that accepts a function with your test's signature. Your test function can accept any number of arguments and return anything, as long as you call it with the correct arguments in the harness.

Example

```rust use test_harness::test;

fn mytestharness(test: F) where F: FnOnce(String) -> Result<(), &'static str> { let string = std::iter::repeat_with(fastrand::alphanumeric).take(10).collect(); test(string).expect("test success"); }

[test(harness = mytestharness)]

fn mytest(randomstring: String) -> Result<(), &'static str> { assert_eq!(string.len(), 10); Ok(()) } ```

This expands to the following, with no further macro magic

```rust fn mytestharness(test: F) where F: FnOnce(String) -> Result<(), &'static str> { let string = std::iter::repeat_with(fastrand::alphanumeric).take(10).collect(); test(string).expect("test success"); }

[test]

fn mytest() { fn mytest(randomstring: String) -> Result<(), &'static str> { asserteq!(string.len(), 10); Ok(()) } mytestharness(my_test); } ```

Async example

You can use this to set up an async runtime and spawn or block on the test.

```rust use test_harness::test;

mod mymod { pub fn setup(test: F) where F: FnOnce(&'static str) -> Fut, Fut: std::future::Future>> + Send + 'static, { futureslite::future::blockon(test("hello")).unwrap() } }

[test(harness = mymod::setup)]

async fn mytest(s: &'static str) -> Result<(), Box> { asserteq!(s, "hello"); Ok(()) } ```

Drop down to standard #[test]

If this macro is used without any additional arguments, it works identically to the built-in #[test] macro.

```rust use test_harness::test;

[test]

fn normal_test() { assert!(true); } ```