Skip to content

Commit 8f7f9b9

Browse files
committed
Add a run-make test for rustc --help and similar
1 parent b91a3a0 commit 8f7f9b9

File tree

5 files changed

+188
-0
lines changed

5 files changed

+188
-0
lines changed

src/tools/run-make-support/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ pub use libc;
4141
pub use object;
4242
pub use regex;
4343
pub use serde_json;
44+
pub use similar;
4445
pub use wasmparser;
4546
// tidy-alphabetical-end
4647

tests/run-make/rustc-help/help-v.diff

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
@@ -51,10 +51,27 @@
2+
Set a codegen option
3+
-V, --version Print version info and exit
4+
-v, --verbose Use verbose output
5+
+ --extern NAME[=PATH]
6+
+ Specify where an external rust library is located
7+
+ --sysroot PATH Override the system root
8+
+ --error-format human|json|short
9+
+ How errors and other messages are produced
10+
+ --json CONFIG Configure the JSON output of the compiler
11+
+ --color auto|always|never
12+
+ Configure coloring of output:
13+
+ auto = colorize, if output goes to a tty (default);
14+
+ always = always colorize output;
15+
+ never = never colorize output
16+
+ --diagnostic-width WIDTH
17+
+ Inform rustc of the width of the output so that
18+
+ diagnostics can be truncated to fit
19+
+ --remap-path-prefix FROM=TO
20+
+ Remap source names in all output (compiler messages
21+
+ and output files)
22+
+ @path Read newline separated options from `path`
23+
24+
Additional help:
25+
-C help Print codegen options
26+
-W help Print 'lint' options and default settings
27+
-Z help Print unstable compiler options
28+
- --help -v Print the full set of options rustc accepts
29+
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
Usage: rustc [OPTIONS] INPUT
2+
3+
Options:
4+
-h, --help Display this message
5+
--cfg SPEC Configure the compilation environment.
6+
SPEC supports the syntax `NAME[="VALUE"]`.
7+
--check-cfg SPEC
8+
Provide list of expected cfgs for checking
9+
-L [KIND=]PATH Add a directory to the library search path. The
10+
optional KIND can be one of dependency, crate, native,
11+
framework, or all (the default).
12+
-l [KIND[:MODIFIERS]=]NAME[:RENAME]
13+
Link the generated crate(s) to the specified native
14+
library NAME. The optional KIND can be one of
15+
static, framework, or dylib (the default).
16+
Optional comma separated MODIFIERS
17+
(bundle|verbatim|whole-archive|as-needed)
18+
may be specified each with a prefix of either '+' to
19+
enable or '-' to disable.
20+
--crate-type [bin|lib|rlib|dylib|cdylib|staticlib|proc-macro]
21+
Comma separated list of types of crates
22+
for the compiler to emit
23+
--crate-name NAME
24+
Specify the name of the crate being built
25+
--edition 2015|2018|2021|2024
26+
Specify which edition of the compiler to use when
27+
compiling code. The default is 2015 and the latest
28+
stable edition is 2021.
29+
--emit [asm|llvm-bc|llvm-ir|obj|metadata|link|dep-info|mir]
30+
Comma separated list of types of output for the
31+
compiler to emit
32+
--print [crate-name|file-names|sysroot|target-libdir|cfg|check-cfg|calling-conventions|target-list|target-cpus|target-features|relocation-models|code-models|tls-models|target-spec-json|all-target-specs-json|native-static-libs|stack-protector-strategies|link-args|deployment-target]
33+
Compiler information to print on stdout
34+
-g Equivalent to -C debuginfo=2
35+
-O Equivalent to -C opt-level=2
36+
-o FILENAME Write output to <filename>
37+
--out-dir DIR Write output to compiler-chosen filename in <dir>
38+
--explain OPT Provide a detailed explanation of an error message
39+
--test Build a test harness
40+
--target TARGET Target triple for which the code is compiled
41+
-A, --allow LINT Set lint allowed
42+
-W, --warn LINT Set lint warnings
43+
--force-warn LINT
44+
Set lint force-warn
45+
-D, --deny LINT Set lint denied
46+
-F, --forbid LINT Set lint forbidden
47+
--cap-lints LEVEL
48+
Set the most restrictive lint level. More restrictive
49+
lints are capped at this level
50+
-C, --codegen OPT[=VALUE]
51+
Set a codegen option
52+
-V, --version Print version info and exit
53+
-v, --verbose Use verbose output
54+
--extern NAME[=PATH]
55+
Specify where an external rust library is located
56+
--sysroot PATH Override the system root
57+
--error-format human|json|short
58+
How errors and other messages are produced
59+
--json CONFIG Configure the JSON output of the compiler
60+
--color auto|always|never
61+
Configure coloring of output:
62+
auto = colorize, if output goes to a tty (default);
63+
always = always colorize output;
64+
never = never colorize output
65+
--diagnostic-width WIDTH
66+
Inform rustc of the width of the output so that
67+
diagnostics can be truncated to fit
68+
--remap-path-prefix FROM=TO
69+
Remap source names in all output (compiler messages
70+
and output files)
71+
@path Read newline separated options from `path`
72+
73+
Additional help:
74+
-C help Print codegen options
75+
-W help Print 'lint' options and default settings
76+
-Z help Print unstable compiler options
77+

