On 05/01/2012 01:03 AM, Alexander Stavonin wrote:
I'm looking for a way for sharing data between all tests in a crate. Shared 
data or singletons are banned by Rust ideology, isn't it? Also we can not have 
single initialization point for all test. What is a best way to provide some 
common data for all tests in a crate or module?

I don't have a good answer. There is no easy way to do this right now, and my response is mostly going to avoid the question.

One very nice thing about our current setup is that the memory isolation helps make tests repeatable. Adding more external state to tests creates more ways for them to fail.

So here are some things that are difficult to do with the current setup

1) using a common data setup for a set of tests
2) using state that globally requires a single initialization or shutdown
3) testing things that are not threadsafe

For solving 1, a feature that might help is test fixtures with setup and teardown routines, like so many unit test frameworks. I strongly want to leave that kind of thing up to external frameworks that build upon the minimal std::test API though.

In Rust a simple interface for fixtures might allow it to be used like

    #[test]
    fn mytest() {
        // `with_fixture` manages the setup and teardown
        with_fixture::<fixture_type> {|fixture|
           // use my fixture object
           assert fixture.initial_value == false;
           ...
        }
    }

I've run into the second and third situation when testing bindings to native libraries that are not thread safe. In those cases I've just stuffed every affected test into a single test, but that's not a good long-term solution.

The core library is currently growing functions to create global, singleton tasks for special internal purposes. Eventually, there will probably be a general solution for synchronizing access to global resources.
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to