Skip to content

Commit

Permalink
Fix warn test for coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
smoelius committed Nov 16, 2023
1 parent 735ec5c commit 0b5161c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 23 deletions.
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 the integration tests (e.g., with `cargo test`), `cargo-dylint` gets built
// with the feature `dylint_internal/testing` enabled. But if you build `cargo-dylint` directly
// (e.g., with `cargo run`), then `cargo-dylint` gets built without that feature. I don't understand
// why.
//
// 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

0 comments on commit 0b5161c

Please sign in to comment.