macro_rules! build_mock_binary_once {
    ($name:ident) => { ... };
}
Expand description

Generate a singleton function to save invoking cargo multiple times for the same binary. This is useful when you have many integration tests that use the one test binary, and don’t want to invoke Cargo over and over for each one.

Calling build_mock_binary_once(binary_name) (no quotes) will generate a function binary_name_path() that returns the path of the built test binary as an OsString, just like build_mock_binary("binary_name") would. Unlike build_mock_binary("binary_name"), the generated function will only build the binary once, and only on the first call. Subsequent calls will use a cached path and assume the initial build is still valid. The generated function unwraps the result internally and will panic on build errors.

For example, if you use build_mock_binary_once(test_it_builds) in tests/common/mod.rs, that module will then contain a function test_it_builds_path() -> std::ffi::OsString. Multiple integration tests can then use common::test_it_builds_path() to obtain the path. Cargo will only be run once for this binary, even if the integration tests that use it are being run in multiple threads.

See this module’s own integration tests for an example. If you need to use the extra arguments from build_mock_binary_with_opts() you will need to implement it manually.