Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
- fix glob missing members test to use proper expectations
- update code to handle case where glob does not match anything
  • Loading branch information
hjr3 committed May 9, 2017
1 parent 06a1371 commit 9817033
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
15 changes: 11 additions & 4 deletions src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,16 @@ impl<'cfg> Workspace<'cfg> {

let mut expanded_list = Vec::new();
for path in list {
let expanded_paths = expand_member_path(&path, root)?;
expanded_list.extend(expanded_paths);
let pathbuf = root.join(path);
let expanded_paths = expand_member_path(&pathbuf)?;

// If glob does not find any valid paths, then put the original
// path in the expanded list to maintain backwards compatibility.
if expanded_paths.is_empty() {
expanded_list.push(pathbuf);
} else {
expanded_list.extend(expanded_paths);
}
}

for path in expanded_list {
Expand Down Expand Up @@ -536,8 +544,7 @@ impl<'cfg> Workspace<'cfg> {
}
}

fn expand_member_path(member_path: &str, root_path: &Path) -> CargoResult<Vec<PathBuf>> {
let path = root_path.join(member_path);
fn expand_member_path(path: &Path) -> CargoResult<Vec<PathBuf>> {
let path = path.to_str().unwrap();
let res = glob(path).map_err(|e| {
human(format!("could not parse pattern `{}`: {}", &path, e))
Expand Down
13 changes: 8 additions & 5 deletions tests/workspaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1444,7 +1444,7 @@ fn glob_syntax() {
}

#[test]
fn glob_syntax_non_cargo_folder() {
fn glob_syntax_invalid_members() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
Expand All @@ -1459,10 +1459,13 @@ fn glob_syntax_non_cargo_folder() {
.file("crates/bar/src/main.rs", "fn main() {}");
p.build();

assert_that(p.cargo("build"), execs().with_status(0));
assert_that(&p.bin("foo"), existing_file());
assert_that(&p.bin("bar"), is_not(existing_file()));
assert_that(p.cargo("build"),
execs().with_status(101)
.with_stderr("\
error: failed to read `[..]Cargo.toml`
assert_that(&p.root().join("Cargo.lock"), existing_file());
Caused by:
[..]
"));
}

0 comments on commit 9817033

Please sign in to comment.