From 47b9fc278e97435c6ad9044250dde372bc231750 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Tue, 17 Jan 2012 14:37:39 -0800 Subject: [PATCH] rustc: --test overrides the crate_type attribute --- src/comp/driver/driver.rs | 4 ++-- src/comp/driver/session.rs | 39 +++++++++++++++++++++++++++----------- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/comp/driver/driver.rs b/src/comp/driver/driver.rs index a8c1cc8118a..5a771abc24f 100644 --- a/src/comp/driver/driver.rs +++ b/src/comp/driver/driver.rs @@ -147,8 +147,8 @@ fn compile_upto(sess: session, cfg: ast::crate_cfg, time(time_passes, "parsing", bind parse_input(sess, cfg, input)); if upto == cu_parse { ret {crate: crate, tcx: none, src: src}; } - sess.building_library = - session::building_library(sess.opts.crate_type, crate); + sess.building_library = session::building_library( + sess.opts.crate_type, crate, sess.opts.test); crate = time(time_passes, "configuration", diff --git a/src/comp/driver/session.rs b/src/comp/driver/session.rs index b68be2c2f18..0d2679999ff 100644 --- a/src/comp/driver/session.rs +++ b/src/comp/driver/session.rs @@ -111,16 +111,21 @@ impl session for session { } } -fn building_library(req_crate_type: crate_type, crate: @ast::crate) -> bool { +fn building_library(req_crate_type: crate_type, crate: @ast::crate, + testing: bool) -> bool { alt req_crate_type { bin_crate. { false } lib_crate. { true } unknown_crate. { - alt front::attr::get_meta_item_value_str_by_name( - crate.node.attrs, - "crate_type") { - option::some("lib") { true } - _ { false } + if testing { + false + } else { + alt front::attr::get_meta_item_value_str_by_name( + crate.node.attrs, + "crate_type") { + option::some("lib") { true } + _ { false } + } } } } @@ -156,31 +161,43 @@ mod test { #[test] fn bin_crate_type_attr_results_in_bin_output() { let crate = make_crate(true, false); - assert !building_library(unknown_crate, crate); + assert !building_library(unknown_crate, crate, false); } #[test] fn lib_crate_type_attr_results_in_lib_output() { let crate = make_crate(false, true); - assert building_library(unknown_crate, crate); + assert building_library(unknown_crate, crate, false); } #[test] fn bin_option_overrides_lib_crate_type() { let crate = make_crate(false, true); - assert !building_library(bin_crate, crate); + assert !building_library(bin_crate, crate, false); } #[test] fn lib_option_overrides_bin_crate_type() { let crate = make_crate(true, false); - assert building_library(lib_crate, crate); + assert building_library(lib_crate, crate, false); } #[test] fn bin_crate_type_is_default() { let crate = make_crate(false, false); - assert !building_library(unknown_crate, crate); + assert !building_library(unknown_crate, crate, false); + } + + #[test] + fn test_option_overrides_lib_crate_type() { + let crate = make_crate(false, true); + assert !building_library(unknown_crate, crate, true); + } + + #[test] + fn test_option_does_not_override_requested_lib_type() { + let crate = make_crate(false, false); + assert building_library(lib_crate, crate, true); } }