diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 7f08118a..25402f1a 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -20,3 +20,4 @@ serde_json = "1.0.79" [features] __auto_concretize = ["test-fuzz/auto_concretize"] __bar_fuzz = [] +__inapplicable_conversion = [] diff --git a/examples/tests/conversion.rs b/examples/tests/conversion.rs index 06b7b7d8..88214397 100644 --- a/examples/tests/conversion.rs +++ b/examples/tests/conversion.rs @@ -60,3 +60,40 @@ mod receiver { X.target(); } } + +#[cfg(feature = "__inapplicable_conversion")] +mod inapplicable_conversion { + use serde::{Deserialize, Serialize}; + + #[derive(Clone)] + struct X; + + #[derive(Clone)] + struct Y; + + #[derive(Clone, Deserialize, Serialize)] + struct Z; + + impl From for Z { + fn from(_: Y) -> Self { + Z + } + } + + impl test_fuzz::Into for Z { + fn into(self) -> Y { + Y + } + } + + #[test_fuzz::test_fuzz_impl] + impl X { + #[test_fuzz::test_fuzz(convert = "Y, Z")] + fn target(self) {} + } + + #[test] + fn test() { + X.target(); + } +} diff --git a/test-fuzz/tests/conversion.rs b/test-fuzz/tests/conversion.rs new file mode 100644 index 00000000..d58b4f0b --- /dev/null +++ b/test-fuzz/tests/conversion.rs @@ -0,0 +1,30 @@ +use assert_cmd::prelude::*; +use predicates::prelude::*; +use std::process::Command; +use testing::examples::MANIFEST_PATH; + +#[test] +fn conversion() { + let mut command = test(); + + command.assert().success(); + + command + .args(["--features", "__inapplicable_conversion"]) + .assert() + .failure() + .stderr(predicate::str::is_match(r#"(?m)\bConversion "Y" -> "Z" does not apply to the following cadidates: \{\s*"X",\s*}$"#).unwrap()); +} + +fn test() -> Command { + let mut command = Command::new("cargo"); + command.args(&[ + "test", + "--manifest-path", + &MANIFEST_PATH, + "--no-run", + "--features", + &("test-fuzz/".to_owned() + test_fuzz::serde_format().as_feature()), + ]); + command +} diff --git a/test-fuzz/tests/rename.rs b/test-fuzz/tests/rename.rs index 01e39434..a35f6b32 100644 --- a/test-fuzz/tests/rename.rs +++ b/test-fuzz/tests/rename.rs @@ -5,32 +5,28 @@ use testing::examples::MANIFEST_PATH; #[test] fn rename() { - Command::new("cargo") - .args(&[ - "test", - "--manifest-path", - &MANIFEST_PATH, - "--no-run", - "--features", - &("test-fuzz/".to_owned() + test_fuzz::serde_format().as_feature()), - ]) - .assert() - .success(); + let mut command = test(); + + command.assert().success(); - Command::new("cargo") - .args(&[ - "test", - "--manifest-path", - &MANIFEST_PATH, - "--no-run", - "--features", - &("test-fuzz/".to_owned() + test_fuzz::serde_format().as_feature()), - "--features", - "__bar_fuzz", - ]) + command + .args(["--features", "__bar_fuzz"]) .assert() .failure() .stderr(predicate::str::contains( "the name `bar_fuzz` is defined multiple times", )); } + +fn test() -> Command { + let mut command = Command::new("cargo"); + command.args(&[ + "test", + "--manifest-path", + &MANIFEST_PATH, + "--no-run", + "--features", + &("test-fuzz/".to_owned() + test_fuzz::serde_format().as_feature()), + ]); + command +}