use crate::prelude::*;
use cargo_test_support::project;
use cargo_test_support::registry::Package;
use cargo_test_support::rustc_host;
use cargo_test_support::str;

#[cargo_test]
fn unused_dep_normal() {
    // The most basic case where there is an unused dependency
    Package::new("unused", "0.1.0").publish();
    let p = project()
        .file(
            "Cargo.toml",
            r#"
            [package]
            name = "foo"
            version = "0.1.0"
            authors = []
            edition = "2018"

            [dependencies]
            unused = "0.1.0"

            [lints.cargo]
            default = { level = "allow", priority = -1 }
            unused_dependencies = "warn"
        "#,
        )
        .file(
            "src/main.rs",
            r#"
            fn main() {}
            "#,
        )
        .build();

    p.cargo("check -Zcargo-lints")
        .masquerade_as_nightly_cargo(&["cargo-lints"])
        .with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 1 package to latest compatible version
[DOWNLOADING] crates ...
[DOWNLOADED] unused v0.1.0 (registry `dummy-registry`)
[CHECKING] unused v0.1.0
[CHECKING] foo v0.1.0 ([ROOT]/foo)
[WARNING] unused dependency
 --> Cargo.toml:9:13
  |
9 |             unused = "0.1.0"
  |             ^^^^^^^^^^^^^^^^
  |
  = [NOTE] `cargo::unused_dependencies` is set to `warn` in `[lints]`
[HELP] consider removing the unused dependency
[WARNING] `foo` (manifest) generated 1 warning
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]])
        .run();
}

#[cargo_test]
fn unused_dep_build() {
    Package::new("unused", "0.1.0").publish();
    let p = project()
        .file(
            "Cargo.toml",
            r#"
            [package]
            name = "foo"
            version = "0.1.0"
            authors = []
            edition = "2018"

            [build-dependencies]
            unused = "0.1.0"

            [lints.cargo]
            default = { level = "allow", priority = -1 }
            unused_dependencies = "warn"
        "#,
        )
        .file(
            "build.rs",
            r#"
            fn main() {}
            "#,
        )
        .file(
            "src/main.rs",
            r#"
            fn main() {}
            "#,
        )
        .build();

    p.cargo("check -Zcargo-lints")
        .masquerade_as_nightly_cargo(&["cargo-lints"])
        .with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 1 package to latest compatible version
[DOWNLOADING] crates ...
[DOWNLOADED] unused v0.1.0 (registry `dummy-registry`)
[COMPILING] unused v0.1.0
[COMPILING] foo v0.1.0 ([ROOT]/foo)
[WARNING] unused dependency
 --> Cargo.toml:9:13
  |
9 |             unused = "0.1.0"
  |             ^^^^^^^^^^^^^^^^
  |
  = [NOTE] `cargo::unused_dependencies` is set to `warn` in `[lints]`
[HELP] consider removing the unused dependency
[WARNING] `foo` (manifest) generated 1 warning
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]])
        .run();
}

#[cargo_test]
fn unused_dep_build_no_build_rs() {
    Package::new("unused", "0.1.0").publish();
    let p = project()
        .file(
            "Cargo.toml",
            r#"
            [package]
            name = "foo"
            version = "0.1.0"
            authors = []
            edition = "2018"

            [build-dependencies]
            unused = "0.1.0"

            [lints.cargo]
            default = { level = "allow", priority = -1 }
            unused_dependencies = "warn"
        "#,
        )
        .file(
            "src/main.rs",
            r#"
            fn main() {}
            "#,
        )
        .build();

    p.cargo("check -Zcargo-lints")
        .masquerade_as_nightly_cargo(&["cargo-lints"])
        .with_stderr_data(str![[r#"
[WARNING] unused dependency
 --> Cargo.toml:9:13
  |
9 |             unused = "0.1.0"
  |             ^^^^^^^^^^^^^^^^
  |
  = [NOTE] `cargo::unused_dependencies` is set to `warn` in `[lints]`
[HELP] consider removing the unused dependency
[WARNING] `foo` (manifest) generated 1 warning
[UPDATING] `dummy-registry` index
[LOCKING] 1 package to latest compatible version
[DOWNLOADING] crates ...
[DOWNLOADED] unused v0.1.0 (registry `dummy-registry`)
[CHECKING] foo v0.1.0 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]])
        .run();
}

