mini-RFC: add an option to fail fast within a single test target?

Rust does not appear to "fail fast" for individual tests explains that --fail-fast applies only at the level of cargo test running multiple targets. Each test target, containing potentially many functions, runs to completion, at least if using the normal harness code.

I don't want to change the default but I do think it would be useful to have an option to stop after the first failure within a single test target. For example, cargo mutants really just wants to know if any tests fail.

Do you think there would be any objection in principle to a PR adding an option for this?

No idea. Such ideas are best discussed on the internals forum (probably under the category "tools and infrastructure" as this concerns libtest).

1 Like

I think you can approximate this behavior by compiling with panic=abort, though that won't work for should_panic tests.

Yes; the built-in test harness (aka libtest) is more or less under a feature freeze and work is being put towards, instead, designing better interfaces for custom test harnesses that can arbitrarily customize test execution behavior.

(Custom test harnesses are possible now but have no stable way to get at #[test] functions.)

I moved this to FR: Add a `--fail-fast` option to libtest · Issue #142859 · rust-lang/rust · GitHub.

Since it looks like a libtest 2.0 might take a while I hope they can still take a small tactical fix for this. We'll see.