Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not list dependency packages by MetadataCommand #356

Merged
merged 2 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Contributor Author

@kdarkhan kdarkhan Jan 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on my tests, CargoMetadata crate calls cargo metadata with or without --no-deps.
When called without --no-deps, the result contains all packages including dependency packages which are sorted alphabetically. In order to create a failing example, I had to create a sample cargo project which has the name alphabetically greater than one of its dependencies (project_with_some_dep > matches).

assert!(cargo_toml.contains(expected_dependency_attrs));
}

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