#[cargo_test]
fn unused_dep_lib_bins() {
    // Make sure that dependency uses by both binaries and libraries
    // are being registered as used
    Package::new("unused", "0.1.0").publish();
    Package::new("lib_used", "0.1.0").publish();
    Package::new("bins_used", "0.1.0").publish();
    let p = project()
        .file(
            "Cargo.toml",
            r#"
            [package]
            name = "foo"
            version = "0.1.0"
            authors = []
            edition = "2018"

            [dependencies]
            unused = "0.1.0"
            lib_used = "0.1.0"
            bins_used = "0.1.0"

            [lints.cargo]
            default = { level = "allow", priority = -1 }
            unused_dependencies = "warn"
        "#,
        )
        .file(
            "src/lib.rs",
            r#"
            use lib_used as _;
            "#,
        )
        .file(
            "src/bin/foo.rs",
            r#"
            use bins_used as _;
            fn main() {}
            "#,
        )
        .file(
            "src/bin/bar.rs",
            r#"
            use bins_used as _;
            fn main() {}
            "#,
        )
        .build();

    p.cargo("check -Zcargo-lints")
        .masquerade_as_nightly_cargo(&["cargo-lints"])
        .with_stderr_data(
            str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 3 packages to latest compatible versions
[DOWNLOADING] crates ...
[DOWNLOADED] unused v0.1.0 (registry `dummy-registry`)
[DOWNLOADED] lib_used v0.1.0 (registry `dummy-registry`)
[DOWNLOADED] bins_used v0.1.0 (registry `dummy-registry`)
[CHECKING] bins_used v0.1.0
[CHECKING] unused v0.1.0
[CHECKING] lib_used v0.1.0
[CHECKING] foo v0.1.0 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[WARNING] unused dependency
 --> Cargo.toml:9:13
  |
9 |             unused = "0.1.0"
  |             ^^^^^^^^^^^^^^^^
  |
  = [NOTE] `cargo::unused_dependencies` is set to `warn` in `[lints]`
[HELP] consider removing the unused dependency
[WARNING] `foo` (manifest) generated 1 warning

"#]]
            .unordered(),
        )
        .run();

    p.cargo("check -Zcargo-lints --lib")
        .masquerade_as_nightly_cargo(&["cargo-lints"])
        .with_stderr_data(str![[r#"
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]])
        .run();

    p.cargo("check -Zcargo-lints --bins")
        .masquerade_as_nightly_cargo(&["cargo-lints"])
        .with_stderr_data(str![[r#"
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]])
        .run();

    p.cargo("check -Zcargo-lints --bin foo")
        .masquerade_as_nightly_cargo(&["cargo-lints"])
        .with_stderr_data(str![[r#"
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]])
        .run();
}

#[cargo_test]
fn unused_dep_build_with_used_dep_normal() {
    // Check sharing of a dependency
    // between build and proper deps
    Package::new("unused_build", "0.1.0").publish();
    let p = project()
        .file(
            "Cargo.toml",
            r#"
            [package]
            name = "foo"
            version = "0.1.0"
            authors = []
            edition = "2018"

            [build-dependencies]
            unused_build = "0.1.0"

            [dependencies]
            unused_build = "0.1.0"

            [lints.cargo]
            default = { level = "allow", priority = -1 }
            unused_dependencies = "warn"
        "#,
        )
        .file(
            "build.rs",
            r#"
            fn main() {}
            "#,
        )
        .file(
            "src/main.rs",
            r#"
            use unused_build as _;
            fn main() {}
            "#,
        )
        .build();

    p.cargo("check -Zcargo-lints")
        .masquerade_as_nightly_cargo(&["cargo-lints"])
        .with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 1 package to latest compatible version
[DOWNLOADING] crates ...
[DOWNLOADED] unused_build v0.1.0 (registry `dummy-registry`)
[COMPILING] unused_build v0.1.0
[COMPILING] foo v0.1.0 ([ROOT]/foo)
[WARNING] unused dependency
 --> Cargo.toml:9:13
  |
9 |             unused_build = "0.1.0"
  |             ^^^^^^^^^^^^^^^^^^^^^^
  |
  = [NOTE] `cargo::unused_dependencies` is set to `warn` in `[lints]`
[HELP] consider removing the unused dependency
[WARNING] `foo` (manifest) generated 1 warning
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]])
        .run();
}

#[cargo_test]
fn unused_dep_normal_but_implicit_used_dep_dev() {
    Package::new("used_dev", "0.1.0").publish();
    let p = project()
        .file(
            "Cargo.toml",
            r#"
            [package]
            name = "foo"
            version = "0.1.0"
            authors = []
            edition = "2018"

            [dependencies]
            used_dev = "0.1.0"

            [lints.cargo]
            default = { level = "allow", priority = -1 }
            unused_dependencies = "warn"
        "#,
        )
        .file(
            "src/main.rs",
            r#"
            fn main() {}
            "#,
        )
        .file(
            "tests/foo.rs",
            r#"
            #[test]
            fn foo() {
                use used_dev as _;
            }
            "#,
        )
        .build();

    p.cargo("check -Zcargo-lints")
        .masquerade_as_nightly_cargo(&["cargo-lints"])
        .with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 1 package to latest compatible version
[DOWNLOADING] crates ...
[DOWNLOADED] used_dev v0.1.0 (registry `dummy-registry`)
[CHECKING] used_dev v0.1.0
[CHECKING] foo v0.1.0 ([ROOT]/foo)
[WARNING] unused dependency
 --> Cargo.toml:9:13
  |
9 |             used_dev = "0.1.0"
  |             ^^^^^^^^^^^^^^^^^^
  |
  = [NOTE] `cargo::unused_dependencies` is set to `warn` in `[lints]`
[HELP] consider removing the unused dependency
[WARNING] `foo` (manifest) generated 1 warning
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]])
        .run();

    p.cargo("check -Zcargo-lints --all-targets")
        .masquerade_as_nightly_cargo(&["cargo-lints"])
        .with_stderr_data(str![[r#"
[CHECKING] foo v0.1.0 ([ROOT]/foo)
[WARNING] unused dependency
 --> Cargo.toml:9:13
  |
9 |             used_dev = "0.1.0"
  |             ^^^^^^^^^^^^^^^^^^
  |
  = [NOTE] `cargo::unused_dependencies` is set to `warn` in `[lints]`
[HELP] consider removing the unused dependency
[HELP] to still use for development builds, move to `dev-dependencies`
[WARNING] `foo` (manifest) generated 1 warning
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]])
        .run();
}

