about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorSeo Sanghyeon <sanxiyn@gmail.com>2016-05-24 00:44:44 +0900
committerSeo Sanghyeon <sanxiyn@gmail.com>2016-05-24 00:44:44 +0900
commitf27fbf9a4a9b0191338b59d34dda0ddcfe833754 (patch)
tree39081ca403773b7c173208e99c8f8ef9bcd0985e /src
parente24d621fcacf59fa8ecc1c1af1c4adeded4bddee (diff)
downloadrust-f27fbf9a4a9b0191338b59d34dda0ddcfe833754.tar.gz
rust-f27fbf9a4a9b0191338b59d34dda0ddcfe833754.zip
Do not inject test harness for --cfg test
Diffstat (limited to 'src')
-rw-r--r--src/librustc_driver/driver.rs6
-rw-r--r--src/libsyntax/test.rs6
-rw-r--r--src/test/run-pass/test-vs-cfg-test.rs18
3 files changed, 24 insertions, 6 deletions
diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs
index 1f3df1ff6f2..2965c763ccc 100644
--- a/src/librustc_driver/driver.rs
+++ b/src/librustc_driver/driver.rs
@@ -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,
diff --git a/src/libsyntax/test.rs b/src/libsyntax/test.rs
index 8eeb61e0de4..56485433101 100644
--- a/src/libsyntax/test.rs
+++ b/src/libsyntax/test.rs
@@ -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
diff --git a/src/test/run-pass/test-vs-cfg-test.rs b/src/test/run-pass/test-vs-cfg-test.rs
new file mode 100644
index 00000000000..708fde59888
--- /dev/null
+++ b/src/test/run-pass/test-vs-cfg-test.rs
@@ -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() {}