Why does cargo think that the fuzz targets functions are tests?

I am using cargo-fuzz and I have a fuzz/ directory with a Cargo.toml, In CI I run the following to run all tests

cargo test --workspace --all-targets

I tried to include the fuzz/ package in my workspace and I noticed that it tries to run the fuzzing when cargo test --workspace --all-targets is run. Why does cargo think that the fuzz targets functions are tests?

Every binary target can contain #[test] tests, so it gets compiled in cfg(test) mode to find and run those tests. If your Cargo.toml is set up in the default way for cargo-fuzz, it should contain test = false to suppress that default behavior.

[[bin]]
name = "fuzz_something"
path = "fuzz_targets/fuzz_something.rs"
test = false
doc = false

Maybe test = false is missing from yours?

If not, please post fuzz/Cargo.toml and the output from cargo test so we can see more clues.

It appears that --all-targets overrides test = false so I have removed that from the CI command. Here is the project.

I guess I was more trying to understand why the function generated by libfuzzer::fuzz_target! is recognized as a test by Cargo.

I see that is documented. I didn't know:

The test field indicates whether or not the target is tested by default by cargo test.


the function generated by libfuzzer::fuzz_target! is recognized as a test by Cargo.

The macro source does not define a #[test]. My guess is that you're not seeing any function being run as a test, but that some of the fuzzer's build config or linker symbols are causing the fuzz test harness code to be run instead of the standard Rust test harness, hence trying to start fuzzing instead of look for #[test]s.