#[cargo_test]
fn unused_dep_normal_but_explicit_used_dep_dev() {
    Package::new("used_once", "0.1.0").publish();
    let p = project()
        .file(
            "Cargo.toml",
            r#"
            [package]
            name = "foo"
            version = "0.1.0"
            authors = []
            edition = "2018"

            [dependencies]
            used_once = "0.1.0"

            [dev-dependencies]
            used_once = "0.1.0"

            [lints.cargo]
            default = { level = "allow", priority = -1 }
            unused_dependencies = "warn"
        "#,
        )
        .file(
            "src/main.rs",
            r#"
            fn main() {}
            "#,
        )
        .file(
            "tests/foo.rs",
            r#"
            #[test]
            fn foo {
                use used_once as _;
            }
            "#,
        )
        .build();

    p.cargo("check -Zcargo-lints")
        .masquerade_as_nightly_cargo(&["cargo-lints"])
        .with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 1 package to latest compatible version
[DOWNLOADING] crates ...
[DOWNLOADED] used_once v0.1.0 (registry `dummy-registry`)
[CHECKING] used_once v0.1.0
[CHECKING] foo v0.1.0 ([ROOT]/foo)
[WARNING] unused dependency
 --> Cargo.toml:9:13
  |
9 |             used_once = "0.1.0"
  |             ^^^^^^^^^^^^^^^^^^^
  |
  = [NOTE] `cargo::unused_dependencies` is set to `warn` in `[lints]`
[HELP] consider removing the unused dependency
[WARNING] `foo` (manifest) generated 1 warning
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]])
        .run();
}

#[cargo_test]
fn unused_dep_dev_but_explicit_used_dep_normal() {
    Package::new("used_once", "0.1.0").publish();
    let p = project()
        .file(
            "Cargo.toml",
            r#"
            [package]
            name = "foo"
            version = "0.1.0"
            authors = []
            edition = "2018"

            [dependencies]
            used_once = "0.1.0"

            [dev-dependencies]
            used_once = "0.1.0"

            [lints.cargo]
            default = { level = "allow", priority = -1 }
            unused_dependencies = "warn"
        "#,
        )
        .file(
            "src/main.rs",
            r#"
            fn main() {
                use used_once as _;
            }
            "#,
        )
        .file(
            "tests/foo.rs",
            r#"
            #[test]
            fn foo {
            }
            "#,
        )
        .build();

    // No warning because the dependency is used at test time by the unit tests and the two
    // dependencies are indistinguishable
    p.cargo("check -Zcargo-lints")
        .masquerade_as_nightly_cargo(&["cargo-lints"])
        .with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 1 package to latest compatible version
[DOWNLOADING] crates ...
[DOWNLOADED] used_once v0.1.0 (registry `dummy-registry`)
[CHECKING] used_once v0.1.0
[CHECKING] foo v0.1.0 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]])
        .run();
}

#[cargo_test]
fn optional_dependency() {
    // The most basic case where there is an unused dependency
    Package::new("unused", "0.1.0").publish();
    Package::new("used", "0.1.0").publish();
    let p = project()
        .file(
            "Cargo.toml",
            r#"
            [package]
            name = "foo"
            version = "0.1.0"
            authors = []
            edition = "2018"

            [dependencies]
            unused = { version = "0.1.0", optional = true }
            used = { version = "0.1.0", optional = true }

            [lints.cargo]
            default = { level = "allow", priority = -1 }
            unused_dependencies = "warn"
        "#,
        )
        .file(
            "src/main.rs",
            r#"
            #[cfg(feature = "used")]
            use used as _;

            fn main() {}
            "#,
        )
        .build();

    p.cargo("check -Zcargo-lints")
        .masquerade_as_nightly_cargo(&["cargo-lints"])
        .with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 2 packages to latest compatible versions
[CHECKING] foo v0.1.0 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]])
        .run();

    p.cargo("check -Zcargo-lints -F used,unused")
        .masquerade_as_nightly_cargo(&["cargo-lints"])
        .with_stderr_data(
            str![[r#"
[DOWNLOADING] crates ...
[DOWNLOADED] used v0.1.0 (registry `dummy-registry`)
[DOWNLOADED] unused v0.1.0 (registry `dummy-registry`)
[CHECKING] unused v0.1.0
[CHECKING] used v0.1.0
[CHECKING] foo v0.1.0 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[WARNING] unused dependency
 --> Cargo.toml:9:13
  |
9 |             unused = { version = "0.1.0", optional = true }
  |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = [NOTE] `cargo::unused_dependencies` is set to `warn` in `[lints]`
[HELP] consider removing the unused dependency
[WARNING] `foo` (manifest) generated 1 warning

"#]]
            .unordered(),
        )
        .run();
}

#[cargo_test]
fn unused_dep_renamed() {
    // Make sure that package renaming works
    Package::new("bar", "0.1.0").publish();
    Package::new("baz", "0.2.0").publish();
    let p = project()
        .file(
            "Cargo.toml",
            r#"
            [package]
            name = "foo"
            version = "0.1.0"
            authors = []
            edition = "2018"

            [dependencies]
            baz = { package = "bar", version = "0.1.0" }
            bar = { package = "baz", version = "0.2.0" }

            [lints.cargo]
            default = { level = "allow", priority = -1 }
            unused_dependencies = "warn"
        "#,
        )
        .file(
            "src/main.rs",
            r#"
            use bar as _;
            fn main() {}
            "#,
        )
        .build();

    p.cargo("check -Zcargo-lints")
        .masquerade_as_nightly_cargo(&["cargo-lints"])
        .with_stderr_data(
            str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 2 packages to latest compatible versions
[DOWNLOADING] crates ...
[DOWNLOADED] baz v0.2.0 (registry `dummy-registry`)
[DOWNLOADED] bar v0.1.0 (registry `dummy-registry`)
[CHECKING] baz v0.2.0
[CHECKING] bar v0.1.0
[CHECKING] foo v0.1.0 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[WARNING] unused dependency
 --> Cargo.toml:9:13
  |
9 |             baz = { package = "bar", version = "0.1.0" }
  |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = [NOTE] `cargo::unused_dependencies` is set to `warn` in `[lints]`
[HELP] consider removing the unused dependency
[WARNING] `foo` (manifest) generated 1 warning

"#]]
            .unordered(),
        )
        .run();
}

#[cargo_test]
fn warning_replay() {
    // The most basic case where there is an unused dependency
    Package::new("unused", "0.1.0").publish();
    let p = project()
        .file(
            "Cargo.toml",
            r#"
            [package]
            name = "foo"
            version = "0.1.0"
            authors = []
            edition = "2018"

            [dependencies]
            unused = "0.1.0"

            [lints.cargo]
            default = { level = "allow", priority = -1 }
            unused_dependencies = "warn"
        "#,
        )
        .file(
            "src/main.rs",
            r#"
            fn main() {}
            "#,
        )
        .build();

    p.cargo("check -Zcargo-lints")
        .masquerade_as_nightly_cargo(&["cargo-lints"])
        .with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 1 package to latest compatible version
[DOWNLOADING] crates ...
[DOWNLOADED] unused v0.1.0 (registry `dummy-registry`)
[CHECKING] unused v0.1.0
[CHECKING] foo v0.1.0 ([ROOT]/foo)
[WARNING] unused dependency
 --> Cargo.toml:9:13
  |
9 |             unused = "0.1.0"
  |             ^^^^^^^^^^^^^^^^
  |
  = [NOTE] `cargo::unused_dependencies` is set to `warn` in `[lints]`
[HELP] consider removing the unused dependency
[WARNING] `foo` (manifest) generated 1 warning
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]])
        .run();

    p.cargo("check -Zcargo-lints")
        .masquerade_as_nightly_cargo(&["cargo-lints"])
        .with_stderr_data(str![[r#"
[WARNING] unused dependency
 --> Cargo.toml:9:13
  |
9 |             unused = "0.1.0"
  |             ^^^^^^^^^^^^^^^^
  |
  = [NOTE] `cargo::unused_dependencies` is set to `warn` in `[lints]`
[HELP] consider removing the unused dependency
[WARNING] `foo` (manifest) generated 1 warning
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]])
        .run();
}

