Skip to content

Commit

Permalink
Auto merge of rust-lang#5662 - ebroto:cargo_tests_invalid_crate, r=fl…
Browse files Browse the repository at this point in the history
…ip1995

cargo-ui tests: check that <dir>/src exists before processing test

I forgot that I had fixed this in a PR I closed some days ago (rust-lang#5643).

Before this change, cargo UI tests could fail when switching between branches if the previous branch had a test that the current branch does not have. The directory is not removed when switching because an ignored `Cargo.lock` file exists, and the code was trying to reach `$DIR/src` unconditionally.

This change will just skip a directory that has no `src` subdirectory.

changelog: none
  • Loading branch information
bors committed May 31, 2020
2 parents 9fdcb13 + 14e9100 commit 9f9877c
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion tests/compile-test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,15 @@ fn run_ui_cargo(config: &mut compiletest::Config) {
}

let src_path = case.path().join("src");
env::set_current_dir(&src_path)?;

// When switching between branches, if the previous branch had a test
// that the current branch does not have, the directory is not removed
// because an ignored Cargo.lock file exists.
if !src_path.exists() {
continue;
}

env::set_current_dir(&src_path)?;
for file in fs::read_dir(&src_path)? {
let file = file?;
if file.file_type()?.is_dir() {
Expand Down

0 comments on commit 9f9877c

Please sign in to comment.