librustc_back: json tests for builtin targets
Expand the supported_targets!() macro to also generate a set of JSON encode/decode tests to verify that the parser will encode and decode all of the fields needed for all of the builtin targets. Additionally, add PartialEq to Target and TargetOptions in support of the tests.
This commit is contained in:
parent
eafecbf868
commit
bd194a77d5
@ -79,6 +79,10 @@ fn load_specific(target: &str) -> TargetResult {
|
||||
$triple => {
|
||||
let mut t = try!($module::target());
|
||||
t.options.is_builtin = true;
|
||||
|
||||
// round-trip through the JSON parser to ensure at
|
||||
// run-time that the parser works correctly
|
||||
t = try!(Target::from_json(t.to_json()));
|
||||
debug!("Got builtin target: {:?}", t);
|
||||
Ok(t)
|
||||
},
|
||||
@ -86,6 +90,28 @@ fn load_specific(target: &str) -> TargetResult {
|
||||
_ => Err(format!("Unable to find target: {}", target))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test_json_encode_decode {
|
||||
use serialize::json::ToJson;
|
||||
use super::Target;
|
||||
$(use super::$module;)*
|
||||
|
||||
$(
|
||||
#[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| {
|
||||
let as_json = original.to_json();
|
||||
let parsed = Target::from_json(as_json).unwrap();
|
||||
assert_eq!(original, parsed);
|
||||
});
|
||||
}
|
||||
)*
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@ -148,7 +174,7 @@ fn load_specific(target: &str) -> TargetResult {
|
||||
/// Everything `rustc` knows about how to compile for a specific target.
|
||||
///
|
||||
/// Every field here must be specified, and has no default value.
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(PartialEq, Clone, Debug)]
|
||||
pub struct Target {
|
||||
/// Target triple to pass to LLVM.
|
||||
pub llvm_target: String,
|
||||
@ -175,7 +201,7 @@ pub struct Target {
|
||||
///
|
||||
/// This has an implementation of `Default`, see each field for what the default is. In general,
|
||||
/// these try to take "minimal defaults" that don't assume anything about the runtime they run in.
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(PartialEq, Clone, Debug)]
|
||||
pub struct TargetOptions {
|
||||
/// Whether the target is built-in or loaded from a custom target specification.
|
||||
pub is_builtin: bool,
|
||||
|
Loading…
Reference in New Issue
Block a user