tests/run-make/rustc-help/help.stdout

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
Usage: rustc [OPTIONS] INPUT
2+
3+
Options:
4+
-h, --help Display this message
5+
--cfg SPEC Configure the compilation environment.
6+
SPEC supports the syntax `NAME[="VALUE"]`.
7+
--check-cfg SPEC
8+
Provide list of expected cfgs for checking
9+
-L [KIND=]PATH Add a directory to the library search path. The
10+
optional KIND can be one of dependency, crate, native,
11+
framework, or all (the default).
12+
-l [KIND[:MODIFIERS]=]NAME[:RENAME]
13+
Link the generated crate(s) to the specified native
14+
library NAME. The optional KIND can be one of
15+
static, framework, or dylib (the default).
16+
Optional comma separated MODIFIERS
17+
(bundle|verbatim|whole-archive|as-needed)
18+
may be specified each with a prefix of either '+' to
19+
enable or '-' to disable.
20+
--crate-type [bin|lib|rlib|dylib|cdylib|staticlib|proc-macro]
21+
Comma separated list of types of crates
22+
for the compiler to emit
23+
--crate-name NAME
24+
Specify the name of the crate being built
25+
--edition 2015|2018|2021|2024
26+
Specify which edition of the compiler to use when
27+
compiling code. The default is 2015 and the latest
28+
stable edition is 2021.
29+
--emit [asm|llvm-bc|llvm-ir|obj|metadata|link|dep-info|mir]
30+
Comma separated list of types of output for the
31+
compiler to emit
32+
--print [crate-name|file-names|sysroot|target-libdir|cfg|check-cfg|calling-conventions|target-list|target-cpus|target-features|relocation-models|code-models|tls-models|target-spec-json|all-target-specs-json|native-static-libs|stack-protector-strategies|link-args|deployment-target]
33+
Compiler information to print on stdout
34+
-g Equivalent to -C debuginfo=2
35+
-O Equivalent to -C opt-level=2
36+
-o FILENAME Write output to <filename>
37+
--out-dir DIR Write output to compiler-chosen filename in <dir>
38+
--explain OPT Provide a detailed explanation of an error message
39+
--test Build a test harness
40+
--target TARGET Target triple for which the code is compiled
41+
-A, --allow LINT Set lint allowed
42+
-W, --warn LINT Set lint warnings
43+
--force-warn LINT
44+
Set lint force-warn
45+
-D, --deny LINT Set lint denied
46+
-F, --forbid LINT Set lint forbidden
47+
--cap-lints LEVEL
48+
Set the most restrictive lint level. More restrictive
49+
lints are capped at this level
50+
-C, --codegen OPT[=VALUE]
51+
Set a codegen option
52+
-V, --version Print version info and exit
53+
-v, --verbose Use verbose output
54+
55+
Additional help:
56+
-C help Print codegen options
57+
-W help Print 'lint' options and default settings
58+
-Z help Print unstable compiler options
59+
--help -v Print the full set of options rustc accepts
60+

tests/run-make/rustc-help/rmake.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Tests `rustc --help` and similar invocations against snapshots and each other.
2+
3+
use run_make_support::{bare_rustc, diff, similar};
4+
5+
fn main() {
6+
// `rustc --help`
7+
let help = bare_rustc().arg("--help").run().stdout_utf8();
8+
diff().expected_file("help.stdout").actual_text("(rustc --help)", &help).run();
9+
10+
// `rustc` should be the same as `rustc --help`
11+
let bare = bare_rustc().run().stdout_utf8();
12+
diff().expected_text("(rustc --help)", &help).actual_text("(rustc)", &bare).run();
13+
14+
// `rustc --help -v` should give a similar but longer help message
15+
let help_v = bare_rustc().arg("--help").arg("-v").run().stdout_utf8();
16+
diff().expected_file("help-v.stdout").actual_text("(rustc --help -v)", &help_v).run();
17+
18+
// Check the diff between `rustc --help` and `rustc --help -v`.
19+
let help_v_diff = similar::TextDiff::from_lines(&help, &help_v).unified_diff().to_string();
20+
diff().expected_file("help-v.diff").actual_text("actual", &help_v_diff).run();
21+
}

0 commit comments

Comments
 (0)