fix: ownership issues

This commit is contained in:
JasterV 2025-11-04 17:19:45 +01:00
parent 50c8ce4912
commit e8cf13db87
3 changed files with 14 additions and 11 deletions

View file

@ -4,7 +4,7 @@ members = ["test-context", "test-context-macros"]
[workspace.package]
edition = "2024"
version = "0.5.1"
version = "0.5.0"
rust-version = "1.91.0"
homepage = "https://github.com/JasterV/test-context"
repository = "https://github.com/JasterV/test-context"

View file

@ -50,35 +50,38 @@ fn refactor_input_body(
let body = match (is_async, args.skip_teardown) {
(true, true) => {
quote! {
use test_context::futures::FutureExt;
let #context_arg_name = <#context_type as test_context::AsyncTestContext>::setup().await;
use test_context::futures::FutureExt;
let mut __context = <#context_type as test_context::AsyncTestContext>::setup().await;
let #context_arg_name = &mut __context;
let #result_name = std::panic::AssertUnwindSafe( async { #body } ).catch_unwind().await;
}
}
(true, false) => {
quote! {
use test_context::futures::FutureExt;
let mut #context_arg_name = <#context_type as test_context::AsyncTestContext>::setup().await;
use test_context::futures::FutureExt;
let mut __context = <#context_type as test_context::AsyncTestContext>::setup().await;
let #context_arg_name = &mut __context;
let #result_name = std::panic::AssertUnwindSafe( async { #body } ).catch_unwind().await;
<#context_type as test_context::AsyncTestContext>::teardown(#context_arg_name).await;
<#context_type as test_context::AsyncTestContext>::teardown(__context).await;
}
}
(false, true) => {
quote! {
let mut #context_arg_name= <#context_type as test_context::TestContext>::setup();
let mut __context = <#context_type as test_context::TestContext>::setup();
let #result_name = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
let #context_arg_name = &mut #context_arg_name;
let #context_arg_name = &mut __context;
#body
}));
}
}
(false, false) => {
quote! {
let mut #context_arg_name = <#context_type as test_context::TestContext>::setup();
let mut __context = <#context_type as test_context::TestContext>::setup();
let #result_name = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
let #context_arg_name = &mut __context;
#body
}));
<#context_type as test_context::TestContext>::teardown(#context_arg_name);
<#context_type as test_context::TestContext>::teardown(__context);
}
}
};

View file

@ -1,7 +1,7 @@
use std::marker::PhantomData;
use rstest::rstest;
use test_context::{test_context, AsyncTestContext, TestContext};
use test_context::{AsyncTestContext, TestContext, test_context};
struct Context {
n: u32,