|  | 
|  | 1 | +// This test is to check if the warning is emitted when no space | 
|  | 2 | +// between `-o` and arg is applied, see issue #142812 | 
|  | 3 | + | 
|  | 4 | +//@ ignore-cross-compile | 
|  | 5 | +use run_make_support::rustc; | 
|  | 6 | + | 
|  | 7 | +fn main() { | 
|  | 8 | +    // test fake args | 
|  | 9 | +    rustc() | 
|  | 10 | +        .input("main.rs") | 
|  | 11 | +        .arg("-optimize") | 
|  | 12 | +        .run() | 
|  | 13 | +        .assert_stderr_contains( | 
|  | 14 | +            "warning: option `-o` has no space between flag name and value, which can be confusing", | 
|  | 15 | +        ) | 
|  | 16 | +        .assert_stderr_contains( | 
|  | 17 | +            "note: output filename `-o ptimize` is applied instead of a flag named `optimize`", | 
|  | 18 | +        ); | 
|  | 19 | +    rustc() | 
|  | 20 | +        .input("main.rs") | 
|  | 21 | +        .arg("-o0") | 
|  | 22 | +        .run() | 
|  | 23 | +        .assert_stderr_contains( | 
|  | 24 | +            "warning: option `-o` has no space between flag name and value, which can be confusing", | 
|  | 25 | +        ) | 
|  | 26 | +        .assert_stderr_contains( | 
|  | 27 | +            "note: output filename `-o 0` is applied instead of a flag named `o0`", | 
|  | 28 | +        ); | 
|  | 29 | +    rustc().input("main.rs").arg("-o1").run(); | 
|  | 30 | +    // test real args by iter optgroups | 
|  | 31 | +    rustc() | 
|  | 32 | +        .input("main.rs") | 
|  | 33 | +        .arg("-out-dir") | 
|  | 34 | +        .run() | 
|  | 35 | +        .assert_stderr_contains( | 
|  | 36 | +            "warning: option `-o` has no space between flag name and value, which can be confusing", | 
|  | 37 | +        ) | 
|  | 38 | +        .assert_stderr_contains( | 
|  | 39 | +            "note: output filename `-o ut-dir` is applied instead of a flag named `out-dir`", | 
|  | 40 | +        ) | 
|  | 41 | +        .assert_stderr_contains( | 
|  | 42 | +            "help: insert a space between `-o` and `ut-dir` if this is intentional: `-o ut-dir`", | 
|  | 43 | +        ); | 
|  | 44 | +    // test real args by iter CG_OPTIONS | 
|  | 45 | +    rustc() | 
|  | 46 | +        .input("main.rs") | 
|  | 47 | +        .arg("-opt_level") | 
|  | 48 | +        .run() | 
|  | 49 | +        .assert_stderr_contains( | 
|  | 50 | +            "warning: option `-o` has no space between flag name and value, which can be confusing", | 
|  | 51 | +        ) | 
|  | 52 | +        .assert_stderr_contains( | 
|  | 53 | +            "note: output filename `-o pt_level` is applied instead of a flag named `opt_level`", | 
|  | 54 | +        ) | 
|  | 55 | +        .assert_stderr_contains( | 
|  | 56 | +            "help: insert a space between `-o` and `pt_level` if this is intentional: `-o pt_level`" | 
|  | 57 | +        ); | 
|  | 58 | +    // separater in-sensitive | 
|  | 59 | +    rustc() | 
|  | 60 | +        .input("main.rs") | 
|  | 61 | +        .arg("-opt-level") | 
|  | 62 | +        .run() | 
|  | 63 | +        .assert_stderr_contains( | 
|  | 64 | +            "warning: option `-o` has no space between flag name and value, which can be confusing", | 
|  | 65 | +        ) | 
|  | 66 | +        .assert_stderr_contains( | 
|  | 67 | +            "note: output filename `-o pt-level` is applied instead of a flag named `opt-level`", | 
|  | 68 | +        ) | 
|  | 69 | +        .assert_stderr_contains( | 
|  | 70 | +            "help: insert a space between `-o` and `pt-level` if this is intentional: `-o pt-level`" | 
|  | 71 | +        ); | 
|  | 72 | +    rustc() | 
|  | 73 | +        .input("main.rs") | 
|  | 74 | +        .arg("-overflow-checks") | 
|  | 75 | +        .run() | 
|  | 76 | +        .assert_stderr_contains( | 
|  | 77 | +            "warning: option `-o` has no space between flag name and value, which can be confusing", | 
|  | 78 | +        ) | 
|  | 79 | +        .assert_stderr_contains( | 
|  | 80 | +            "note: output filename `-o verflow-checks` \ | 
|  | 81 | +            is applied instead of a flag named `overflow-checks`", | 
|  | 82 | +        ) | 
|  | 83 | +        .assert_stderr_contains( | 
|  | 84 | +            "help: insert a space between `-o` and `verflow-checks` \ | 
|  | 85 | +            if this is intentional: `-o verflow-checks`", | 
|  | 86 | +        ); | 
|  | 87 | + | 
|  | 88 | +    // No warning for Z_OPTIONS | 
|  | 89 | +    rustc().input("main.rs").arg("-oom").run().assert_stderr_equals(""); | 
|  | 90 | + | 
|  | 91 | +    // test no warning when there is space between `-o` and arg | 
|  | 92 | +    rustc().input("main.rs").arg("-o").arg("ptimize").run().assert_stderr_equals(""); | 
|  | 93 | +    rustc().input("main.rs").arg("--out-dir").arg("xxx").run().assert_stderr_equals(""); | 
|  | 94 | +    rustc().input("main.rs").arg("-o").arg("out-dir").run().assert_stderr_equals(""); | 
|  | 95 | +} | 
0 commit comments