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

Refactor cargo lint tests #13880

Merged
merged 3 commits into from
May 9, 2024
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
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
use cargo_test_support::prelude::*;
use cargo_test_support::project;
use cargo_test_support::registry::Package;
use cargo_test_support::{file, str};
use cargo_test_support::str;
use cargo_test_support::{file, project};

#[cargo_test]
fn case() {
Package::new("bar", "0.1.0").publish();
let p = project()
.file(
"Cargo.toml",
r#"
cargo-features = ["test-dummy-unstable"]

[package]
name = "foo"
version = "0.1.0"
edition = "2021"

[dependencies]
bar = { version = "0.1.0", optional = true }
version = "0.0.1"
edition = "2015"
authors = []
im-a-teapot = true

[lints.cargo]
implicit_features = "allow"
"#,
im_a_teapot = "deny"
"#,
)
.file("src/lib.rs", "")
.build();

snapbox::cmd::Command::cargo_ui()
.masquerade_as_nightly_cargo(&["cargo-lints"])
.masquerade_as_nightly_cargo(&["cargo-lints", "test-dummy-unstable"])
.current_dir(p.root())
.arg("check")
.arg("-Zcargo-lints")
.assert()
.success()
.code(101)
.stdout_matches(str![""])
.stderr_matches(file!["stderr.term.svg"]);
}
41 changes: 41 additions & 0 deletions tests/testsuite/lints/error/stderr.term.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
137 changes: 137 additions & 0 deletions tests/testsuite/lints/implicit_features.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
use cargo_test_support::project;
use cargo_test_support::registry::Package;

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

[dependencies]
bar = { version = "0.1.0", optional = true }
"#,
)
.file("src/lib.rs", "")
.build();

p.cargo("check -Zcargo-lints")
.masquerade_as_nightly_cargo(&["cargo-lints"])
.with_stderr(
"\
[UPDATING] [..]
[LOCKING] 2 packages to latest compatible versions
[CHECKING] foo v0.1.0 ([CWD])
[FINISHED] [..]
",
)
.run();
}

#[cargo_test]
fn warn() {
Package::new("bar", "0.1.0").publish();
Package::new("baz", "0.1.0").publish();
Package::new("target-dep", "0.1.0").publish();
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
edition = "2021"

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

[build-dependencies]
baz = { version = "0.1.0", optional = true }

[target.'cfg(target_os = "linux")'.dependencies]
target-dep = { version = "0.1.0", optional = true }

[lints.cargo]
implicit_features = "warn"
"#,
)
.file("src/lib.rs", "")
.build();

p.cargo("check -Zcargo-lints")
.masquerade_as_nightly_cargo(&["cargo-lints"])
.with_stderr(
"\
warning: implicit features for optional dependencies is deprecated and will be unavailable in the 2024 edition
--> Cargo.toml:8:1
|
8 | bar = { version = \"0.1.0\", optional = true }
| ---
|
= note: `cargo::implicit_features` is set to `warn` in `[lints]`
warning: implicit features for optional dependencies is deprecated and will be unavailable in the 2024 edition
--> Cargo.toml:11:1
|
11 | baz = { version = \"0.1.0\", optional = true }
| ---
|
warning: implicit features for optional dependencies is deprecated and will be unavailable in the 2024 edition
--> Cargo.toml:14:1
|
14 | target-dep = { version = \"0.1.0\", optional = true }
| ----------
|
[UPDATING] [..]
[LOCKING] 4 packages to latest compatible versions
[CHECKING] foo v0.1.0 ([CWD])
[FINISHED] [..]
",
)
.run();
}

#[cargo_test(nightly, reason = "edition2024 is not stable")]
fn implicit_features_edition_2024() {
Package::new("bar", "0.1.0").publish();
Package::new("baz", "0.1.0").publish();
let p = project()
.file(
"Cargo.toml",
r#"
cargo-features = ["edition2024"]
[package]
name = "foo"
version = "0.1.0"
edition = "2024"

[dependencies]
bar = { version = "0.1.0", optional = true }
baz = { version = "0.1.0", optional = true }

[features]
baz = ["dep:baz"]

[lints.cargo]
unused_optional_dependency = "allow"
"#,
)
.file("src/lib.rs", "")
.build();

p.cargo("check -Zcargo-lints")
.masquerade_as_nightly_cargo(&["cargo-lints", "edition2024"])
.with_stderr(
"\
[UPDATING] [..]
[LOCKING] 2 packages to latest Rust [..] compatible versions
[CHECKING] foo v0.1.0 ([CWD])
[FINISHED] [..]
",
)
.run();
}
32 changes: 0 additions & 32 deletions tests/testsuite/lints/implicit_features/edition_2021/mod.rs

This file was deleted.

This file was deleted.

45 changes: 0 additions & 45 deletions tests/testsuite/lints/implicit_features/edition_2021_warn/mod.rs

This file was deleted.

Loading
Loading