]> git.lizzy.rs Git - rust.git/commitdiff
treat test binaries like all others
authorRalf Jung <post@ralfj.de>
Tue, 27 Nov 2018 14:06:23 +0000 (15:06 +0100)
committerRalf Jung <post@ralfj.de>
Tue, 11 Dec 2018 16:42:18 +0000 (17:42 +0100)
src/bin/cargo-miri.rs
src/bin/miri.rs

index 7e1785fd3b9380a19ebd844aa6b92cc9295084ab..179f11dd56a3d4b7d8d89c05ed73e7b515cece53 100644 (file)
@@ -279,9 +279,8 @@ fn main() {
                 (MiriCommand::Test, "lib") => {
                     // For libraries we call `cargo rustc -- --test <rustc args>`
                     // Notice now that `--test` is a rustc arg rather than a cargo arg. This tells
-                    // rustc to build a test harness which calls all #[test] functions. We don't
-                    // use the harness since we execute each #[test] function's MIR ourselves before
-                    // compilation even completes, but this option is necessary to build the library.
+                    // rustc to build a test harness which calls all #[test] functions.
+                    // We then execute that harness just like any other binary.
                     if let Err(code) = process(
                         vec!["--".to_string(), "--test".to_string()].into_iter().chain(
                             args,
index e88c13305d15425a9c19cc40a7ee0b0e544cf570..c2255d706339d8d6556f79ea8f1e492cff3709de 100644 (file)
@@ -23,8 +23,6 @@
 use rustc_driver::{Compilation, CompilerCalls, RustcDefaultCalls};
 use rustc_driver::driver::{CompileState, CompileController};
 use rustc::session::config::{self, Input, ErrorOutputType};
-use rustc::hir::{self, itemlikevisit};
-use rustc::ty::TyCtxt;
 use rustc_codegen_utils::codegen_backend::CodegenBackend;
 use syntax::ast;
 
@@ -115,43 +113,12 @@ fn after_analysis<'a, 'tcx>(
 
     let tcx = state.tcx.unwrap();
 
-    if std::env::args().any(|arg| arg == "--test") {
-        struct Visitor<'a, 'tcx: 'a> {
-            tcx: TyCtxt<'a, 'tcx, 'tcx>,
-            state: &'a CompileState<'a, 'tcx>,
-            validate: bool,
-        };
-        impl<'a, 'tcx: 'a, 'hir> itemlikevisit::ItemLikeVisitor<'hir> for Visitor<'a, 'tcx> {
-            fn visit_item(&mut self, i: &'hir hir::Item) {
-                if let hir::ItemKind::Fn(.., body_id) = i.node {
-                    if i.attrs.iter().any(|attr| {
-                        attr.name() == "test"
-                    })
-                    {
-                        let did = self.tcx.hir().body_owner_def_id(body_id);
-                        println!(
-                            "running test: {}",
-                            self.tcx.def_path_debug_str(did),
-                        );
-                        miri::eval_main(self.tcx, did, self.validate);
-                        self.state.session.abort_if_errors();
-                    }
-                }
-            }
-            fn visit_trait_item(&mut self, _trait_item: &'hir hir::TraitItem) {}
-            fn visit_impl_item(&mut self, _impl_item: &'hir hir::ImplItem) {}
-        }
-        state.hir_crate.unwrap().visit_all_item_likes(
-            &mut Visitor { tcx, state, validate }
-        );
-    } else if let Some((entry_node_id, _, _)) = *state.session.entry_fn.borrow() {
-        let entry_def_id = tcx.hir().local_def_id(entry_node_id);
-        miri::eval_main(tcx, entry_def_id, validate);
-
-        state.session.abort_if_errors();
-    } else {
-        println!("no main function found, assuming auxiliary build");
-    }
+    let (entry_node_id, _, _) = state.session.entry_fn.borrow().expect("no main function found!");
+    let entry_def_id = tcx.hir().local_def_id(entry_node_id);
+
+    miri::eval_main(tcx, entry_def_id, validate);
+
+    state.session.abort_if_errors();
 }
 
 fn init_early_loggers() {