#[cargo_test]
fn unused_dep_target() {
    // The most basic case where there is an unused dependency
    Package::new("unused", "0.1.0").publish();
    Package::new("used", "0.1.0").publish();
    let host = rustc_host();
    let p = project()
        .file(
            "Cargo.toml",
            &format!(
                r#"
            [package]
            name = "foo"
            version = "0.1.0"
            authors = []
            edition = "2018"

            [target.{host}.dependencies]
            unused = "0.1.0"
            used = "0.1.0"

            [lints.cargo]
            default = {{ level = "allow", priority = -1 }}
            unused_dependencies = "warn"
        "#
            ),
        )
        .file(
            "src/main.rs",
            r#"
            use used as _;
            fn main() {}
            "#,
        )
        .build();

    p.cargo(&format!("check -Zcargo-lints --target {host}"))
        .masquerade_as_nightly_cargo(&["cargo-lints"])
        .with_stderr_data(
            str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 2 packages to latest compatible versions
[DOWNLOADING] crates ...
[DOWNLOADED] used v0.1.0 (registry `dummy-registry`)
[DOWNLOADED] unused v0.1.0 (registry `dummy-registry`)
[CHECKING] unused v0.1.0
[CHECKING] used v0.1.0
[CHECKING] foo v0.1.0 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[WARNING] unused dependency
 --> Cargo.toml:9:13
  |
9 |             unused = "0.1.0"
  |             ^^^^^^^^^^^^^^^^
  |
  = [NOTE] `cargo::unused_dependencies` is set to `warn` in `[lints]`
[HELP] consider removing the unused dependency
[WARNING] `foo` (manifest) generated 1 warning

"#]]
            .unordered(),
        )
        .run();
}

#[cargo_test]
fn unused_dev_deps() {
    // Test for unused dev dependencies
    Package::new("unit_used", "0.1.0").publish();
    Package::new("doctest_used", "0.1.0").publish();
    Package::new("test_used", "0.1.0").publish();
    Package::new("example_used", "0.1.0").publish();
    Package::new("bench_used", "0.1.0").publish();
    Package::new("unused", "0.1.0").publish();
    let p = project()
        .file(
            "Cargo.toml",
            r#"
            [package]
            name = "foo"
            version = "0.1.0"
            authors = []
            edition = "2018"

            [dev-dependencies]
            unit_used = "0.1.0"
            doctest_used = "0.1.0"
            test_used = "0.1.0"
            example_used = "0.1.0"
            bench_used = "0.1.0"
            unused = "0.1.0"

            [lints.cargo]
            default = { level = "allow", priority = -1 }
            unused_dependencies = "warn"
        "#,
        )
        .file(
            "src/lib.rs",
            r#"
            /// ```
            /// use doctest_used as _;
            /// ```
            pub fn foo() {}

            #[test]
            fn test() {
                use unit_used as _;
            }
        "#,
        )
        .file(
            "tests/hello.rs",
            r#"
            use test_used as _;
            "#,
        )
        .file(
            "examples/hello.rs",
            r#"
            use example_used as _;
            fn main() {}
            "#,
        )
        .file(
            "benches/hello.rs",
            r#"
            use bench_used as _;
            fn main() {}
            "#,
        )
        .build();

    // doesn't check any tests, still no unused dev dep warnings
    p.cargo("check -Zcargo-lints")
        .masquerade_as_nightly_cargo(&["cargo-lints"])
        .with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 6 packages to latest compatible versions
[CHECKING] foo v0.1.0 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]])
        .run();

    // doesn't check doctests, still no unused dev dep warnings
    p.cargo("check -Zcargo-lints --all-targets")
        .masquerade_as_nightly_cargo(&["cargo-lints"])
        .with_stderr_data(
            str![[r#"
[DOWNLOADING] crates ...
[DOWNLOADED] unused v0.1.0 (registry `dummy-registry`)
[DOWNLOADED] unit_used v0.1.0 (registry `dummy-registry`)
[DOWNLOADED] test_used v0.1.0 (registry `dummy-registry`)
[DOWNLOADED] example_used v0.1.0 (registry `dummy-registry`)
[DOWNLOADED] doctest_used v0.1.0 (registry `dummy-registry`)
[DOWNLOADED] bench_used v0.1.0 (registry `dummy-registry`)
[CHECKING] bench_used v0.1.0
[CHECKING] unused v0.1.0
[CHECKING] doctest_used v0.1.0
[CHECKING] example_used v0.1.0
[CHECKING] unit_used v0.1.0
[CHECKING] test_used v0.1.0
[CHECKING] foo v0.1.0 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]]
            .unordered(),
        )
        .run();

    // doesn't test doctests and benches and thus doesn't create unused dev dep warnings
    p.cargo("test -Zcargo-lints --no-run")
        .masquerade_as_nightly_cargo(&["cargo-lints"])
        .with_stderr_data(
            str![[r#"
[COMPILING] example_used v0.1.0
[COMPILING] unit_used v0.1.0
[COMPILING] unused v0.1.0
[COMPILING] test_used v0.1.0
[COMPILING] bench_used v0.1.0
[COMPILING] doctest_used v0.1.0
[COMPILING] foo v0.1.0 ([ROOT]/foo)
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[EXECUTABLE] unittests src/lib.rs (target/debug/deps/foo-[HASH][EXE])
[EXECUTABLE] tests/hello.rs (target/debug/deps/hello-[HASH][EXE])

"#]]
            .unordered(),
        )
        .run();

    // doesn't test doctests, still no unused dev dep warnings
    p.cargo("test -Zcargo-lints --no-run --all-targets")
        .masquerade_as_nightly_cargo(&["cargo-lints"])
        .with_stderr_data(str![[r#"
[COMPILING] foo v0.1.0 ([ROOT]/foo)
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[EXECUTABLE] unittests src/lib.rs (target/debug/deps/foo-[HASH][EXE])
[EXECUTABLE] tests/hello.rs (target/debug/deps/hello-[HASH][EXE])
[EXECUTABLE] benches/hello.rs (target/debug/deps/hello-[HASH][EXE])
[EXECUTABLE] unittests examples/hello.rs (target/debug/examples/hello-[HASH][EXE])

"#]])
        .run();

    // tests everything including doctests, but not
    // the benches
    p.cargo("test -Zcargo-lints")
        .masquerade_as_nightly_cargo(&["cargo-lints"])
        .with_stderr_data(str![[r#"
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] unittests src/lib.rs (target/debug/deps/foo-[HASH][EXE])
[RUNNING] tests/hello.rs (target/debug/deps/hello-[HASH][EXE])
[DOCTEST] foo

"#]])
        .run();
}

#[cargo_test]
fn package_selection() {
    // Make sure that workspaces are supported,
    // --all params, -p params, etc.
    Package::new("used_bar", "0.1.0").publish();
    Package::new("used_foo", "0.1.0").publish();
    Package::new("used_external", "0.1.0").publish();
    Package::new("unused_bar", "0.1.0").publish();
    Package::new("unused_foo", "0.1.0").publish();
    Package::new("unused_external", "0.1.0").publish();
    let p = project()
        .file(
            "Cargo.toml",
            r#"
            [workspace]
            members = ["foo", "bar"]
            exclude = ["external"]
        "#,
        )
        .file(
            "foo/Cargo.toml",
            r#"
            [package]
            name = "foo"
            version = "0.1.0"
            authors = []
            edition = "2018"

            [dependencies]
            unused_foo = "0.1.0"
            used_foo = "0.1.0"
            bar.path = "../bar"
            external.path = "../external"

            [lints.cargo]
            default = { level = "allow", priority = -1 }
            unused_dependencies = "warn"
            "#,
        )
        .file(
            "foo/src/lib.rs",
            r#"
            use used_foo as _;
            "#,
        )
        .file(
            "bar/Cargo.toml",
            r#"
            [package]
            name = "bar"
            version = "0.1.0"
            authors = []
            edition = "2018"

            [dependencies]
            unused_bar = "0.1.0"
            used_bar = "0.1.0"

            [lints.cargo]
            default = { level = "allow", priority = -1 }
            unused_dependencies = "warn"
            "#,
        )
        .file(
            "bar/src/lib.rs",
            r#"
            use used_bar as _;
            "#,
        )
        .file(
            "external/Cargo.toml",
            r#"
            [package]
            name = "external"
            version = "0.1.0"
            authors = []
            edition = "2018"

            [dependencies]
            unused_external = "0.1.0"
            used_external = "0.1.0"

            [lints.cargo]
            default = { level = "allow", priority = -1 }
            unused_dependencies = "warn"
            "#,
        )
        .file(
            "external/src/lib.rs",
            r#"
            use used_external as _;
            "#,
        )
        .build();

    p.cargo("check -Zcargo-lints")
        .masquerade_as_nightly_cargo(&["cargo-lints"])
        .with_stderr_data(
            str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 7 packages to latest compatible versions
[DOWNLOADING] crates ...
[DOWNLOADED] unused_bar v0.1.0 (registry `dummy-registry`)
[DOWNLOADED] unused_external v0.1.0 (registry `dummy-registry`)
[DOWNLOADED] unused_foo v0.1.0 (registry `dummy-registry`)
[DOWNLOADED] used_bar v0.1.0 (registry `dummy-registry`)
[DOWNLOADED] used_external v0.1.0 (registry `dummy-registry`)
[DOWNLOADED] used_foo v0.1.0 (registry `dummy-registry`)
[CHECKING] used_bar v0.1.0
[CHECKING] unused_external v0.1.0
[CHECKING] used_external v0.1.0
[CHECKING] unused_bar v0.1.0
[CHECKING] used_foo v0.1.0
[CHECKING] unused_foo v0.1.0
[CHECKING] bar v0.1.0 ([ROOT]/foo/bar)
[CHECKING] external v0.1.0 ([ROOT]/foo/external)
[CHECKING] foo v0.1.0 ([ROOT]/foo/foo)
[WARNING] unused dependency
 --> bar/Cargo.toml:9:13
  |
9 |             unused_bar = "0.1.0"
  |             ^^^^^^^^^^^^^^^^^^^^
  |
  = [NOTE] `cargo::unused_dependencies` is set to `warn` in `[lints]`
[HELP] consider removing the unused dependency
  |
  |
[WARNING] unused dependency
  --> foo/Cargo.toml:11:13
   |
11 |             bar.path = "../bar"
   |             ^^^
   |
   = [NOTE] `cargo::unused_dependencies` is set to `warn` in `[lints]`
[HELP] consider removing the unused dependency
   |
   |
[WARNING] unused dependency
  --> foo/Cargo.toml:12:13
12 |             external.path = "../external"
   |             ^^^^^^^^
[HELP] consider removing the unused dependency
[WARNING] unused dependency
 --> foo/Cargo.toml:9:13
9 |             unused_foo = "0.1.0"
  |             ^^^^^^^^^^^^^^^^^^^^
[HELP] consider removing the unused dependency
[WARNING] `bar` (manifest) generated 1 warning
[WARNING] `foo` (manifest) generated 3 warnings
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]]
            .unordered(),
        )
        .run();

    p.cargo("check -Zcargo-lints -p foo")
        .masquerade_as_nightly_cargo(&["cargo-lints"])
        .with_stderr_data(
            str![[r#"
[WARNING] unused dependency
  --> foo/Cargo.toml:11:13
   |
11 |             bar.path = "../bar"
   |             ^^^
   |
   = [NOTE] `cargo::unused_dependencies` is set to `warn` in `[lints]`
[HELP] consider removing the unused dependency
   |
   |
[WARNING] unused dependency
  --> foo/Cargo.toml:12:13
12 |             external.path = "../external"
   |             ^^^^^^^^
[HELP] consider removing the unused dependency
[WARNING] unused dependency
 --> foo/Cargo.toml:9:13
  |
9 |             unused_foo = "0.1.0"
  |             ^^^^^^^^^^^^^^^^^^^^
  |
[HELP] consider removing the unused dependency
[WARNING] `foo` (manifest) generated 3 warnings
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]]
            .unordered(),
        )
        .run();

    p.cargo("check -Zcargo-lints -p bar")
        .masquerade_as_nightly_cargo(&["cargo-lints"])
        .with_stderr_data(
            str![[r#"
[WARNING] unused dependency
 --> bar/Cargo.toml:9:13
  |
9 |             unused_bar = "0.1.0"
  |             ^^^^^^^^^^^^^^^^^^^^
  |
  = [NOTE] `cargo::unused_dependencies` is set to `warn` in `[lints]`
[HELP] consider removing the unused dependency
[WARNING] `bar` (manifest) generated 1 warning
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]]
            .unordered(),
        )
        .run();
}

#[cargo_test]
fn pinned_transitive_dep() {
    // The most basic case where there is an unused dependency
    Package::new("transitive", "0.1.0")
        .file("src/lib.rs", "pub fn fun() {}")
        .publish();
    Package::new("transitive", "0.1.1")
        .file("src/lib.rs", "pub fn fun() {}")
        .publish();
    Package::new("intermediate", "0.1.0")
        .dep("transitive", "0.1")
        .file("src/lib.rs", "pub fn fun() { transitive::fun(); }")
        .publish();
    let p = project()
        .file(
            "Cargo.toml",
            r#"
            [package]
            name = "foo"
            version = "0.1.0"
            authors = []
            edition = "2018"

            [dependencies]
            intermediate = "0.1.0"

            [target."cfg(false)".dependencies]
            transitive = "=0.1.1"

            [lints.cargo]
            default = { level = "allow", priority = -1 }
            unused_dependencies = "warn"
        "#,
        )
        .file(
            "src/main.rs",
            r#"
            fn main() { intermediate::fun(); }
            "#,
        )
        .build();

    p.cargo("check -Zcargo-lints")
        .masquerade_as_nightly_cargo(&["cargo-lints"])
        .with_stderr_data(
            str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 2 packages to latest compatible versions
[DOWNLOADING] crates ...
[DOWNLOADED] intermediate v0.1.0 (registry `dummy-registry`)
[DOWNLOADED] transitive v0.1.1 (registry `dummy-registry`)
[CHECKING] transitive v0.1.1
[CHECKING] intermediate v0.1.0
[CHECKING] foo v0.1.0 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]]
            .unordered(),
        )
        .run();
}

#[cargo_test]
fn activated_transitive_dep() {
    // The most basic case where there is an unused dependency
    Package::new("transitive", "0.1.1")
        .feature("a", &[])
        .file(
            "src/lib.rs",
            r#"
pub fn fun() -> &'static str {
    #[cfg(feature = "a")]
    {
        "a"
    }
    #[cfg(not(feature = "a"))]
    {
        "not a"
    }
}
"#,
        )
        .publish();
    Package::new("intermediate", "0.1.0")
        .dep("transitive", "0.1")
        .file(
            "src/lib.rs",
            "pub fn fun() -> &'static str { transitive::fun() }",
        )
        .publish();
    let p = project()
        .file(
            "Cargo.toml",
            r#"
            [package]
            name = "foo"
            version = "0.1.0"
            authors = []
            edition = "2018"

            [dependencies]
            intermediate = "0.1.0"
            transitive = { version = "0.1.1", features = ["a"] }

            [lints.cargo]
            default = { level = "allow", priority = -1 }
            unused_dependencies = "warn"
        "#,
        )
        .file(
            "src/main.rs",
            r#"
            fn main() { assert_eq!(intermediate::fun(), "a"); }
            "#,
        )
        .build();

    p.cargo("check -Zcargo-lints")
        .masquerade_as_nightly_cargo(&["cargo-lints"])
        .with_stderr_data(
            str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 2 packages to latest compatible versions
[DOWNLOADING] crates ...
[DOWNLOADED] intermediate v0.1.0 (registry `dummy-registry`)
[DOWNLOADED] transitive v0.1.1 (registry `dummy-registry`)
[CHECKING] transitive v0.1.1
[CHECKING] intermediate v0.1.0
[CHECKING] foo v0.1.0 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]]
            .unordered(),
        )
        .run();
}

