use crate::prelude::*;
use cargo_test_support::project;
use cargo_test_support::str;

#[cargo_test]
fn with_repo() {
    let p = project()
        .file(
            "Cargo.toml",
            r#"
[package]
name = "cargo"
version = "0.0.1"
edition = "2015"
repository = "https://github.com/rust-lang/cargo/"
homepage = "https://github.com/rust-lang/cargo/"

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

    p.cargo("fetch -Zcargo-lints")
        .masquerade_as_nightly_cargo(&["cargo-lints"])
        .with_stderr_data(str![[r#"
[WARNING] `package.homepage` is redundant with another manifest field
 --> Cargo.toml:7:12
  |
6 | repository = "https://github.com/rust-lang/cargo/"
  |              -------------------------------------
7 | homepage = "https://github.com/rust-lang/cargo/"
  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = [NOTE] `cargo::redundant_homepage` is set to `warn` in `[lints]`
[HELP] consider removing `package.homepage`
[WARNING] `cargo` (manifest) generated 1 warning

"#]])
        .run();
}

#[cargo_test]
fn with_docs() {
    let p = project()
        .file(
            "Cargo.toml",
            r#"
[package]
name = "cargo"
version = "0.0.1"
edition = "2015"
documentation = "https://docs.rs/cargo/latest/cargo/"
homepage = "https://docs.rs/cargo/latest/cargo/"

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

    p.cargo("fetch -Zcargo-lints")
        .masquerade_as_nightly_cargo(&["cargo-lints"])
        .with_stderr_data(str![[r#"
[WARNING] `package.homepage` is redundant with another manifest field
 --> Cargo.toml:7:12
  |
6 | documentation = "https://docs.rs/cargo/latest/cargo/"
  |                 -------------------------------------
7 | homepage = "https://docs.rs/cargo/latest/cargo/"
  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = [NOTE] `cargo::redundant_homepage` is set to `warn` in `[lints]`
[HELP] consider removing `package.homepage`
[WARNING] `cargo` (manifest) generated 1 warning

"#]])
        .run();
}

#[cargo_test]
fn inherited() {
    let p = project()
        .file(
            "Cargo.toml",
            r#"
[workspace.package]
documentation = "https://docs.rs/cargo/latest/cargo/"
homepage = "https://docs.rs/cargo/latest/cargo/"

[package]
name = "cargo"
version = "0.0.1"
edition = "2015"
documentation.workspace = true
homepage.workspace = true

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

    p.cargo("fetch -Zcargo-lints")
        .masquerade_as_nightly_cargo(&["cargo-lints"])
        .with_stderr_data(str![[r#"
[WARNING] `package.homepage` is redundant with another manifest field
  --> Cargo.toml:11:1
   |
10 | documentation.workspace = true
   | -------------
11 | homepage.workspace = true
   | ^^^^^^^^
   |
   = [NOTE] `cargo::redundant_homepage` is set to `warn` in `[lints]`
[HELP] consider removing `package.homepage`
[WARNING] `cargo` (manifest) generated 1 warning

"#]])
        .run();
}
