Skip to content

Commit 006c94c

Browse files
committed
Use named struct arguments instead of comment named args
1 parent 607497d commit 006c94c

File tree

2 files changed

+67
-60
lines changed

2 files changed

+67
-60
lines changed

tests/run-make/print-cfg/rmake.rs

+35-29
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,42 @@ use std::iter::FromIterator;
1414

1515
use run_make_support::{rustc, tmp_dir};
1616

17+
struct PrintCfg {
18+
target: &'static str,
19+
includes: &'static [&'static str],
20+
disallow: &'static [&'static str],
21+
}
22+
1723
fn main() {
18-
check(
19-
/*target*/ "x86_64-pc-windows-gnu",
20-
/*includes*/ &["windows", "target_arch=\"x86_64\""],
21-
/*disallow*/ &["unix"],
22-
);
23-
check(
24-
/*target*/ "i686-pc-windows-msvc",
25-
/*includes*/ &["windows", "target_env=\"msvc\""],
26-
/*disallow*/ &["unix"],
27-
);
28-
check(
29-
/*target*/ "i686-apple-darwin",
30-
/*includes*/ &["unix", "target_os=\"macos\"", "target_vendor=\"apple\""],
31-
/*disallow*/ &["windows"],
32-
);
33-
check(
34-
/*target*/ "i686-unknown-linux-gnu",
35-
/*includes*/ &["unix", "target_env=\"gnu\""],
36-
/*disallow*/ &["windows"],
37-
);
38-
check(
39-
/*target*/ "arm-unknown-linux-gnueabihf",
40-
/*includes*/ &["unix", "target_abi=\"eabihf\""],
41-
/*disallow*/ &["windows"],
42-
);
24+
check(PrintCfg {
25+
target: "x86_64-pc-windows-gnu",
26+
includes: &["windows", "target_arch=\"x86_64\""],
27+
disallow: &["unix"],
28+
});
29+
check(PrintCfg {
30+
target: "i686-pc-windows-msvc",
31+
includes: &["windows", "target_env=\"msvc\""],
32+
disallow: &["unix"],
33+
});
34+
check(PrintCfg {
35+
target: "i686-apple-darwin",
36+
includes: &["unix", "target_os=\"macos\"", "target_vendor=\"apple\""],
37+
disallow: &["windows"],
38+
});
39+
check(PrintCfg {
40+
target: "i686-unknown-linux-gnu",
41+
includes: &["unix", "target_env=\"gnu\""],
42+
disallow: &["windows"],
43+
});
44+
check(PrintCfg {
45+
target: "arm-unknown-linux-gnueabihf",
46+
includes: &["unix", "target_abi=\"eabihf\""],
47+
disallow: &["windows"],
48+
});
4349
}
4450

45-
fn check(target: &str, includes: &[&str], disallow: &[&str]) {
46-
fn _inner(output: &str, includes: &[&str], disallow: &[&str]) {
51+
fn check(PrintCfg { target, includes, disallow }: PrintCfg) {
52+
fn check_(output: &str, includes: &[&str], disallow: &[&str]) {
4753
let mut found = HashSet::<String>::new();
4854
let mut recorded = HashSet::<String>::new();
4955

@@ -82,7 +88,7 @@ fn check(target: &str, includes: &[&str], disallow: &[&str]) {
8288

8389
let stdout = String::from_utf8(output.stdout).unwrap();
8490

85-
_inner(&stdout, includes, disallow);
91+
check_(&stdout, includes, disallow);
8692
}
8793

8894
// --print=cfg=PATH
@@ -95,6 +101,6 @@ fn check(target: &str, includes: &[&str], disallow: &[&str]) {
95101

96102
let output = std::fs::read_to_string(&tmp_path).unwrap();
97103

98-
_inner(&output, includes, disallow);
104+
check_(&output, includes, disallow);
99105
}
100106
}

tests/run-make/print-to-output/rmake.rs

+32-31
Original file line numberDiff line numberDiff line change
@@ -7,61 +7,62 @@ use std::ffi::OsString;
77

88
use run_make_support::{rustc, target, tmp_dir};
99

10+
struct Option<'a> {
11+
target: &'a str,
12+
option: &'static str,
13+
includes: &'static [&'static str],
14+
}
15+
1016
fn main() {
1117
// Printed from CodegenBackend trait impl in rustc_codegen_llvm/src/lib.rs
12-
check(
13-
/*target*/ &target(),
14-
/*option*/ "relocation-models",
15-
/*includes*/ &["dynamic-no-pic"],
16-
);
18+
check(Option {
19+
target: &target(),
20+
option: "relocation-models",
21+
includes: &["dynamic-no-pic"],
22+
});
1723

1824
// Printed by compiler/rustc_codegen_llvm/src/llvm_util.rs
19-
check(
20-
/*target*/ "wasm32-unknown-unknown",
21-
/*option*/ "target-features",
22-
/*includes*/ &["reference-types"],
23-
);
25+
check(Option {
26+
target: "wasm32-unknown-unknown",
27+
option: "target-features",
28+
includes: &["reference-types"],
29+
});
2430

2531
// Printed by C++ code in rustc_llvm/llvm-wrapper/PassWrapper.cpp
26-
check(
27-
/*target*/ "wasm32-unknown-unknown",
28-
/*option*/ "target-cpus",
29-
/*includes*/ &["generic"],
30-
);
32+
check(Option {
33+
target: "wasm32-unknown-unknown",
34+
option: "target-cpus",
35+
includes: &["generic"],
36+
});
3137
}
3238

33-
fn check(target: &str, option: &str, includes: &[&str]) {
34-
fn _inner(output: &str, includes: &[&str]) {
39+
fn check(args: Option) {
40+
fn check_(output: &str, includes: &[&str]) {
3541
for i in includes {
3642
assert!(output.contains(i), "output doesn't contains: {}", i);
3743
}
3844
}
3945

4046
// --print={option}
4147
let stdout = {
42-
let output = rustc().target(target).print(option).run();
43-
44-
let stdout = String::from_utf8(output.stdout).unwrap();
45-
46-
_inner(&stdout, includes);
48+
let output = rustc().target(args.target).print(args.option).run();
4749

48-
stdout
50+
String::from_utf8(output.stdout).unwrap()
4951
};
5052

5153
// --print={option}=PATH
5254
let output = {
53-
let tmp_path = tmp_dir().join(format!("{option}.txt"));
54-
let mut print_arg = OsString::from(format!("--print={option}="));
55+
let tmp_path = tmp_dir().join(format!("{}.txt", args.option));
56+
let mut print_arg = OsString::from(format!("--print={}=", args.option));
5557
print_arg.push(tmp_path.as_os_str());
5658

57-
let _output = rustc().target(target).arg(print_arg).run();
59+
let _output = rustc().target(args.target).arg(print_arg).run();
5860

59-
let output = std::fs::read_to_string(&tmp_path).unwrap();
60-
61-
_inner(&output, includes);
62-
63-
output
61+
std::fs::read_to_string(&tmp_path).unwrap()
6462
};
6563

64+
check_(&stdout, args.includes);
65+
check_(&output, args.includes);
66+
6667
assert_eq!(&stdout, &output);
6768
}

0 commit comments

Comments
 (0)