-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
once with a test context #159
Comments
Or maybe |
It could be an options .... but I've some doubts about your example: you can never write something like this in safe rust and you must wrap your shared instance in a Anyway this can be useful... I'll try to find some time for implement it but I'm little busy now :( |
Ok I try to sketch a valid example #[derive(PartialEq, Debug, Copy, Clone)]
struct Service(u32);
#[fixture]
fn random() -> u32 {
rand::thread_rng().gen()
}
#[fixture]
#[once_test]
fn shared_random(#[from(random)] r: u32) -> u32 {
r
}
#[fixture]
fn service_a(shared_random: &u32) -> Service {
Service(*random)
}
#[fixture]
fn service_b(shared_random: &u32) -> Service {
Service(*random)
}
#[fixture]
fn service_c(random: u32) -> Service {
Service(random)
}
use once_cell::sync::Lazy
use std::sync::Mutex;
static SERVICE: Lazy<Mutex<Option<Service>>> = Lazy::new(|| Mutex::new(None));
fn check_service(s: Service) {
let old = SERVICE.lock().unwrap();
match *old {
Some(old_service) => assert_ne!(old_service, s),
None => { *old = Some(s); }
}
}
#[rstest]
#[case::first_contest]
#[case::other_contest]
fn shared_dep(service_a: Service, service_b: Service, service_c: Service) {
assert_eq!(service_a, service_b);
assert_ne!(service_a, service_c);
check_service(service_a);
} |
I'm looking at this issue and trying to see if this is what I need for my use case. I need a fixture that is like My case is that I am testing a builder pattern framework. I have a mutable Builder that I can add objects to and get a handle back. Later my Builder gets consumed into some repository of objects. In other words, for one test case I need all fixtures to receive a &mut of the same Builder. The test case itself needs to receive the final built Builder and consume it. A contrived example:
If this is possible now, I'd love to hear how. If not, does your |
@jsadusk Use mutable reference in Rust is a pain 😢 I think that you can do it by wrap it around a mutex, use |
In continue of #152
For example we have few services and some shared object:
And if we try to test if it will fail
It would be nice to have something like #[once_test] here.
The text was updated successfully, but these errors were encountered: