]> git.lizzy.rs Git - rust.git/blob - src/librustc_target/spec/tests/tests_impl.rs
rustc_target: Move tests into a separate unconfigured file
[rust.git] / src / librustc_target / spec / tests / tests_impl.rs
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 }