Add unstable --print=crate-root-lint-levels
This commit is contained in:
parent
69cb0a9e15
commit
df18de57a5
11 changed files with 186 additions and 5 deletions
5
tests/run-make/print-crate-root-lint-levels/lib.rs
Normal file
5
tests/run-make/print-crate-root-lint-levels/lib.rs
Normal file
|
@ -0,0 +1,5 @@
|
|||
#![allow(unexpected_cfgs)]
|
||||
#![expect(unused_mut)]
|
||||
|
||||
#[deny(unknown_lints)]
|
||||
mod my_mod {}
|
118
tests/run-make/print-crate-root-lint-levels/rmake.rs
Normal file
118
tests/run-make/print-crate-root-lint-levels/rmake.rs
Normal file
|
@ -0,0 +1,118 @@
|
|||
//! This checks the output of `--print=crate-root-lint-levels`
|
||||
|
||||
extern crate run_make_support;
|
||||
|
||||
use std::collections::HashSet;
|
||||
use std::iter::FromIterator;
|
||||
|
||||
use run_make_support::rustc;
|
||||
|
||||
struct CrateRootLintLevels {
|
||||
args: &'static [&'static str],
|
||||
contains: Contains,
|
||||
}
|
||||
|
||||
struct Contains {
|
||||
contains: &'static [&'static str],
|
||||
doesnt_contain: &'static [&'static str],
|
||||
}
|
||||
|
||||
fn main() {
|
||||
check(CrateRootLintLevels {
|
||||
args: &[],
|
||||
contains: Contains {
|
||||
contains: &[
|
||||
"unexpected_cfgs=allow",
|
||||
"unused_mut=expect",
|
||||
"warnings=warn",
|
||||
"stable_features=warn",
|
||||
"unknown_lints=warn",
|
||||
],
|
||||
doesnt_contain: &["unexpected_cfgs=warn", "unused_mut=warn"],
|
||||
},
|
||||
});
|
||||
check(CrateRootLintLevels {
|
||||
args: &["-Wunexpected_cfgs"],
|
||||
contains: Contains {
|
||||
contains: &["unexpected_cfgs=allow", "warnings=warn"],
|
||||
doesnt_contain: &["unexpected_cfgs=warn"],
|
||||
},
|
||||
});
|
||||
check(CrateRootLintLevels {
|
||||
args: &["-Dwarnings"],
|
||||
contains: Contains {
|
||||
contains: &[
|
||||
"unexpected_cfgs=allow",
|
||||
"warnings=deny",
|
||||
"stable_features=deny",
|
||||
"unknown_lints=deny",
|
||||
],
|
||||
doesnt_contain: &["warnings=warn"],
|
||||
},
|
||||
});
|
||||
check(CrateRootLintLevels {
|
||||
args: &["-Dstable_features"],
|
||||
contains: Contains {
|
||||
contains: &["warnings=warn", "stable_features=deny", "unexpected_cfgs=allow"],
|
||||
doesnt_contain: &["warnings=deny"],
|
||||
},
|
||||
});
|
||||
check(CrateRootLintLevels {
|
||||
args: &["-Dwarnings", "--force-warn=stable_features"],
|
||||
contains: Contains {
|
||||
contains: &["warnings=deny", "stable_features=force-warn", "unknown_lints=deny"],
|
||||
doesnt_contain: &["warnings=warn"],
|
||||
},
|
||||
});
|
||||
check(CrateRootLintLevels {
|
||||
args: &["-Dwarnings", "--cap-lints=warn"],
|
||||
contains: Contains {
|
||||
contains: &[
|
||||
"unexpected_cfgs=allow",
|
||||
"warnings=warn",
|
||||
"stable_features=warn",
|
||||
"unknown_lints=warn",
|
||||
],
|
||||
doesnt_contain: &["warnings=deny"],
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
fn check(CrateRootLintLevels { args, contains }: CrateRootLintLevels) {
|
||||
let output = rustc()
|
||||
.input("lib.rs")
|
||||
.arg("-Zunstable-options")
|
||||
.print("crate-root-lint-levels")
|
||||
.args(args)
|
||||
.run();
|
||||
|
||||
let stdout = output.stdout_utf8();
|
||||
|
||||
let mut found = HashSet::<String>::new();
|
||||
|
||||
for l in stdout.lines() {
|
||||
assert!(l == l.trim());
|
||||
if let Some((left, right)) = l.split_once('=') {
|
||||
assert!(!left.contains("\""));
|
||||
assert!(!right.contains("\""));
|
||||
} else {
|
||||
assert!(l.contains('='));
|
||||
}
|
||||
assert!(found.insert(l.to_string()), "{}", &l);
|
||||
}
|
||||
|
||||
let Contains { contains, doesnt_contain } = contains;
|
||||
|
||||
{
|
||||
let should_found = HashSet::<String>::from_iter(contains.iter().map(|s| s.to_string()));
|
||||
let diff: Vec<_> = should_found.difference(&found).collect();
|
||||
assert!(diff.is_empty(), "should found: {:?}, didn't found {:?}", &should_found, &diff);
|
||||
}
|
||||
{
|
||||
let should_not_find =
|
||||
HashSet::<String>::from_iter(doesnt_contain.iter().map(|s| s.to_string()));
|
||||
let diff: Vec<_> = should_not_find.intersection(&found).collect();
|
||||
assert!(diff.is_empty(), "should not find {:?}, did found {:?}", &should_not_find, &diff);
|
||||
}
|
||||
}
|
|
@ -29,7 +29,7 @@ Options:
|
|||
--emit [asm|llvm-bc|llvm-ir|obj|metadata|link|dep-info|mir]
|
||||
Comma separated list of types of output for the
|
||||
compiler to emit
|
||||
--print [all-target-specs-json|calling-conventions|cfg|check-cfg|code-models|crate-name|deployment-target|file-names|host-tuple|link-args|native-static-libs|relocation-models|split-debuginfo|stack-protector-strategies|supported-crate-types|sysroot|target-cpus|target-features|target-libdir|target-list|target-spec-json|tls-models]
|
||||
--print [all-target-specs-json|calling-conventions|cfg|check-cfg|code-models|crate-name|crate-root-lint-levels|deployment-target|file-names|host-tuple|link-args|native-static-libs|relocation-models|split-debuginfo|stack-protector-strategies|supported-crate-types|sysroot|target-cpus|target-features|target-libdir|target-list|target-spec-json|tls-models]
|
||||
Compiler information to print on stdout
|
||||
-g Equivalent to -C debuginfo=2
|
||||
-O Equivalent to -C opt-level=3
|
||||
|
|
|
@ -29,7 +29,7 @@ Options:
|
|||
--emit [asm|llvm-bc|llvm-ir|obj|metadata|link|dep-info|mir]
|
||||
Comma separated list of types of output for the
|
||||
compiler to emit
|
||||
--print [all-target-specs-json|calling-conventions|cfg|check-cfg|code-models|crate-name|deployment-target|file-names|host-tuple|link-args|native-static-libs|relocation-models|split-debuginfo|stack-protector-strategies|supported-crate-types|sysroot|target-cpus|target-features|target-libdir|target-list|target-spec-json|tls-models]
|
||||
--print [all-target-specs-json|calling-conventions|cfg|check-cfg|code-models|crate-name|crate-root-lint-levels|deployment-target|file-names|host-tuple|link-args|native-static-libs|relocation-models|split-debuginfo|stack-protector-strategies|supported-crate-types|sysroot|target-cpus|target-features|target-libdir|target-list|target-spec-json|tls-models]
|
||||
Compiler information to print on stdout
|
||||
-g Equivalent to -C debuginfo=2
|
||||
-O Equivalent to -C opt-level=3
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue