|  | 
|  | 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 | +} | 
|  | 61 | + | 
|  | 62 | +fn check(CrateRootLintLevels { args, contains }: CrateRootLintLevels) { | 
|  | 63 | +    let output = rustc() | 
|  | 64 | +        .input("lib.rs") | 
|  | 65 | +        .arg("-Zunstable-options") | 
|  | 66 | +        .print("crate-root-lint-levels") | 
|  | 67 | +        .args(args) | 
|  | 68 | +        .run(); | 
|  | 69 | + | 
|  | 70 | +    let stdout = output.stdout_utf8(); | 
|  | 71 | + | 
|  | 72 | +    let mut found = HashSet::<String>::new(); | 
|  | 73 | + | 
|  | 74 | +    for l in stdout.lines() { | 
|  | 75 | +        assert!(l == l.trim()); | 
|  | 76 | +        if let Some((left, right)) = l.split_once('=') { | 
|  | 77 | +            assert!(!left.contains("\"")); | 
|  | 78 | +            assert!(!right.contains("\"")); | 
|  | 79 | +        } else { | 
|  | 80 | +            assert!(l.contains('=')); | 
|  | 81 | +        } | 
|  | 82 | +        assert!(found.insert(l.to_string()), "{}", &l); | 
|  | 83 | +    } | 
|  | 84 | + | 
|  | 85 | +    let Contains { contains, doesnt_contain } = contains; | 
|  | 86 | + | 
|  | 87 | +    { | 
|  | 88 | +        let should_found = HashSet::<String>::from_iter(contains.iter().map(|s| s.to_string())); | 
|  | 89 | +        let diff: Vec<_> = should_found.difference(&found).collect(); | 
|  | 90 | +        assert!(diff.is_empty(), "should found: {:?}, didn't found {:?}", &should_found, &diff); | 
|  | 91 | +    } | 
|  | 92 | +    { | 
|  | 93 | +        let should_not_find = | 
|  | 94 | +            HashSet::<String>::from_iter(doesnt_contain.iter().map(|s| s.to_string())); | 
|  | 95 | +        let diff: Vec<_> = should_not_find.intersection(&found).collect(); | 
|  | 96 | +        assert!(diff.is_empty(), "should not find {:?}, did found {:?}", &should_not_find, &diff); | 
|  | 97 | +    } | 
|  | 98 | +} | 
0 commit comments