module_fixtures/
module_fixtures.rs1use rest::prelude::*;
2use std::cell::RefCell;
3
4thread_local! {
6 static TEST_COUNTER: RefCell<u32> = RefCell::new(0);
7}
8
9fn increment_counter() {
11 TEST_COUNTER.with(|counter| {
12 *counter.borrow_mut() += 1;
13 });
14}
15
16fn get_counter() -> u32 {
18 return TEST_COUNTER.with(|counter| *counter.borrow());
19}
20
21fn setup_module_fixtures() {
23 println!("\nExample of using module-level fixtures:");
24 println!("In a real test, you would use:");
25 println!("#[with_fixtures_module]");
26 println!("mod my_test_module {{");
27 println!(" #[setup]");
28 println!(" fn setup() {{ /* setup code */ }}");
29 println!("");
30 println!(" #[tear_down]");
31 println!(" fn tear_down() {{ /* cleanup code */ }}");
32 println!("");
33 println!(" #[test]");
34 println!(" fn test_something() {{ /* fixtures automatically applied */ }}");
35 println!("}}\n");
36}
37
38fn run_fixture_setup() {
40 println!("Setting up test environment...");
41 TEST_COUNTER.with(|counter| {
42 *counter.borrow_mut() = 0;
43 });
44}
45
46fn run_fixture_teardown() {
48 println!("Cleaning up test environment...");
49 TEST_COUNTER.with(|counter| {
50 println!("Final counter value: {}", *counter.borrow());
51 });
52}
53
54fn run_simulated_test() {
56 run_fixture_setup();
58
59 println!("Running test...");
60 expect!(get_counter()).to_equal(0);
62
63 increment_counter();
65 expect!(get_counter()).to_equal(1);
66
67 run_fixture_teardown();
69}
70
71fn main() {
72 config().enhanced_output(true).apply();
74
75 setup_module_fixtures();
77
78 run_simulated_test();
80
81 println!("\nAll tests passed!");
82}