diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2020-04-11 13:53:12 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2020-04-13 18:37:51 +0300 |
| commit | 7a4f059add44699af6d24abdcfd39f429dd54084 (patch) | |
| tree | bc76caf924b4128c7812ab894575f7b6be90c42d | |
| parent | 3ad8c8858e93020416edef421d489c15e46a0365 (diff) | |
| download | rust-7a4f059add44699af6d24abdcfd39f429dd54084.tar.gz rust-7a4f059add44699af6d24abdcfd39f429dd54084.zip | |
rustc_target: Move tests into a separate unconfigured file
as much as possible.
| -rw-r--r-- | src/librustc_target/spec/mod.rs | 48 | ||||
| -rw-r--r-- | src/librustc_target/spec/tests/tests_impl.rs | 43 |
2 files changed, 48 insertions, 43 deletions
diff --git a/src/librustc_target/spec/mod.rs b/src/librustc_target/spec/mod.rs index a1b99748260..91fd3f8e18e 100644 --- a/src/librustc_target/spec/mod.rs +++ b/src/librustc_target/spec/mod.rs @@ -309,24 +309,14 @@ macro_rules! supported_targets { } #[cfg(test)] - mod test_json_encode_decode { - use rustc_serialize::json::ToJson; - use super::Target; - $(use super::$module;)+ + mod tests { + mod tests_impl; + // Cannot put this into a separate file without duplication, make an exception. $( - #[test] // `#[test]` - this is hard to put into a separate file, make an exception + #[test] // `#[test]` fn $module() { - // Grab the TargetResult struct. If we successfully retrieved - // a Target, then the test JSON encoding/decoding can run for this - // Target on this testing platform (i.e., checking the iOS targets - // only on a Mac test platform). - let _ = $module::target().map(|original| { - original.check_consistency(); - let as_json = original.to_json(); - let parsed = Target::from_json(as_json).unwrap(); - assert_eq!(original, parsed); - }); + tests_impl::test_target(super::$module::target()); } )+ } @@ -1289,34 +1279,6 @@ impl Target { } } } - - #[cfg(test)] - fn check_consistency(&self) { - // Check that LLD with the given flavor is treated identically to the linker it emulates. - // If you target really needs to deviate from the rules below, whitelist it - // and document the reasons. - assert_eq!( - self.linker_flavor == LinkerFlavor::Msvc - || self.linker_flavor == LinkerFlavor::Lld(LldFlavor::Link), - self.options.lld_flavor == LldFlavor::Link, - ); - for args in &[ - &self.options.pre_link_args, - &self.options.pre_link_args_crt, - &self.options.late_link_args, - &self.options.late_link_args_dynamic, - &self.options.late_link_args_static, - &self.options.post_link_args, - ] { - assert_eq!( - args.get(&LinkerFlavor::Msvc), - args.get(&LinkerFlavor::Lld(LldFlavor::Link)), - ); - if args.contains_key(&LinkerFlavor::Msvc) { - assert_eq!(self.options.lld_flavor, LldFlavor::Link); - } - } - } } impl ToJson for Target { diff --git a/src/librustc_target/spec/tests/tests_impl.rs b/src/librustc_target/spec/tests/tests_impl.rs new file mode 100644 index 00000000000..4cf186bdd7c --- /dev/null +++ b/src/librustc_target/spec/tests/tests_impl.rs @@ -0,0 +1,43 @@ +use super::super::*; + +pub(super) fn test_target(target: TargetResult) { + // Grab the TargetResult struct. If we successfully retrieved + // a Target, then the test JSON encoding/decoding can run for this + // Target on this testing platform (i.e., checking the iOS targets + // only on a Mac test platform). + if let Ok(original) = target { + original.check_consistency(); + let as_json = original.to_json(); + let parsed = Target::from_json(as_json).unwrap(); + assert_eq!(original, parsed); + } +} + +impl Target { + fn check_consistency(&self) { + // Check that LLD with the given flavor is treated identically to the linker it emulates. + // If you target really needs to deviate from the rules below, whitelist it + // and document the reasons. + assert_eq!( + self.linker_flavor == LinkerFlavor::Msvc + || self.linker_flavor == LinkerFlavor::Lld(LldFlavor::Link), + self.options.lld_flavor == LldFlavor::Link, + ); + for args in &[ + &self.options.pre_link_args, + &self.options.pre_link_args_crt, + &self.options.late_link_args, + &self.options.late_link_args_dynamic, + &self.options.late_link_args_static, + &self.options.post_link_args, + ] { + assert_eq!( + args.get(&LinkerFlavor::Msvc), + args.get(&LinkerFlavor::Lld(LldFlavor::Link)), + ); + if args.contains_key(&LinkerFlavor::Msvc) { + assert_eq!(self.options.lld_flavor, LldFlavor::Link); + } + } + } +} |
