Skip to content

Commit

Permalink
Merge pull request #356 from kdarkhan/no-dep
Browse files Browse the repository at this point in the history
Do not list dependency packages by MetadataCommand
  • Loading branch information
fitzgen authored Jan 9, 2024
2 parents ef67b11 + b02b2b8 commit cdd6e41
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -938,11 +938,11 @@ pub struct Manifest {

impl Manifest {
pub fn parse() -> Result<Self> {
let metatdata = MetadataCommand::new().exec()?;
let package = metatdata.packages.first().with_context(|| {
let metadata = MetadataCommand::new().no_deps().exec()?;
let package = metadata.packages.first().with_context(|| {
anyhow!(
"Expected to find at least one package in {}",
metatdata.target_directory
metadata.target_directory
)
})?;
let crate_name = package.name.clone();
Expand Down
34 changes: 34 additions & 0 deletions tests/tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,40 @@ fn init_finds_parent_project() {
assert!(project.fuzz_target_path("fuzz_target_1").is_file());
}

#[test]
fn init_defines_correct_dependency() {
let project_name = "project_with_some_dep";
let project = project(project_name)
.file(
"Cargo.toml",
&format!(
r#"
[workspace]
[package]
name = "{name}"
version = "1.0.0"
[dependencies]
matches = "0.1.10"
"#,
name = project_name
),
)
.build();
project
.cargo_fuzz()
.current_dir(project.root().join("src"))
.arg("init")
.assert()
.success();
assert!(project.fuzz_dir().is_dir());
assert!(project.fuzz_cargo_toml().is_file());
let cargo_toml = fs::read_to_string(project.fuzz_cargo_toml()).unwrap();
let expected_dependency_attrs =
&format!("[dependencies.{name}]\npath = \"..\"", name = project_name);
assert!(cargo_toml.contains(expected_dependency_attrs));
}

#[test]
fn add() {
let project = project("add").with_fuzz().build();
Expand Down

0 comments on commit cdd6e41

Please sign in to comment.