#[cargo_test]
fn allow_rustflags() {
    // The most basic case where there is an unused dependency
    Package::new("unused", "0.1.0").publish();
    let p = project()
        .file(
            "Cargo.toml",
            r#"
            [package]
            name = "foo"
            version = "0.1.0"
            authors = []
            edition = "2018"

            [dependencies]
            unused = "0.1.0"

            [lints.cargo]
            default = { level = "allow", priority = -1 }
            unused_dependencies = "warn"
        "#,
        )
        .file(
            "src/main.rs",
            r#"
            fn main() {}
            "#,
        )
        .build();

    p.cargo("check -Zcargo-lints")
        .env("RUSTFLAGS", "-Aunused_crate_dependencies")
        .masquerade_as_nightly_cargo(&["cargo-lints"])
        .with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 1 package to latest compatible version
[DOWNLOADING] crates ...
[DOWNLOADED] unused v0.1.0 (registry `dummy-registry`)
[CHECKING] unused v0.1.0
[CHECKING] foo v0.1.0 ([ROOT]/foo)
[WARNING] unused dependency
 --> Cargo.toml:9:13
  |
9 |             unused = "0.1.0"
  |             ^^^^^^^^^^^^^^^^
  |
  = [NOTE] `cargo::unused_dependencies` is set to `warn` in `[lints]`
[HELP] consider removing the unused dependency
[WARNING] `foo` (manifest) generated 1 warning
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]])
        .run();
}

