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

Fix warn test for coverage #951

Merged
merged 1 commit into from
Nov 17, 2023
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
25 changes: 16 additions & 9 deletions cargo-dylint/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,6 @@ struct Dylint {
#[clap(long, hide = true)]
list: bool,

#[clap(
long,
value_name = "path",
help = "Path to Cargo.toml. Note: if the manifest uses metadata, then `--manifest-path \
<path>` must appear before `--`, not after."
)]
manifest_path: Option<String>,

#[clap(long = "new", hide = true)]
new_path: Option<String>,

Expand Down Expand Up @@ -200,6 +192,14 @@ struct NameOpts {
)]
libs: Vec<String>,

#[clap(
long,
value_name = "path",
help = "Path to Cargo.toml. Note: if the manifest uses metadata, then `--manifest-path \
<path>` must appear before `--`, not after."
)]
manifest_path: Option<String>,

#[clap(long, help = "Do not build metadata entries")]
no_build: bool,

Expand All @@ -225,6 +225,7 @@ impl From<Dylint> for dylint::Dylint {
NameOpts {
all,
libs,
manifest_path,
no_build,
no_metadata,
paths,
Expand All @@ -236,7 +237,6 @@ impl From<Dylint> for dylint::Dylint {
isolate,
keep_going,
list,
manifest_path,
new_path,
no_deps,
packages,
Expand Down Expand Up @@ -334,6 +334,13 @@ impl NameOpts {
pub fn absorb(&mut self, other: Self) {
self.all |= other.all;
self.libs.extend(other.libs);
if other.manifest_path.is_some() {
assert!(
self.manifest_path.is_none(),
"`--manifest-path` used multiple times"
);
self.manifest_path = other.manifest_path;
}
self.no_build |= other.no_build;
self.no_metadata |= other.no_metadata;
self.paths.extend(other.paths);
Expand Down
37 changes: 27 additions & 10 deletions cargo-dylint/tests/warn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,48 @@ fn no_libraries_were_found() {
.assert()
.success();

std::process::Command::cargo_bin("cargo-dylint")
.unwrap()
.current_dir(&tempdir)
.args(["dylint", "--all"])
cargo_dylint()
.args([
"dylint",
"--all",
"--manifest-path",
&tempdir.path().join("Cargo.toml").to_string_lossy(),
])
.assert()
.success()
.stderr(predicate::eq("Warning: No libraries were found.\n"));

std::process::Command::cargo_bin("cargo-dylint")
.unwrap()
.current_dir(&tempdir)
.args(["dylint", "list"])
cargo_dylint()
.args([
"dylint",
"list",
"--manifest-path",
&tempdir.path().join("Cargo.toml").to_string_lossy(),
])
.assert()
.success()
.stderr(predicate::eq("Warning: No libraries were found.\n"));
}

#[test]
fn nothing_to_do() {
std::process::Command::cargo_bin("cargo-dylint")
.unwrap()
cargo_dylint()
.args(["dylint"])
.assert()
.success()
.stderr(predicate::eq(
"Warning: Nothing to do. Did you forget `--all`?\n",
));
}

// smoelius: If you build `cargo-dylint` directly (e.g., with `cargo run`), it gets built without
// the feature `dylint_internal/testing`, as you would expect. But if you build the integration
// tests (e.g., with `cargo test`), `cargo-dylint` gets built with that feature enabled. I don't
// understand why the difference.
//
// This problem was encountered in the `no_env_logger_warning` test as well.
fn cargo_dylint() -> std::process::Command {
let mut command = std::process::Command::new("cargo");
command.args(["run", "--quiet", "--bin", "cargo-dylint"]);
command
}
4 changes: 0 additions & 4 deletions dylint/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,6 @@ fn cargo_metadata(opts: &crate::Dylint) -> Result<Option<&'static Metadata>> {
command.manifest_path(path);
}

if let Some(path) = &opts.manifest_path {
command.manifest_path(path);
}

match command.exec() {
Ok(metadata) => Ok(Some(metadata)),
Err(err) => {
Expand Down