From c23a457e72abe608715ac76f076f47dc42af07a5 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 30 May 2024 20:31:44 +0200 Subject: Merging upstream version 1.74.1+dfsg1. Signed-off-by: Daniel Baumann --- src/tools/cargo/tests/testsuite/lints.rs | 197 +++++++++++++------------------ 1 file changed, 82 insertions(+), 115 deletions(-) (limited to 'src/tools/cargo/tests/testsuite/lints.rs') diff --git a/src/tools/cargo/tests/testsuite/lints.rs b/src/tools/cargo/tests/testsuite/lints.rs index 854de69e9..21139d00a 100644 --- a/src/tools/cargo/tests/testsuite/lints.rs +++ b/src/tools/cargo/tests/testsuite/lints.rs @@ -3,72 +3,6 @@ use cargo_test_support::project; use cargo_test_support::registry::Package; -#[cargo_test] -fn package_requires_option() { - let foo = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.0.1" - authors = [] - - [lints.rust] - unsafe_code = "forbid" - "#, - ) - .file("src/lib.rs", "") - .build(); - - foo.cargo("check") - .with_stderr( - "\ -warning: unused manifest key `lints` (may be supported in a future version) - -this Cargo does not support nightly features, but if you -switch to nightly channel you can pass -`-Zlints` to enable this feature. -[CHECKING] [..] -[FINISHED] [..] -", - ) - .run(); -} - -#[cargo_test] -fn workspace_requires_option() { - let foo = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.0.1" - authors = [] - - [workspace.lints.rust] - unsafe_code = "forbid" - "#, - ) - .file("src/lib.rs", "") - .build(); - - foo.cargo("check") - .with_stderr( - "\ -warning: [CWD]/Cargo.toml: unused manifest key `lints` (may be supported in a future version) - -this Cargo does not support nightly features, but if you -switch to nightly channel you can pass -`-Zlints` to enable this feature. -[CHECKING] [..] -[FINISHED] [..] -", - ) - .run(); -} - #[cargo_test] fn dependency_warning_ignored() { let foo = project() @@ -133,53 +67,55 @@ fn malformed_on_stable() { .build(); foo.cargo("check") + .with_status(101) .with_stderr( "\ -warning: unused manifest key `lints` (may be supported in a future version) +error: failed to parse manifest[..] -this Cargo does not support nightly features, but if you -switch to nightly channel you can pass -`-Zlints` to enable this feature. -[CHECKING] [..] -[FINISHED] [..] +Caused by: + TOML parse error at line 2, column 25 + | + 2 | lints = 20 + | ^^ + invalid type: integer `20`, expected a lints table ", ) .run(); } #[cargo_test] -fn malformed_on_nightly() { +fn fail_on_invalid_tool() { let foo = project() .file( "Cargo.toml", r#" - lints = 20 [package] name = "foo" version = "0.0.1" authors = [] + [workspace.lints.super-awesome-linter] + unsafe_code = "forbid" "#, ) .file("src/lib.rs", "") .build(); - foo.cargo("check -Zlints") - .masquerade_as_nightly_cargo(&["lints"]) + foo.cargo("check") .with_status(101) .with_stderr( "\ -error: failed to parse manifest[..] +[..] Caused by: - invalid type: integer `20`, expected a map + unsupported `super-awesome-linter` in `[lints]`, must be one of rust, clippy, rustdoc ", ) .run(); } #[cargo_test] -fn fail_on_invalid_tool() { +fn invalid_type_in_lint_value() { let foo = project() .file( "Cargo.toml", @@ -187,24 +123,26 @@ fn fail_on_invalid_tool() { [package] name = "foo" version = "0.0.1" - authors = [] - [workspace.lints.super-awesome-linter] - unsafe_code = "forbid" + [workspace.lints.rust] + rust-2018-idioms = -1 "#, ) .file("src/lib.rs", "") .build(); - foo.cargo("check -Zlints") - .masquerade_as_nightly_cargo(&["lints"]) + foo.cargo("check") .with_status(101) .with_stderr( "\ -[..] +error: failed to parse manifest at `[..]/Cargo.toml` Caused by: - unsupported `super-awesome-linter` in `[lints]`, must be one of rust, clippy, rustdoc + TOML parse error at line 7, column 36 + | + 7 | rust-2018-idioms = -1 + | ^^ + invalid type: integer `-1`, expected a string or map ", ) .run(); @@ -228,8 +166,7 @@ fn fail_on_tool_injection() { .file("src/lib.rs", "") .build(); - foo.cargo("check -Zlints") - .masquerade_as_nightly_cargo(&["lints"]) + foo.cargo("check") .with_status(101) .with_stderr( "\ @@ -260,8 +197,7 @@ fn fail_on_redundant_tool() { .file("src/lib.rs", "") .build(); - foo.cargo("check -Zlints") - .masquerade_as_nightly_cargo(&["lints"]) + foo.cargo("check") .with_status(101) .with_stderr( "\ @@ -292,8 +228,7 @@ fn fail_on_conflicting_tool() { .file("src/lib.rs", "") .build(); - foo.cargo("check -Zlints") - .masquerade_as_nightly_cargo(&["lints"]) + foo.cargo("check") .with_status(101) .with_stderr( "\ @@ -331,8 +266,7 @@ pub fn foo(num: i32) -> u32 { ) .build(); - foo.cargo("check -Zlints") - .masquerade_as_nightly_cargo(&["lints"]) + foo.cargo("check") .with_status(101) .with_stderr_contains( "\ @@ -370,8 +304,7 @@ pub fn foo(num: i32) -> u32 { ) .build(); - foo.cargo("check -Zlints") - .masquerade_as_nightly_cargo(&["lints"]) + foo.cargo("check") .with_status(101) .with_stderr_contains( "\ @@ -381,6 +314,49 @@ error: usage of an `unsafe` block .run(); } +#[cargo_test] +fn workspace_and_package_lints() { + let foo = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + + [lints] + workspace = true + [lints.rust] + "unsafe_code" = "allow" + + [workspace.lints.rust] + "unsafe_code" = "deny" + "#, + ) + .file( + "src/lib.rs", + " +pub fn foo(num: i32) -> u32 { + unsafe { std::mem::transmute(num) } +} +", + ) + .build(); + + foo.cargo("check") + .with_status(101) + .with_stderr( + "\ +[ERROR] failed to parse manifest at `[CWD]/Cargo.toml` + +Caused by: + cannot override `workspace.lints` in `lints`, either remove the overrides or `lints.workspace = true` and manually specify the lints +", + ) + .run(); +} + #[cargo_test] fn attribute_has_precedence() { let foo = project() @@ -408,9 +384,8 @@ pub fn foo(num: i32) -> u32 { ) .build(); - foo.cargo("check -Zlints") + foo.cargo("check") .arg("-v") // Show order of rustflags on failure - .masquerade_as_nightly_cargo(&["lints"]) .run(); } @@ -439,10 +414,9 @@ pub fn foo(num: i32) -> u32 { ) .build(); - foo.cargo("check -Zlints") + foo.cargo("check") .arg("-v") // Show order of rustflags on failure .env("RUSTFLAGS", "-Aunsafe_code") - .masquerade_as_nightly_cargo(&["lints"]) .run(); } @@ -475,9 +449,9 @@ pub fn foo(num: i32) -> u32 { ) .build(); - foo.cargo("check -Zlints") + foo.cargo("check") .arg("-v") // Show order of rustflags on failure - .masquerade_as_nightly_cargo(&["lints", "profile-rustflags"]) + .masquerade_as_nightly_cargo(&["profile-rustflags"]) .run(); } @@ -512,9 +486,8 @@ pub fn foo(num: i32) -> u32 { ) .build(); - foo.cargo("check -Zlints") + foo.cargo("check") .arg("-v") // Show order of rustflags on failure - .masquerade_as_nightly_cargo(&["lints"]) .run(); } @@ -552,8 +525,7 @@ pub fn foo() -> u32 { ) .build(); - foo.cargo("check -Zlints") - .masquerade_as_nightly_cargo(&["lints"]) + foo.cargo("check") .with_status(101) .with_stderr_contains( "\ @@ -597,9 +569,7 @@ pub fn foo() -> u32 { ) .build(); - foo.cargo("check -Zlints") - .masquerade_as_nightly_cargo(&["lints"]) - .run(); + foo.cargo("check").run(); } #[cargo_test] @@ -627,8 +597,7 @@ pub fn foo() -> u32 { ) .build(); - foo.cargo("doc -Zlints") - .masquerade_as_nightly_cargo(&["lints"]) + foo.cargo("doc") .with_status(101) .with_stderr_contains( "\ @@ -671,8 +640,7 @@ pub const Ĕ: i32 = 2; ) .build(); - foo.cargo("check -Zlints") - .masquerade_as_nightly_cargo(&["lints"]) + foo.cargo("check") .with_stderr( "\ [CHECKING] foo v0.0.1 ([CWD]) @@ -681,8 +649,7 @@ pub const Ĕ: i32 = 2; ) .run(); - foo.cargo("test --doc -Zlints") - .masquerade_as_nightly_cargo(&["lints"]) + foo.cargo("test --doc") .with_stderr( "\ [COMPILING] foo v0.0.1 ([CWD]) -- cgit v1.2.3