Skip to content

Commit

Permalink
treat test binaries like all others
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Dec 2, 2018
1 parent 16c23ef commit 5a17c17
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 43 deletions.
7 changes: 3 additions & 4 deletions src/bin/cargo-miri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,7 @@ 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.
if let Err(code) = process(
vec!["--".to_string(), "--test".to_string()].into_iter().chain(
args,
Expand Down Expand Up @@ -326,8 +324,9 @@ fn main() {
};

args.extend_from_slice(&["--cfg".to_owned(), r#"feature="cargo-miri""#.to_owned()]);
command.args(&args);

match command.args(&args).status() {
match command.status() {
Ok(exit) => {
if !exit.success() {
std::process::exit(exit.code().unwrap_or(42));
Expand Down
45 changes: 6 additions & 39 deletions src/bin/miri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ use rustc_metadata::cstore::CStore;
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;

Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 5a17c17

Please sign in to comment.