Skip to content

Commit 5b3300d

Browse files
committed
Add ui_cargo_toml_metadata test
1 parent 4562dd0 commit 5b3300d

File tree

28 files changed

+90
-34
lines changed

28 files changed

+90
-34
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ compiletest_rs = { version = "0.8", features = ["tmp"] }
3232
tester = "0.9"
3333
regex = "1.5"
3434
toml = "0.5"
35+
walkdir = "2.3"
3536
# This is used by the `collect-metadata` alias.
3637
filetime = "0.2"
3738

tests/compile-test.rs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ fn rustfix_coverage_known_exceptions_accuracy() {
433433
let rs_path = Path::new("tests/ui").join(filename);
434434
assert!(
435435
rs_path.exists(),
436-
"`{}` does not exists",
436+
"`{}` does not exist",
437437
rs_path.strip_prefix(env!("CARGO_MANIFEST_DIR")).unwrap().display()
438438
);
439439
let fixed_path = rs_path.with_extension("fixed");
@@ -445,6 +445,45 @@ fn rustfix_coverage_known_exceptions_accuracy() {
445445
}
446446
}
447447

448+
#[test]
449+
fn ui_cargo_toml_metadata() {
450+
let ui_cargo_path = Path::new("tests/ui-cargo");
451+
let cargo_common_metadata_path = ui_cargo_path.join("cargo_common_metadata");
452+
let publish_exceptions =
453+
["fail_publish", "fail_publish_true", "pass_publish_empty"].map(|path| cargo_common_metadata_path.join(path));
454+
455+
for entry in walkdir::WalkDir::new(ui_cargo_path) {
456+
let entry = entry.unwrap();
457+
let path = entry.path();
458+
if path.file_name() != Some(OsStr::new("Cargo.toml")) {
459+
continue;
460+
}
461+
462+
let toml = fs::read_to_string(path).unwrap().parse::<toml::Value>().unwrap();
463+
464+
let package = toml.as_table().unwrap().get("package").unwrap().as_table().unwrap();
465+
466+
let name = package.get("name").unwrap().as_str().unwrap().replace('-', "_");
467+
assert!(
468+
path.parent()
469+
.unwrap()
470+
.components()
471+
.map(|component| component.as_os_str().to_string_lossy().replace('-', "_"))
472+
.any(|s| *s == name)
473+
|| path.starts_with(&cargo_common_metadata_path),
474+
"{:?} has incorrect package name",
475+
path
476+
);
477+
478+
let publish = package.get("publish").and_then(toml::Value::as_bool).unwrap_or(true);
479+
assert!(
480+
!publish || publish_exceptions.contains(&path.parent().unwrap().to_path_buf()),
481+
"{:?} lacks `publish = false`",
482+
path
483+
);
484+
}
485+
}
486+
448487
/// Restores an env var on drop
449488
#[must_use]
450489
struct VarGuard {

tests/ui-cargo/cargo_common_metadata/fail/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "cargo_common_metadata"
2+
name = "cargo_common_metadata_fail"
33
version = "0.1.0"
44
publish = false
55

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
error: package `cargo_common_metadata` is missing `package.description` metadata
1+
error: package `cargo_common_metadata_fail` is missing `package.description` metadata
22
|
33
= note: `-D clippy::cargo-common-metadata` implied by `-D warnings`
44

5-
error: package `cargo_common_metadata` is missing `either package.license or package.license_file` metadata
5+
error: package `cargo_common_metadata_fail` is missing `either package.license or package.license_file` metadata
66

7-
error: package `cargo_common_metadata` is missing `package.repository` metadata
7+
error: package `cargo_common_metadata_fail` is missing `package.repository` metadata
88

9-
error: package `cargo_common_metadata` is missing `package.readme` metadata
9+
error: package `cargo_common_metadata_fail` is missing `package.readme` metadata
1010

11-
error: package `cargo_common_metadata` is missing `package.keywords` metadata
11+
error: package `cargo_common_metadata_fail` is missing `package.keywords` metadata
1212

13-
error: package `cargo_common_metadata` is missing `package.categories` metadata
13+
error: package `cargo_common_metadata_fail` is missing `package.categories` metadata
1414

1515
error: aborting due to 6 previous errors
1616

tests/ui-cargo/cargo_common_metadata/fail_publish/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "cargo_common_metadata"
2+
name = "cargo_common_metadata_fail_publish"
33
version = "0.1.0"
44
publish = ["some-registry-name"]
55

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
error: package `cargo_common_metadata` is missing `package.description` metadata
1+
error: package `cargo_common_metadata_fail_publish` is missing `package.description` metadata
22
|
33
= note: `-D clippy::cargo-common-metadata` implied by `-D warnings`
44

5-
error: package `cargo_common_metadata` is missing `either package.license or package.license_file` metadata
5+
error: package `cargo_common_metadata_fail_publish` is missing `either package.license or package.license_file` metadata
66

7-
error: package `cargo_common_metadata` is missing `package.repository` metadata
7+
error: package `cargo_common_metadata_fail_publish` is missing `package.repository` metadata
88

9-
error: package `cargo_common_metadata` is missing `package.readme` metadata
9+
error: package `cargo_common_metadata_fail_publish` is missing `package.readme` metadata
1010

11-
error: package `cargo_common_metadata` is missing `package.keywords` metadata
11+
error: package `cargo_common_metadata_fail_publish` is missing `package.keywords` metadata
1212

13-
error: package `cargo_common_metadata` is missing `package.categories` metadata
13+
error: package `cargo_common_metadata_fail_publish` is missing `package.categories` metadata
1414

1515
error: aborting due to 6 previous errors
1616

tests/ui-cargo/cargo_common_metadata/fail_publish_true/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "cargo_common_metadata"
2+
name = "cargo_common_metadata_fail_publish_true"
33
version = "0.1.0"
44
publish = true
55

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
error: package `cargo_common_metadata` is missing `package.description` metadata
1+
error: package `cargo_common_metadata_fail_publish_true` is missing `package.description` metadata
22
|
33
= note: `-D clippy::cargo-common-metadata` implied by `-D warnings`
44

5-
error: package `cargo_common_metadata` is missing `either package.license or package.license_file` metadata
5+
error: package `cargo_common_metadata_fail_publish_true` is missing `either package.license or package.license_file` metadata
66

7-
error: package `cargo_common_metadata` is missing `package.repository` metadata
7+
error: package `cargo_common_metadata_fail_publish_true` is missing `package.repository` metadata
88

9-
error: package `cargo_common_metadata` is missing `package.readme` metadata
9+
error: package `cargo_common_metadata_fail_publish_true` is missing `package.readme` metadata
1010

11-
error: package `cargo_common_metadata` is missing `package.keywords` metadata
11+
error: package `cargo_common_metadata_fail_publish_true` is missing `package.keywords` metadata
1212

13-
error: package `cargo_common_metadata` is missing `package.categories` metadata
13+
error: package `cargo_common_metadata_fail_publish_true` is missing `package.categories` metadata
1414

1515
error: aborting due to 6 previous errors
1616

tests/ui-cargo/cargo_common_metadata/pass/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "cargo_common_metadata"
2+
name = "cargo_common_metadata_pass"
33
version = "0.1.0"
44
publish = false
55
description = "A test package for the cargo_common_metadata lint"

tests/ui-cargo/cargo_common_metadata/pass_publish_empty/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "cargo_common_metadata"
2+
name = "cargo_common_metadata_pass_publish_empty"
33
version = "0.1.0"
44
publish = []
55

tests/ui-cargo/cargo_common_metadata/pass_publish_false/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "cargo_common_metadata"
2+
name = "cargo_common_metadata_pass_publish_false"
33
version = "0.1.0"
44
publish = false
55

tests/ui-cargo/cargo_rust_version/fail_both_diff/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
name = "fail-both-diff"
33
version = "0.1.0"
44
rust-version = "1.56"
5+
publish = false
56

67
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
78

tests/ui-cargo/cargo_rust_version/fail_both_same/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
name = "fail-both-same"
33
version = "0.1.0"
44
rust-version = "1.57.0"
5+
publish = false
56

67
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
78

tests/ui-cargo/cargo_rust_version/fail_cargo/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
name = "fail-cargo"
33
version = "0.1.0"
44
rust-version = "1.56.1"
5+
publish = false
56

67
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
78

tests/ui-cargo/cargo_rust_version/fail_clippy/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[package]
22
name = "fail-clippy"
33
version = "0.1.0"
4+
publish = false
45

56
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
67

tests/ui-cargo/cargo_rust_version/fail_file_attr/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
name = "fail-file-attr"
33
version = "0.1.0"
44
rust-version = "1.13"
5+
publish = false
56

67
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
78

tests/ui-cargo/cargo_rust_version/pass_both_same/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
[package]
2-
name = "fail-both-same"
2+
name = "pass-both-same"
33
version = "0.1.0"
44
rust-version = "1.13.0"
5+
publish = false
56

67
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
78

tests/ui-cargo/cargo_rust_version/pass_cargo/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
[package]
2-
name = "fail-cargo"
2+
name = "pass-cargo"
33
version = "0.1.0"
44
rust-version = "1.13.0"
5+
publish = false
56

67
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
78

tests/ui-cargo/cargo_rust_version/pass_clippy/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[package]
2-
name = "fail-clippy"
2+
name = "pass-clippy"
33
version = "0.1.0"
4+
publish = false
45

56
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
67

tests/ui-cargo/cargo_rust_version/pass_file_attr/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
[package]
2-
name = "fail-file-attr"
2+
name = "pass-file-attr"
33
version = "0.1.0"
44
rust-version = "1.59"
5+
publish = false
56

67
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
78

tests/ui-cargo/cargo_rust_version/warn_both_diff/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
name = "warn-both-diff"
33
version = "0.1.0"
44
rust-version = "1.56.0"
5+
publish = false
56

67
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
78

tests/ui-cargo/module_style/fail_mod/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
[package]
2-
name = "fail"
2+
name = "fail-mod"
33
version = "0.1.0"
44
edition = "2018"
5+
publish = false
56

67
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
78

tests/ui-cargo/module_style/fail_no_mod/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
[package]
2-
name = "fail"
2+
name = "fail-no-mod"
33
version = "0.1.0"
44
edition = "2018"
5+
publish = false
56

67
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
78

tests/ui-cargo/module_style/pass_mod/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
[package]
2-
name = "fail"
2+
name = "pass-mod"
33
version = "0.1.0"
44
edition = "2018"
5+
publish = false
56

67
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
78

tests/ui-cargo/module_style/pass_no_mod/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
[package]
2-
name = "pass"
2+
name = "pass-no-mod"
33
version = "0.1.0"
44
edition = "2018"
5+
publish = false
56

67
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
78

tests/ui-cargo/multiple_config_files/no_warn/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
name = "no_warn"
33
version = "0.1.0"
44
edition = "2021"
5+
publish = false
56

67
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
78

tests/ui-cargo/multiple_config_files/warn/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
name = "warn"
33
version = "0.1.0"
44
edition = "2021"
5+
publish = false
56

67
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
78

tests/ui-cargo/multiple_crate_versions/pass/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "cargo_common_metadata"
2+
name = "multiple_crate_versions"
33
version = "0.1.0"
44
publish = false
55

0 commit comments

Comments
 (0)