Skip to content

Commit 47b9fc2

Browse files
committed
rustc: --test overrides the crate_type attribute
1 parent af4e18d commit 47b9fc2

File tree

2 files changed

+30
-13
lines changed

2 files changed

+30
-13
lines changed

src/comp/driver/driver.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ fn compile_upto(sess: session, cfg: ast::crate_cfg,
147147
time(time_passes, "parsing", bind parse_input(sess, cfg, input));
148148
if upto == cu_parse { ret {crate: crate, tcx: none, src: src}; }
149149

150-
sess.building_library =
151-
session::building_library(sess.opts.crate_type, crate);
150+
sess.building_library = session::building_library(
151+
sess.opts.crate_type, crate, sess.opts.test);
152152

153153
crate =
154154
time(time_passes, "configuration",

src/comp/driver/session.rs

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,21 @@ impl session for session {
111111
}
112112
}
113113

114-
fn building_library(req_crate_type: crate_type, crate: @ast::crate) -> bool {
114+
fn building_library(req_crate_type: crate_type, crate: @ast::crate,
115+
testing: bool) -> bool {
115116
alt req_crate_type {
116117
bin_crate. { false }
117118
lib_crate. { true }
118119
unknown_crate. {
119-
alt front::attr::get_meta_item_value_str_by_name(
120-
crate.node.attrs,
121-
"crate_type") {
122-
option::some("lib") { true }
123-
_ { false }
120+
if testing {
121+
false
122+
} else {
123+
alt front::attr::get_meta_item_value_str_by_name(
124+
crate.node.attrs,
125+
"crate_type") {
126+
option::some("lib") { true }
127+
_ { false }
128+
}
124129
}
125130
}
126131
}
@@ -156,31 +161,43 @@ mod test {
156161
#[test]
157162
fn bin_crate_type_attr_results_in_bin_output() {
158163
let crate = make_crate(true, false);
159-
assert !building_library(unknown_crate, crate);
164+
assert !building_library(unknown_crate, crate, false);
160165
}
161166

162167
#[test]
163168
fn lib_crate_type_attr_results_in_lib_output() {
164169
let crate = make_crate(false, true);
165-
assert building_library(unknown_crate, crate);
170+
assert building_library(unknown_crate, crate, false);
166171
}
167172

168173
#[test]
169174
fn bin_option_overrides_lib_crate_type() {
170175
let crate = make_crate(false, true);
171-
assert !building_library(bin_crate, crate);
176+
assert !building_library(bin_crate, crate, false);
172177
}
173178

174179
#[test]
175180
fn lib_option_overrides_bin_crate_type() {
176181
let crate = make_crate(true, false);
177-
assert building_library(lib_crate, crate);
182+
assert building_library(lib_crate, crate, false);
178183
}
179184

180185
#[test]
181186
fn bin_crate_type_is_default() {
182187
let crate = make_crate(false, false);
183-
assert !building_library(unknown_crate, crate);
188+
assert !building_library(unknown_crate, crate, false);
189+
}
190+
191+
#[test]
192+
fn test_option_overrides_lib_crate_type() {
193+
let crate = make_crate(false, true);
194+
assert !building_library(unknown_crate, crate, true);
195+
}
196+
197+
#[test]
198+
fn test_option_does_not_override_requested_lib_type() {
199+
let crate = make_crate(false, false);
200+
assert building_library(lib_crate, crate, true);
184201
}
185202
}
186203

0 commit comments

Comments
 (0)