Skip to content

Commit f27fbf9

Browse files
committed
Do not inject test harness for --cfg test
1 parent e24d621 commit f27fbf9

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

src/librustc_driver/driver.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,11 @@ pub fn phase_2_configure_and_expand(sess: &Session,
743743
})?;
744744

745745
krate = time(time_passes, "maybe building test harness", || {
746-
syntax::test::modify_for_testing(&sess.parse_sess, &sess.opts.cfg, krate, sess.diagnostic())
746+
syntax::test::modify_for_testing(&sess.parse_sess,
747+
sess.opts.test,
748+
&sess.opts.cfg,
749+
krate,
750+
sess.diagnostic())
747751
});
748752

749753
krate = time(time_passes,

src/libsyntax/test.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,10 @@ struct TestCtxt<'a> {
6868
// Traverse the crate, collecting all the test functions, eliding any
6969
// existing main functions, and synthesizing a main test harness
7070
pub fn modify_for_testing(sess: &ParseSess,
71+
should_test: bool,
7172
cfg: &ast::CrateConfig,
7273
krate: ast::Crate,
7374
span_diagnostic: &errors::Handler) -> ast::Crate {
74-
// We generate the test harness when building in the 'test'
75-
// configuration, either with the '--test' or '--cfg test'
76-
// command line options.
77-
let should_test = attr::contains_name(&krate.config, "test");
78-
7975
// Check for #[reexport_test_harness_main = "some_name"] which
8076
// creates a `use some_name = __test::main;`. This needs to be
8177
// unconditional, so that the attribute is still marked as used in

src/test/run-pass/test-vs-cfg-test.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-flags: --cfg test
12+
13+
// Make sure `--cfg test` does not inject test harness
14+
15+
#[test]
16+
fn test() { panic!(); }
17+
18+
fn main() {}

0 commit comments

Comments
 (0)