| 
 | 1 | +// This test intentionally feeds invalid inputs to codegen and checks if the error message outputs  | 
 | 2 | +// contain specific helpful indications.  | 
 | 3 | + | 
 | 4 | +//@ ignore-cross-compile  | 
 | 5 | + | 
 | 6 | +use run_make_support::regex::Regex;  | 
 | 7 | +use run_make_support::rustc;  | 
 | 8 | + | 
 | 9 | +fn main() {  | 
 | 10 | +    // Option taking a number.  | 
 | 11 | +    rustc()  | 
 | 12 | +        .input("dummy.rs")  | 
 | 13 | +        .arg("-Ccodegen-units")  | 
 | 14 | +        .run_fail()  | 
 | 15 | +        .assert_stderr_contains("codegen option `codegen-units` requires a number");  | 
 | 16 | +    rustc().input("dummy.rs").arg("-Ccodegen-units=").run_fail().assert_stderr_contains(  | 
 | 17 | +        "incorrect value `` for codegen option `codegen-units` - a number was expected",  | 
 | 18 | +    );  | 
 | 19 | +    rustc().input("dummy.rs").arg("-Ccodegen-units=foo").run_fail().assert_stderr_contains(  | 
 | 20 | +        "incorrect value `foo` for codegen option `codegen-units` - a number was expected",  | 
 | 21 | +    );  | 
 | 22 | +    rustc().input("dummy.rs").arg("-Ccodegen-units=1").run();  | 
 | 23 | + | 
 | 24 | +    // Option taking a string.  | 
 | 25 | +    rustc()  | 
 | 26 | +        .input("dummy.rs")  | 
 | 27 | +        .arg("-Cextra-filename")  | 
 | 28 | +        .run_fail()  | 
 | 29 | +        .assert_stderr_contains("codegen option `extra-filename` requires a string");  | 
 | 30 | +    rustc().input("dummy.rs").arg("-Cextra-filename=").run();  | 
 | 31 | +    rustc().input("dummy.rs").arg("-Cextra-filename=foo").run();  | 
 | 32 | + | 
 | 33 | +    // Option taking no argument.  | 
 | 34 | +    rustc().input("dummy.rs").arg("-Clto=").run_fail().assert_stderr_contains(  | 
 | 35 | +        "codegen option `lto` - either a boolean (`yes`, `no`, `on`, `off`, etc), `thin`, \  | 
 | 36 | +             `fat`, or omitted",  | 
 | 37 | +    );  | 
 | 38 | +    rustc().input("dummy.rs").arg("-Clto=1").run_fail().assert_stderr_contains(  | 
 | 39 | +        "codegen option `lto` - either a boolean (`yes`, `no`, `on`, `off`, etc), `thin`, \  | 
 | 40 | +             `fat`, or omitted",  | 
 | 41 | +    );  | 
 | 42 | +    rustc().input("dummy.rs").arg("-Clto=foo").run_fail().assert_stderr_contains(  | 
 | 43 | +        "codegen option `lto` - either a boolean (`yes`, `no`, `on`, `off`, etc), `thin`, \  | 
 | 44 | +             `fat`, or omitted",  | 
 | 45 | +    );  | 
 | 46 | +    rustc().input("dummy.rs").arg("-Clto").run();  | 
 | 47 | + | 
 | 48 | +    let regex = Regex::new("--gc-sections|-z[^ ]* [^ ]*<ignore>|-dead_strip|/OPT:REF").unwrap();  | 
 | 49 | +    // Should not link dead code...  | 
 | 50 | +    let stdout = rustc().input("dummy.rs").print("link-args").run().stdout_utf8();  | 
 | 51 | +    assert!(regex.is_match(&stdout));  | 
 | 52 | +    // ... unless you specifically ask to keep it  | 
 | 53 | +    let stdout =  | 
 | 54 | +        rustc().input("dummy.rs").print("link-args").arg("-Clink-dead-code").run().stdout_utf8();  | 
 | 55 | +    assert!(!regex.is_match(&stdout));  | 
 | 56 | +}  | 
0 commit comments