| 
 | 1 | +//! This checks the output of `--print=crate-root-lint-levels`  | 
 | 2 | +
  | 
 | 3 | +extern crate run_make_support;  | 
 | 4 | + | 
 | 5 | +use std::collections::HashSet;  | 
 | 6 | +use std::iter::FromIterator;  | 
 | 7 | + | 
 | 8 | +use run_make_support::rustc;  | 
 | 9 | + | 
 | 10 | +struct CrateRootLintLevels {  | 
 | 11 | +    args: &'static [&'static str],  | 
 | 12 | +    contains: Contains,  | 
 | 13 | +}  | 
 | 14 | + | 
 | 15 | +struct Contains {  | 
 | 16 | +    contains: &'static [&'static str],  | 
 | 17 | +    doesnt_contain: &'static [&'static str],  | 
 | 18 | +}  | 
 | 19 | + | 
 | 20 | +fn main() {  | 
 | 21 | +    check(CrateRootLintLevels {  | 
 | 22 | +        args: &[],  | 
 | 23 | +        contains: Contains {  | 
 | 24 | +            contains: &[  | 
 | 25 | +                "unexpected_cfgs=allow",  | 
 | 26 | +                "unused_mut=expect",  | 
 | 27 | +                "warnings=warn",  | 
 | 28 | +                "stable_features=warn",  | 
 | 29 | +                "unknown_lints=warn",  | 
 | 30 | +            ],  | 
 | 31 | +            doesnt_contain: &["unexpected_cfgs=warn", "unused_mut=warn"],  | 
 | 32 | +        },  | 
 | 33 | +    });  | 
 | 34 | +    check(CrateRootLintLevels {  | 
 | 35 | +        args: &["-Wunexpected_cfgs"],  | 
 | 36 | +        contains: Contains {  | 
 | 37 | +            contains: &["unexpected_cfgs=allow", "warnings=warn"],  | 
 | 38 | +            doesnt_contain: &["unexpected_cfgs=warn"],  | 
 | 39 | +        },  | 
 | 40 | +    });  | 
 | 41 | +    check(CrateRootLintLevels {  | 
 | 42 | +        args: &["-Dwarnings"],  | 
 | 43 | +        contains: Contains {  | 
 | 44 | +            contains: &[  | 
 | 45 | +                "unexpected_cfgs=allow",  | 
 | 46 | +                "warnings=deny",  | 
 | 47 | +                "stable_features=deny",  | 
 | 48 | +                "unknown_lints=deny",  | 
 | 49 | +            ],  | 
 | 50 | +            doesnt_contain: &["warnings=warn"],  | 
 | 51 | +        },  | 
 | 52 | +    });  | 
 | 53 | +    check(CrateRootLintLevels {  | 
 | 54 | +        args: &["-Dstable_features"],  | 
 | 55 | +        contains: Contains {  | 
 | 56 | +            contains: &["warnings=warn", "stable_features=deny", "unexpected_cfgs=allow"],  | 
 | 57 | +            doesnt_contain: &["warnings=deny"],  | 
 | 58 | +        },  | 
 | 59 | +    });  | 
 | 60 | +    check(CrateRootLintLevels {  | 
 | 61 | +        args: &["-Dwarnings", "--force-warn=stable_features"],  | 
 | 62 | +        contains: Contains {  | 
 | 63 | +            contains: &["warnings=deny", "stable_features=force-warn", "unknown_lints=deny"],  | 
 | 64 | +            doesnt_contain: &["warnings=warn"],  | 
 | 65 | +        },  | 
 | 66 | +    });  | 
 | 67 | +    check(CrateRootLintLevels {  | 
 | 68 | +        args: &["-Dwarnings", "--cap-lints=warn"],  | 
 | 69 | +        contains: Contains {  | 
 | 70 | +            contains: &[  | 
 | 71 | +                "unexpected_cfgs=allow",  | 
 | 72 | +                "warnings=warn",  | 
 | 73 | +                "stable_features=warn",  | 
 | 74 | +                "unknown_lints=warn",  | 
 | 75 | +            ],  | 
 | 76 | +            doesnt_contain: &["warnings=deny"],  | 
 | 77 | +        },  | 
 | 78 | +    });  | 
 | 79 | +}  | 
 | 80 | + | 
 | 81 | +#[track_caller]  | 
 | 82 | +fn check(CrateRootLintLevels { args, contains }: CrateRootLintLevels) {  | 
 | 83 | +    let output = rustc()  | 
 | 84 | +        .input("lib.rs")  | 
 | 85 | +        .arg("-Zunstable-options")  | 
 | 86 | +        .print("crate-root-lint-levels")  | 
 | 87 | +        .args(args)  | 
 | 88 | +        .run();  | 
 | 89 | + | 
 | 90 | +    let stdout = output.stdout_utf8();  | 
 | 91 | + | 
 | 92 | +    let mut found = HashSet::<String>::new();  | 
 | 93 | + | 
 | 94 | +    for l in stdout.lines() {  | 
 | 95 | +        assert!(l == l.trim());  | 
 | 96 | +        if let Some((left, right)) = l.split_once('=') {  | 
 | 97 | +            assert!(!left.contains("\""));  | 
 | 98 | +            assert!(!right.contains("\""));  | 
 | 99 | +        } else {  | 
 | 100 | +            assert!(l.contains('='));  | 
 | 101 | +        }  | 
 | 102 | +        assert!(found.insert(l.to_string()), "{}", &l);  | 
 | 103 | +    }  | 
 | 104 | + | 
 | 105 | +    let Contains { contains, doesnt_contain } = contains;  | 
 | 106 | + | 
 | 107 | +    {  | 
 | 108 | +        let should_found = HashSet::<String>::from_iter(contains.iter().map(|s| s.to_string()));  | 
 | 109 | +        let diff: Vec<_> = should_found.difference(&found).collect();  | 
 | 110 | +        assert!(diff.is_empty(), "should found: {:?}, didn't found {:?}", &should_found, &diff);  | 
 | 111 | +    }  | 
 | 112 | +    {  | 
 | 113 | +        let should_not_find =  | 
 | 114 | +            HashSet::<String>::from_iter(doesnt_contain.iter().map(|s| s.to_string()));  | 
 | 115 | +        let diff: Vec<_> = should_not_find.intersection(&found).collect();  | 
 | 116 | +        assert!(diff.is_empty(), "should not find {:?}, did found {:?}", &should_not_find, &diff);  | 
 | 117 | +    }  | 
 | 118 | +}  | 
0 commit comments