Skip to content

Commit

Permalink
Specify packages as URLs including the directory
Browse files Browse the repository at this point in the history
  • Loading branch information
sourcefrog committed Jan 4, 2025
1 parent eb840c3 commit c8b759c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 43 deletions.
10 changes: 7 additions & 3 deletions src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub fn cargo_bin() -> String {
/// cargo binary itself.
// (This is split out so it's easier to test.)
fn cargo_argv(
_build_bir: &Utf8Path,
build_dir: &Utf8Path,
packages: &PackageSelection,
phase: Phase,
options: &Options,
Expand Down Expand Up @@ -149,7 +149,11 @@ fn cargo_argv(
cargo_args.push("--workspace".to_string());
}
PackageSelection::Explicit(packages) => {
cargo_args.extend(packages.iter().map(|p| format!("--package={}", p.name)));
cargo_args.extend(
packages
.iter()
.map(|p| format!("--package={}", p.to_path_url(&build_dir))),
);
}
}
let features = &options.features;
Expand Down Expand Up @@ -263,7 +267,7 @@ mod test {
"check",
"--tests",
"--verbose",
"--package=cargo-mutants-testdata-something",
"--package=path+file:///tmp/xyz#cargo-mutants-testdata-something",
]
);

Expand Down
9 changes: 9 additions & 0 deletions src/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ impl Package {
relative_dir,
})
}

pub fn to_path_url(&self, dir: &Utf8Path) -> String {
let mut dir = dir.to_string();
if !self.relative_dir.as_str().is_empty() {
dir.push('/');
dir.push_str(self.relative_dir.as_str());
}
format!("path+file://{dir}#{name}", name = self.name)
}
}

/// Find all the files that are named in the `path` of targets in a
Expand Down
48 changes: 8 additions & 40 deletions tests/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,38 +130,19 @@ fn workspace_tree_is_well_tested() {
assert_eq!(baseline_phases.len(), 2);
assert_eq!(baseline_phases[0]["process_status"], "Success");
assert_eq!(
baseline_phases[0]["argv"]
.as_array()
.unwrap()
baseline_phases[0]["argv"].as_array().unwrap()[1..=3]
.iter()
.map(|v| v.as_str().unwrap())
.skip(1)
.collect_vec(),
[
"test",
"--no-run",
"--verbose",
"--package=cargo_mutants_testdata_workspace_utils",
"--package=main",
"--package=main2"
]
["test", "--no-run", "--verbose"]
);
assert_eq!(baseline_phases[1]["process_status"], "Success");
assert_eq!(
baseline_phases[1]["argv"]
.as_array()
.unwrap()
baseline_phases[1]["argv"].as_array().unwrap()[1..=2]
.iter()
.map(|v| v.as_str().unwrap())
.skip(1)
.collect_vec(),
[
"test",
"--verbose",
"--package=cargo_mutants_testdata_workspace_utils",
"--package=main",
"--package=main2"
],
["test", "--verbose"],
);
}

Expand Down Expand Up @@ -192,32 +173,19 @@ fn workspace_tree_is_well_tested() {
assert_eq!(baseline_phases.len(), 2);
assert_eq!(baseline_phases[0]["process_status"], "Success");
assert_eq!(
baseline_phases[0]["argv"].as_array().unwrap()[1..]
baseline_phases[0]["argv"].as_array().unwrap()[1..=3]
.iter()
.map(|v| v.as_str().unwrap())
.collect_vec(),
[
"test",
"--no-run",
"--verbose",
"--package=cargo_mutants_testdata_workspace_utils",
"--package=main",
"--package=main2"
],
["test", "--no-run", "--verbose",],
);
assert_eq!(baseline_phases[1]["process_status"], "Success");
assert_eq!(
baseline_phases[1]["argv"].as_array().unwrap()[1..]
baseline_phases[1]["argv"].as_array().unwrap()[1..=2]
.iter()
.map(|v| v.as_str().unwrap())
.collect_vec(),
[
"test",
"--verbose",
"--package=cargo_mutants_testdata_workspace_utils",
"--package=main",
"--package=main2"
],
["test", "--verbose",],
);
}
}
Expand Down

0 comments on commit c8b759c

Please sign in to comment.