mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Do not inject test harness for --cfg test
This commit is contained in:
parent
e24d621fca
commit
f27fbf9a4a
@ -743,7 +743,11 @@ pub fn phase_2_configure_and_expand(sess: &Session,
|
||||
})?;
|
||||
|
||||
krate = time(time_passes, "maybe building test harness", || {
|
||||
syntax::test::modify_for_testing(&sess.parse_sess, &sess.opts.cfg, krate, sess.diagnostic())
|
||||
syntax::test::modify_for_testing(&sess.parse_sess,
|
||||
sess.opts.test,
|
||||
&sess.opts.cfg,
|
||||
krate,
|
||||
sess.diagnostic())
|
||||
});
|
||||
|
||||
krate = time(time_passes,
|
||||
|
@ -68,14 +68,10 @@ struct TestCtxt<'a> {
|
||||
// Traverse the crate, collecting all the test functions, eliding any
|
||||
// existing main functions, and synthesizing a main test harness
|
||||
pub fn modify_for_testing(sess: &ParseSess,
|
||||
should_test: bool,
|
||||
cfg: &ast::CrateConfig,
|
||||
krate: ast::Crate,
|
||||
span_diagnostic: &errors::Handler) -> ast::Crate {
|
||||
// We generate the test harness when building in the 'test'
|
||||
// configuration, either with the '--test' or '--cfg test'
|
||||
// command line options.
|
||||
let should_test = attr::contains_name(&krate.config, "test");
|
||||
|
||||
// Check for #[reexport_test_harness_main = "some_name"] which
|
||||
// creates a `use some_name = __test::main;`. This needs to be
|
||||
// unconditional, so that the attribute is still marked as used in
|
||||
|
18
src/test/run-pass/test-vs-cfg-test.rs
Normal file
18
src/test/run-pass/test-vs-cfg-test.rs
Normal file
@ -0,0 +1,18 @@
|
||||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// compile-flags: --cfg test
|
||||
|
||||
// Make sure `--cfg test` does not inject test harness
|
||||
|
||||
#[test]
|
||||
fn test() { panic!(); }
|
||||
|
||||
fn main() {}
|
Loading…
Reference in New Issue
Block a user