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

Rewrite cargo-metadata support #122

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
25 changes: 25 additions & 0 deletions integration-tests/unused-kebab-spec/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions integration-tests/unused-kebab-spec/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "unused-kebab-spec"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
log-once = "0.3.1"
Empty file.
16 changes: 16 additions & 0 deletions integration-tests/unused-renamed-in-registry/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions integration-tests/unused-renamed-in-registry/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "unused-renamed-in-registry"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
xml-rs = "0.8.14"
Empty file.
16 changes: 16 additions & 0 deletions integration-tests/unused-renamed-in-spec/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions integration-tests/unused-renamed-in-spec/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "unused-renamed-in-spec"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
tracing = { version = "0.4.14", package = "log" }
Empty file.
42 changes: 42 additions & 0 deletions src/search_unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,48 @@ fn test_crate_renaming_works() -> anyhow::Result<()> {
Ok(())
}

#[test]
fn test_unused_renamed_in_registry() -> anyhow::Result<()> {
// when a lib like xml-rs is exposed with a different name,
// cargo-machete reports the unused spec properly.
let analysis = find_unused(
&PathBuf::from(TOP_LEVEL).join("./integration-tests/unused-renamed-in-registry/Cargo.toml"),
UseCargoMetadata::Yes,
)?
.expect("no error during processing");
assert_eq!(analysis.unused, &["xml-rs".to_string()]);

Ok(())
}

#[test]
fn test_unused_renamed_in_spec() -> anyhow::Result<()> {
// when a lib is renamed through key = { package = … },
// cargo-machete reports the unused spec properly.
let analysis = find_unused(
&PathBuf::from(TOP_LEVEL).join("./integration-tests/unused-renamed-in-spec/Cargo.toml"),
UseCargoMetadata::Yes,
)?
.expect("no error during processing");
assert_eq!(analysis.unused, &["tracing".to_string()]);

Ok(())
}

#[test]
fn test_unused_kebab_spec() -> anyhow::Result<()> {
// when a lib is renamed through key = { package = … },
// cargo-machete reports the unused spec properly.
Comment on lines +802 to +803
Copy link
Owner

Choose a reason for hiding this comment

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

Think this comment is a copy-pasto from the previous one, and should be updated maybe?

let analysis = find_unused(
&PathBuf::from(TOP_LEVEL).join("./integration-tests/unused-kebab-spec/Cargo.toml"),
UseCargoMetadata::Yes,
)?
.expect("no error during processing");
assert_eq!(analysis.unused, &["log-once".to_string()]);

Ok(())
}

#[test]
fn test_ignore_deps_works() {
// ensure that ignored deps listed in Cargo.toml package.metadata.cargo-machete.ignored are
Expand Down