Skip to content

Commit

Permalink
Add conversion test
Browse files Browse the repository at this point in the history
  • Loading branch information
smoelius committed Mar 11, 2022
1 parent 1ddbec4 commit f71e976
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 22 deletions.
1 change: 1 addition & 0 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ serde_json = "1.0.79"
[features]
__auto_concretize = ["test-fuzz/auto_concretize"]
__bar_fuzz = []
__inapplicable_conversion = []
37 changes: 37 additions & 0 deletions examples/tests/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Y> for Z {
fn from(_: Y) -> Self {
Z
}
}

impl test_fuzz::Into<Y> 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();
}
}
30 changes: 30 additions & 0 deletions test-fuzz/tests/conversion.rs
Original file line number Diff line number Diff line change
@@ -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
}
40 changes: 18 additions & 22 deletions test-fuzz/tests/rename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit f71e976

Please sign in to comment.