mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-31 06:22:00 +00:00
Add ui_cargo_toml_metadata
test
This commit is contained in:
parent
4562dd0a8e
commit
5b3300dc29
@ -32,6 +32,7 @@ compiletest_rs = { version = "0.8", features = ["tmp"] }
|
||||
tester = "0.9"
|
||||
regex = "1.5"
|
||||
toml = "0.5"
|
||||
walkdir = "2.3"
|
||||
# This is used by the `collect-metadata` alias.
|
||||
filetime = "0.2"
|
||||
|
||||
|
@ -433,7 +433,7 @@ fn rustfix_coverage_known_exceptions_accuracy() {
|
||||
let rs_path = Path::new("tests/ui").join(filename);
|
||||
assert!(
|
||||
rs_path.exists(),
|
||||
"`{}` does not exists",
|
||||
"`{}` does not exist",
|
||||
rs_path.strip_prefix(env!("CARGO_MANIFEST_DIR")).unwrap().display()
|
||||
);
|
||||
let fixed_path = rs_path.with_extension("fixed");
|
||||
@ -445,6 +445,45 @@ fn rustfix_coverage_known_exceptions_accuracy() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ui_cargo_toml_metadata() {
|
||||
let ui_cargo_path = Path::new("tests/ui-cargo");
|
||||
let cargo_common_metadata_path = ui_cargo_path.join("cargo_common_metadata");
|
||||
let publish_exceptions =
|
||||
["fail_publish", "fail_publish_true", "pass_publish_empty"].map(|path| cargo_common_metadata_path.join(path));
|
||||
|
||||
for entry in walkdir::WalkDir::new(ui_cargo_path) {
|
||||
let entry = entry.unwrap();
|
||||
let path = entry.path();
|
||||
if path.file_name() != Some(OsStr::new("Cargo.toml")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let toml = fs::read_to_string(path).unwrap().parse::<toml::Value>().unwrap();
|
||||
|
||||
let package = toml.as_table().unwrap().get("package").unwrap().as_table().unwrap();
|
||||
|
||||
let name = package.get("name").unwrap().as_str().unwrap().replace('-', "_");
|
||||
assert!(
|
||||
path.parent()
|
||||
.unwrap()
|
||||
.components()
|
||||
.map(|component| component.as_os_str().to_string_lossy().replace('-', "_"))
|
||||
.any(|s| *s == name)
|
||||
|| path.starts_with(&cargo_common_metadata_path),
|
||||
"{:?} has incorrect package name",
|
||||
path
|
||||
);
|
||||
|
||||
let publish = package.get("publish").and_then(toml::Value::as_bool).unwrap_or(true);
|
||||
assert!(
|
||||
!publish || publish_exceptions.contains(&path.parent().unwrap().to_path_buf()),
|
||||
"{:?} lacks `publish = false`",
|
||||
path
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Restores an env var on drop
|
||||
#[must_use]
|
||||
struct VarGuard {
|
||||
|
@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "cargo_common_metadata"
|
||||
name = "cargo_common_metadata_fail"
|
||||
version = "0.1.0"
|
||||
publish = false
|
||||
|
||||
|
@ -1,16 +1,16 @@
|
||||
error: package `cargo_common_metadata` is missing `package.description` metadata
|
||||
error: package `cargo_common_metadata_fail` is missing `package.description` metadata
|
||||
|
|
||||
= note: `-D clippy::cargo-common-metadata` implied by `-D warnings`
|
||||
|
||||
error: package `cargo_common_metadata` is missing `either package.license or package.license_file` metadata
|
||||
error: package `cargo_common_metadata_fail` is missing `either package.license or package.license_file` metadata
|
||||
|
||||
error: package `cargo_common_metadata` is missing `package.repository` metadata
|
||||
error: package `cargo_common_metadata_fail` is missing `package.repository` metadata
|
||||
|
||||
error: package `cargo_common_metadata` is missing `package.readme` metadata
|
||||
error: package `cargo_common_metadata_fail` is missing `package.readme` metadata
|
||||
|
||||
error: package `cargo_common_metadata` is missing `package.keywords` metadata
|
||||
error: package `cargo_common_metadata_fail` is missing `package.keywords` metadata
|
||||
|
||||
error: package `cargo_common_metadata` is missing `package.categories` metadata
|
||||
error: package `cargo_common_metadata_fail` is missing `package.categories` metadata
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "cargo_common_metadata"
|
||||
name = "cargo_common_metadata_fail_publish"
|
||||
version = "0.1.0"
|
||||
publish = ["some-registry-name"]
|
||||
|
||||
|
@ -1,16 +1,16 @@
|
||||
error: package `cargo_common_metadata` is missing `package.description` metadata
|
||||
error: package `cargo_common_metadata_fail_publish` is missing `package.description` metadata
|
||||
|
|
||||
= note: `-D clippy::cargo-common-metadata` implied by `-D warnings`
|
||||
|
||||
error: package `cargo_common_metadata` is missing `either package.license or package.license_file` metadata
|
||||
error: package `cargo_common_metadata_fail_publish` is missing `either package.license or package.license_file` metadata
|
||||
|
||||
error: package `cargo_common_metadata` is missing `package.repository` metadata
|
||||
error: package `cargo_common_metadata_fail_publish` is missing `package.repository` metadata
|
||||
|
||||
error: package `cargo_common_metadata` is missing `package.readme` metadata
|
||||
error: package `cargo_common_metadata_fail_publish` is missing `package.readme` metadata
|
||||
|
||||
error: package `cargo_common_metadata` is missing `package.keywords` metadata
|
||||
error: package `cargo_common_metadata_fail_publish` is missing `package.keywords` metadata
|
||||
|
||||
error: package `cargo_common_metadata` is missing `package.categories` metadata
|
||||
error: package `cargo_common_metadata_fail_publish` is missing `package.categories` metadata
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "cargo_common_metadata"
|
||||
name = "cargo_common_metadata_fail_publish_true"
|
||||
version = "0.1.0"
|
||||
publish = true
|
||||
|
||||
|
@ -1,16 +1,16 @@
|
||||
error: package `cargo_common_metadata` is missing `package.description` metadata
|
||||
error: package `cargo_common_metadata_fail_publish_true` is missing `package.description` metadata
|
||||
|
|
||||
= note: `-D clippy::cargo-common-metadata` implied by `-D warnings`
|
||||
|
||||
error: package `cargo_common_metadata` is missing `either package.license or package.license_file` metadata
|
||||
error: package `cargo_common_metadata_fail_publish_true` is missing `either package.license or package.license_file` metadata
|
||||
|
||||
error: package `cargo_common_metadata` is missing `package.repository` metadata
|
||||
error: package `cargo_common_metadata_fail_publish_true` is missing `package.repository` metadata
|
||||
|
||||
error: package `cargo_common_metadata` is missing `package.readme` metadata
|
||||
error: package `cargo_common_metadata_fail_publish_true` is missing `package.readme` metadata
|
||||
|
||||
error: package `cargo_common_metadata` is missing `package.keywords` metadata
|
||||
error: package `cargo_common_metadata_fail_publish_true` is missing `package.keywords` metadata
|
||||
|
||||
error: package `cargo_common_metadata` is missing `package.categories` metadata
|
||||
error: package `cargo_common_metadata_fail_publish_true` is missing `package.categories` metadata
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "cargo_common_metadata"
|
||||
name = "cargo_common_metadata_pass"
|
||||
version = "0.1.0"
|
||||
publish = false
|
||||
description = "A test package for the cargo_common_metadata lint"
|
||||
|
@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "cargo_common_metadata"
|
||||
name = "cargo_common_metadata_pass_publish_empty"
|
||||
version = "0.1.0"
|
||||
publish = []
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "cargo_common_metadata"
|
||||
name = "cargo_common_metadata_pass_publish_false"
|
||||
version = "0.1.0"
|
||||
publish = false
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
name = "fail-both-diff"
|
||||
version = "0.1.0"
|
||||
rust-version = "1.56"
|
||||
publish = false
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
name = "fail-both-same"
|
||||
version = "0.1.0"
|
||||
rust-version = "1.57.0"
|
||||
publish = false
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
name = "fail-cargo"
|
||||
version = "0.1.0"
|
||||
rust-version = "1.56.1"
|
||||
publish = false
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
[package]
|
||||
name = "fail-clippy"
|
||||
version = "0.1.0"
|
||||
publish = false
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
name = "fail-file-attr"
|
||||
version = "0.1.0"
|
||||
rust-version = "1.13"
|
||||
publish = false
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
|
@ -1,7 +1,8 @@
|
||||
[package]
|
||||
name = "fail-both-same"
|
||||
name = "pass-both-same"
|
||||
version = "0.1.0"
|
||||
rust-version = "1.13.0"
|
||||
publish = false
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
|
@ -1,7 +1,8 @@
|
||||
[package]
|
||||
name = "fail-cargo"
|
||||
name = "pass-cargo"
|
||||
version = "0.1.0"
|
||||
rust-version = "1.13.0"
|
||||
publish = false
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
[package]
|
||||
name = "fail-clippy"
|
||||
name = "pass-clippy"
|
||||
version = "0.1.0"
|
||||
publish = false
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
|
@ -1,7 +1,8 @@
|
||||
[package]
|
||||
name = "fail-file-attr"
|
||||
name = "pass-file-attr"
|
||||
version = "0.1.0"
|
||||
rust-version = "1.59"
|
||||
publish = false
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
name = "warn-both-diff"
|
||||
version = "0.1.0"
|
||||
rust-version = "1.56.0"
|
||||
publish = false
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
|
@ -1,7 +1,8 @@
|
||||
[package]
|
||||
name = "fail"
|
||||
name = "fail-mod"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
publish = false
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
|
@ -1,7 +1,8 @@
|
||||
[package]
|
||||
name = "fail"
|
||||
name = "fail-no-mod"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
publish = false
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
|
@ -1,7 +1,8 @@
|
||||
[package]
|
||||
name = "fail"
|
||||
name = "pass-mod"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
publish = false
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
|
@ -1,7 +1,8 @@
|
||||
[package]
|
||||
name = "pass"
|
||||
name = "pass-no-mod"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
publish = false
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
name = "no_warn"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
name = "warn"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "cargo_common_metadata"
|
||||
name = "multiple_crate_versions"
|
||||
version = "0.1.0"
|
||||
publish = false
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user