|
| 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 | +use run_make_support::rustc; |
| 4 | + |
| 5 | +fn main() { |
| 6 | + // test fake args |
| 7 | + rustc() |
| 8 | + .input("main.rs") |
| 9 | + .arg("-optimize") |
| 10 | + .run() |
| 11 | + .assert_stderr_contains( |
| 12 | + "warning: option `-o` has no space between flag name and value, which can be confusing", |
| 13 | + ) |
| 14 | + .assert_stderr_contains( |
| 15 | + "note: option `-o ptimize` is applied instead of a flag named `optimize`", |
| 16 | + ) |
| 17 | + .assert_stderr_contains("to specify output filename `ptimize`"); |
| 18 | + rustc() |
| 19 | + .input("main.rs") |
| 20 | + .arg("-o0") |
| 21 | + .run() |
| 22 | + .assert_stderr_contains( |
| 23 | + "warning: option `-o` has no space between flag name and value, which can be confusing", |
| 24 | + ) |
| 25 | + .assert_stderr_contains("note: option `-o 0` is applied instead of a flag named `o0`") |
| 26 | + .assert_stderr_contains("to specify output filename `0`"); |
| 27 | + rustc().input("main.rs").arg("-o1").run(); |
| 28 | + // test real args by iter optgroups |
| 29 | + rustc() |
| 30 | + .input("main.rs") |
| 31 | + .arg("-out-dir") |
| 32 | + .run() |
| 33 | + .assert_stderr_contains( |
| 34 | + "warning: option `-o` has no space between flag name and value, which can be confusing", |
| 35 | + ) |
| 36 | + .assert_stderr_contains( |
| 37 | + "note: option `-o ut-dir` is applied instead of a flag named `out-dir`", |
| 38 | + ) |
| 39 | + .assert_stderr_contains("to specify output filename `ut-dir`") |
| 40 | + .assert_stderr_contains("Do you mean `--out-dir`?"); |
| 41 | + // test real args by iter CG_OPTIONS |
| 42 | + rustc() |
| 43 | + .input("main.rs") |
| 44 | + .arg("-opt-level") |
| 45 | + .run() |
| 46 | + .assert_stderr_contains( |
| 47 | + "warning: option `-o` has no space between flag name and value, which can be confusing", |
| 48 | + ) |
| 49 | + .assert_stderr_contains( |
| 50 | + "note: option `-o pt-level` is applied instead of a flag named `opt-level`", |
| 51 | + ) |
| 52 | + .assert_stderr_contains("to specify output filename `pt-level`") |
| 53 | + .assert_stderr_contains("Do you mean `-C opt_level`?"); |
| 54 | + rustc() |
| 55 | + .input("main.rs") |
| 56 | + .arg("-overflow-checks") |
| 57 | + .run() |
| 58 | + .assert_stderr_contains( |
| 59 | + "warning: option `-o` has no space between flag name and value, which can be confusing", |
| 60 | + ) |
| 61 | + .assert_stderr_contains( |
| 62 | + "note: option `-o verflow-checks` is applied instead of a flag named `overflow-checks`", |
| 63 | + ) |
| 64 | + .assert_stderr_contains("to specify output filename `verflow-checks`") |
| 65 | + .assert_stderr_contains("Do you mean `-C overflow_checks`?"); |
| 66 | + // test real args by iter Z_OPTIONS |
| 67 | + rustc() |
| 68 | + .input("main.rs") |
| 69 | + .arg("-oom") |
| 70 | + .run() |
| 71 | + .assert_stderr_contains( |
| 72 | + "warning: option `-o` has no space between flag name and value, which can be confusing", |
| 73 | + ) |
| 74 | + .assert_stderr_contains("note: option `-o om` is applied instead of a flag named `oom`") |
| 75 | + .assert_stderr_contains("to specify output filename `om`") |
| 76 | + .assert_stderr_contains("note: Do you mean `-Z oom`?"); |
| 77 | + |
| 78 | + // test no warning when there is space between `-o` and arg |
| 79 | + rustc().input("main.rs").arg("-o").arg("ptimize").run().assert_stderr_equals(""); |
| 80 | + rustc().input("main.rs").arg("--out-dir").arg("xxx").run().assert_stderr_equals(""); |
| 81 | + rustc().input("main.rs").arg("-o").arg("out-dir").run().assert_stderr_equals(""); |
| 82 | +} |
0 commit comments