Skip to content

Commit

Permalink
config: Add clean_rmeta method
Browse files Browse the repository at this point in the history
This method removes */deps/*.rmeta files in directories in rustcflags.
These files are created by `cargo check`, and conflict with `cargo
build` rlib files, causing E0464 for tests which use the parent crate.

Fix #78
  • Loading branch information
hdhoang authored and Thomas Bracht Laumann Jespersen committed Dec 29, 2017
1 parent 354d650 commit 31af8e9
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ fn run_mode(mode: &'static str) {
config.mode = mode.parse().expect("Invalid mode");
config.src_base = PathBuf::from(format!("tests/{}", mode));
config.link_deps(); // Populate config.target_rustcflags with dependencies on the path
config.clean_rmeta(); // If your tests import the parent crate, this helps with E0464

compiletest::run_tests(&config);
}
Expand Down
25 changes: 25 additions & 0 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub use self::Mode::*;

use std::env;
use std::fmt;
use std::fs::{read_dir, remove_file};
use std::str::FromStr;
use std::path::PathBuf;
use rustc;
Expand Down Expand Up @@ -246,6 +247,30 @@ impl Config {
self.target_rustcflags = Some(flags);
}

/// Remove rmeta files from target `deps` directory
///
/// These files are created by `cargo check`, and conflict with
/// `cargo build` rlib files, causing E0464 for tests which use
/// the parent crate.
pub fn clean_rmeta(&self) {
if self.target_rustcflags.is_some() {
for directory in self.target_rustcflags
.as_ref()
.unwrap()
.split_whitespace()
.filter(|s| s.ends_with("/deps"))
{
if let Ok(mut entries) = read_dir(directory) {
while let Some(Ok(entry)) = entries.next() {
if entry.file_name().to_string_lossy().ends_with(".rmeta") {
let _ = remove_file(entry.path());
}
}
}
}
}
}

#[cfg(feature = "tmp")]
pub fn tempdir(mut self) -> config_tempdir::ConfigWithTemp {
use tempdir;
Expand Down
6 changes: 0 additions & 6 deletions test-project/tests/compile-fail/with-own-crate.rs

This file was deleted.

3 changes: 3 additions & 0 deletions test-project/tests/run-pass/with-own-crate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
extern crate testp;

fn main() {}
1 change: 1 addition & 0 deletions test-project/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ fn run_mode(mode: &'static str) {
config.mode = cfg_mode;
config.src_base = PathBuf::from(format!("tests/{}", mode));
config.link_deps();
config.clean_rmeta();

compiletest::run_tests(&config);
}
Expand Down

0 comments on commit 31af8e9

Please sign in to comment.