#[cargo_test]
fn allow_attribute() {
    // The most basic case where there is an unused dependency
    Package::new("unused", "0.1.0").publish();
    let p = project()
        .file(
            "Cargo.toml",
            r#"
            [package]
            name = "foo"
            version = "0.1.0"
            authors = []
            edition = "2018"

            [dependencies]
            unused = "0.1.0"

            [lints.cargo]
            default = { level = "allow", priority = -1 }
            unused_dependencies = "warn"
        "#,
        )
        .file(
            "src/main.rs",
            r#"
            #![allow(unused_crate_dependencies)]
            fn main() {}
            "#,
        )
        .build();

    p.cargo("check -Zcargo-lints")
        .masquerade_as_nightly_cargo(&["cargo-lints"])
        .with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 1 package to latest compatible version
[DOWNLOADING] crates ...
[DOWNLOADED] unused v0.1.0 (registry `dummy-registry`)
[CHECKING] unused v0.1.0
[CHECKING] foo v0.1.0 ([ROOT]/foo)
[WARNING] unused dependency
 --> Cargo.toml:9:13
  |
9 |             unused = "0.1.0"
  |             ^^^^^^^^^^^^^^^^
  |
  = [NOTE] `cargo::unused_dependencies` is set to `warn` in `[lints]`
[HELP] consider removing the unused dependency
[WARNING] `foo` (manifest) generated 1 warning
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]])
        .run();
}

#[cargo_test]
fn deny_in_manifest() {
    // The most basic case where there is an unused dependency
    Package::new("unused", "0.1.0").publish();
    let p = project()
        .file(
            "Cargo.toml",
            r#"
            [package]
            name = "foo"
            version = "0.1.0"
            authors = []
            edition = "2018"

            [dependencies]
            unused = "0.1.0"

            [lints.cargo]
            unused_dependencies = "deny"
        "#,
        )
        .file(
            "src/main.rs",
            r#"
            fn main() {}
            "#,
        )
        .build();

    p.cargo("check -Zcargo-lints")
        .masquerade_as_nightly_cargo(&["cargo-lints"])
        .with_status(101)
        .with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 1 package to latest compatible version
[DOWNLOADING] crates ...
[DOWNLOADED] unused v0.1.0 (registry `dummy-registry`)
[CHECKING] unused v0.1.0
[CHECKING] foo v0.1.0 ([ROOT]/foo)
[ERROR] unused dependency
 --> Cargo.toml:9:13
  |
9 |             unused = "0.1.0"
  |             ^^^^^^^^^^^^^^^^
  |
  = [NOTE] `cargo::unused_dependencies` is set to `deny` in `[lints]`
[HELP] consider removing the unused dependency
[ERROR] could not finalize `foo` (manifest) due to 1 previous error

"#]])
        .run();
}

