Passing --test-threads=1 to cargo test by default?

Even if you can't add mutex to protect bindings (which is definitely a problem IMO, but I don't know all there details) you can add mutex to your tests:

static LIBRARY_USER: Mutex<Executor> = Mutex::new(Executor);

#[derive(Clone, Copy)]
struct Executor;

impl Executor {
    fn run_test(self, f: impl FnOnce()) {
        f();
    }
}

#[test]
fn my_test() {
    LIBRARY_USER.lock().unwrap().run_test(||
        println!("Hello, world!")
    )
}
4 Likes