Skip to content

Commit 7a4f059

Browse files
committed
rustc_target: Move tests into a separate unconfigured file
as much as possible.
1 parent 3ad8c88 commit 7a4f059

File tree

2 files changed

+48
-43
lines changed

2 files changed

+48
-43
lines changed

src/librustc_target/spec/mod.rs

Lines changed: 5 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -309,24 +309,14 @@ macro_rules! supported_targets {
309309
}
310310

311311
#[cfg(test)]
312-
mod test_json_encode_decode {
313-
use rustc_serialize::json::ToJson;
314-
use super::Target;
315-
$(use super::$module;)+
312+
mod tests {
313+
mod tests_impl;
316314

315+
// Cannot put this into a separate file without duplication, make an exception.
317316
$(
318-
#[test] // `#[test]` - this is hard to put into a separate file, make an exception
317+
#[test] // `#[test]`
319318
fn $module() {
320-
// Grab the TargetResult struct. If we successfully retrieved
321-
// a Target, then the test JSON encoding/decoding can run for this
322-
// Target on this testing platform (i.e., checking the iOS targets
323-
// only on a Mac test platform).
324-
let _ = $module::target().map(|original| {
325-
original.check_consistency();
326-
let as_json = original.to_json();
327-
let parsed = Target::from_json(as_json).unwrap();
328-
assert_eq!(original, parsed);
329-
});
319+
tests_impl::test_target(super::$module::target());
330320
}
331321
)+
332322
}
@@ -1289,34 +1279,6 @@ impl Target {
12891279
}
12901280
}
12911281
}
1292-
1293-
#[cfg(test)]
1294-
fn check_consistency(&self) {
1295-
// Check that LLD with the given flavor is treated identically to the linker it emulates.
1296-
// If you target really needs to deviate from the rules below, whitelist it
1297-
// and document the reasons.
1298-
assert_eq!(
1299-
self.linker_flavor == LinkerFlavor::Msvc
1300-
|| self.linker_flavor == LinkerFlavor::Lld(LldFlavor::Link),
1301-
self.options.lld_flavor == LldFlavor::Link,
1302-
);
1303-
for args in &[
1304-
&self.options.pre_link_args,
1305-
&self.options.pre_link_args_crt,
1306-
&self.options.late_link_args,
1307-
&self.options.late_link_args_dynamic,
1308-
&self.options.late_link_args_static,
1309-
&self.options.post_link_args,
1310-
] {
1311-
assert_eq!(
1312-
args.get(&LinkerFlavor::Msvc),
1313-
args.get(&LinkerFlavor::Lld(LldFlavor::Link)),
1314-
);
1315-
if args.contains_key(&LinkerFlavor::Msvc) {
1316-
assert_eq!(self.options.lld_flavor, LldFlavor::Link);
1317-
}
1318-
}
1319-
}
13201282
}
13211283

13221284
impl ToJson for Target {
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
use super::super::*;
2+
3+
pub(super) fn test_target(target: TargetResult) {
4+
// Grab the TargetResult struct. If we successfully retrieved
5+
// a Target, then the test JSON encoding/decoding can run for this
6+
// Target on this testing platform (i.e., checking the iOS targets
7+
// only on a Mac test platform).
8+
if let Ok(original) = target {
9+
original.check_consistency();
10+
let as_json = original.to_json();
11+
let parsed = Target::from_json(as_json).unwrap();
12+
assert_eq!(original, parsed);
13+
}
14+
}
15+
16+
impl Target {
17+
fn check_consistency(&self) {
18+
// Check that LLD with the given flavor is treated identically to the linker it emulates.
19+
// If you target really needs to deviate from the rules below, whitelist it
20+
// and document the reasons.
21+
assert_eq!(
22+
self.linker_flavor == LinkerFlavor::Msvc
23+
|| self.linker_flavor == LinkerFlavor::Lld(LldFlavor::Link),
24+
self.options.lld_flavor == LldFlavor::Link,
25+
);
26+
for args in &[
27+
&self.options.pre_link_args,
28+
&self.options.pre_link_args_crt,
29+
&self.options.late_link_args,
30+
&self.options.late_link_args_dynamic,
31+
&self.options.late_link_args_static,
32+
&self.options.post_link_args,
33+
] {
34+
assert_eq!(
35+
args.get(&LinkerFlavor::Msvc),
36+
args.get(&LinkerFlavor::Lld(LldFlavor::Link)),
37+
);
38+
if args.contains_key(&LinkerFlavor::Msvc) {
39+
assert_eq!(self.options.lld_flavor, LldFlavor::Link);
40+
}
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)