#[cargo_test]
fn deny_rustflags() {
    // The most basic case where there is an unused dependency
    Package::new("unused", "0.1.0").publish();
    let p = project()
        .file(
            "Cargo.toml",
            r#"
            [package]
            name = "foo"
            version = "0.1.0"
            authors = []
            edition = "2018"

            [dependencies]
            unused = "0.1.0"

            [lints.cargo]
            default = { level = "allow", priority = -1 }
            unused_dependencies = "warn"
        "#,
        )
        .file(
            "src/main.rs",
            r#"
            fn main() {}
            "#,
        )
        .build();

    p.cargo("check -Zcargo-lints")
        .env("RUSTFLAGS", "-Dunused_crate_dependencies")
        .masquerade_as_nightly_cargo(&["cargo-lints"])
        .with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 1 package to latest compatible version
[DOWNLOADING] crates ...
[DOWNLOADED] unused v0.1.0 (registry `dummy-registry`)
[CHECKING] unused v0.1.0
[CHECKING] foo v0.1.0 ([ROOT]/foo)
[WARNING] unused dependency
 --> Cargo.toml:9:13
  |
9 |             unused = "0.1.0"
  |             ^^^^^^^^^^^^^^^^
  |
  = [NOTE] `cargo::unused_dependencies` is set to `warn` in `[lints]`
[HELP] consider removing the unused dependency
[WARNING] `foo` (manifest) generated 1 warning
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]])
        .run();
}

#[cargo_test]
fn deny_attribute() {
    // The most basic case where there is an unused dependency
    Package::new("unused", "0.1.0").publish();
    let p = project()
        .file(
            "Cargo.toml",
            r#"
            [package]
            name = "foo"
            version = "0.1.0"
            authors = []
            edition = "2018"

            [dependencies]
            unused = "0.1.0"

            [lints.cargo]
            default = { level = "allow", priority = -1 }
            unused_dependencies = "warn"
        "#,
        )
        .file(
            "src/main.rs",
            r#"
            #![deny(unused_crate_dependencies)]
            fn main() {}
            "#,
        )
        .build();

    p.cargo("check -Zcargo-lints")
        .masquerade_as_nightly_cargo(&["cargo-lints"])
        .with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 1 package to latest compatible version
[DOWNLOADING] crates ...
[DOWNLOADED] unused v0.1.0 (registry `dummy-registry`)
[CHECKING] unused v0.1.0
[CHECKING] foo v0.1.0 ([ROOT]/foo)
[WARNING] unused dependency
 --> Cargo.toml:9:13
  |
9 |             unused = "0.1.0"
  |             ^^^^^^^^^^^^^^^^
  |
  = [NOTE] `cargo::unused_dependencies` is set to `warn` in `[lints]`
[HELP] consider removing the unused dependency
[WARNING] `foo` (manifest) generated 1 warning
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]])
        .run();
}

#[cargo_test]
fn forbid_rustflags() {
    // The most basic case where there is an unused dependency
    Package::new("unused", "0.1.0").publish();
    let p = project()
        .file(
            "Cargo.toml",
            r#"
            [package]
            name = "foo"
            version = "0.1.0"
            authors = []
            edition = "2018"

            [dependencies]
            unused = "0.1.0"

            [lints.cargo]
            default = { level = "allow", priority = -1 }
            unused_dependencies = "warn"
        "#,
        )
        .file(
            "src/main.rs",
            r#"
            fn main() {}
            "#,
        )
        .build();

    p.cargo("check -Zcargo-lints")
        .env("RUSTFLAGS", "-Funused_crate_dependencies")
        .masquerade_as_nightly_cargo(&["cargo-lints"])
        .with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 1 package to latest compatible version
[DOWNLOADING] crates ...
[DOWNLOADED] unused v0.1.0 (registry `dummy-registry`)
[CHECKING] unused v0.1.0
[CHECKING] foo v0.1.0 ([ROOT]/foo)
[WARNING] unused dependency
 --> Cargo.toml:9:13
  |
9 |             unused = "0.1.0"
  |             ^^^^^^^^^^^^^^^^
  |
  = [NOTE] `cargo::unused_dependencies` is set to `warn` in `[lints]`
[HELP] consider removing the unused dependency
[WARNING] `foo` (manifest) generated 1 warning
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]])
        .run();
}

#[cargo_test]
fn forbid_attribute() {
    // The most basic case where there is an unused dependency
    Package::new("unused", "0.1.0").publish();
    let p = project()
        .file(
            "Cargo.toml",
            r#"
            [package]
            name = "foo"
            version = "0.1.0"
            authors = []
            edition = "2018"

            [dependencies]
            unused = "0.1.0"

            [lints.cargo]
            default = { level = "allow", priority = -1 }
            unused_dependencies = "warn"
        "#,
        )
        .file(
            "src/main.rs",
            r#"
            #![forbid(unused_crate_dependencies)]
            fn main() {}
            "#,
        )
        .build();

    p.cargo("check -Zcargo-lints")
        .masquerade_as_nightly_cargo(&["cargo-lints"])
        .with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 1 package to latest compatible version
[DOWNLOADING] crates ...
[DOWNLOADED] unused v0.1.0 (registry `dummy-registry`)
[CHECKING] unused v0.1.0
[CHECKING] foo v0.1.0 ([ROOT]/foo)
[WARNING] unused dependency
 --> Cargo.toml:9:13
  |
9 |             unused = "0.1.0"
  |             ^^^^^^^^^^^^^^^^
  |
  = [NOTE] `cargo::unused_dependencies` is set to `warn` in `[lints]`
[HELP] consider removing the unused dependency
[WARNING] `foo` (manifest) generated 1 warning
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]])
        .run();
}
