Skip to content

Commit

Permalink
Workspace::open can just take a str
Browse files Browse the repository at this point in the history
  • Loading branch information
sourcefrog committed Nov 8, 2023
1 parent d214257 commit 8e665ec
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ mod test {
let mut list_output = String::new();
let console = Console::new();
let workspace = Workspace::open(
&Utf8Path::new(".")
Utf8Path::new(".")
.canonicalize_utf8()
.expect("Canonicalize source path"),
)
Expand Down
24 changes: 12 additions & 12 deletions src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ struct PackageTop {
}

impl Workspace {
pub fn open(start_dir: &Utf8Path) -> Result<Self> {
let dir = locate_project(start_dir, true)?;
pub fn open<P: AsRef<Utf8Path>>(start_dir: P) -> Result<Self> {
let dir = locate_project(start_dir.as_ref(), true)?;
let cargo_toml_path = dir.join("Cargo.toml");
debug!(?cargo_toml_path, ?dir, "Find root files");
check_interrupted()?;
Expand Down Expand Up @@ -303,12 +303,12 @@ mod test {

#[test]
fn error_opening_outside_of_crate() {
Workspace::open(Utf8Path::new("/")).unwrap_err();
Workspace::open("/").unwrap_err();
}

#[test]
fn open_subdirectory_of_crate_opens_the_crate() {
let workspace = Workspace::open(Utf8Path::new("testdata/tree/factorial/src"))
let workspace = Workspace::open("testdata/tree/factorial/src")
.expect("open source tree from subdirectory");
let root = &workspace.dir;
assert!(root.is_dir());
Expand All @@ -319,16 +319,16 @@ mod test {

#[test]
fn find_root_from_subdirectory_of_workspace_finds_the_workspace_root() {
let root = Workspace::open(Utf8Path::new("testdata/tree/workspace/main"))
let root = Workspace::open("testdata/tree/workspace/main")
.expect("Find root from within workspace/main")
.dir;
assert_eq!(root.file_name(), Some("workspace"), "Wrong root: {root:?}");
}

#[test]
fn find_top_source_files_from_subdirectory_of_workspace() {
let workspace = Workspace::open(Utf8Path::new("testdata/tree/workspace/main"))
.expect("Find workspace root");
let workspace =
Workspace::open("testdata/tree/workspace/main").expect("Find workspace root");
assert_eq!(
workspace
.packages(&PackageFilter::All)
Expand All @@ -352,14 +352,14 @@ mod test {

#[test]
fn auto_packages_in_workspace_subdir_finds_single_package() {
let workspace = Workspace::open(Utf8Path::new("testdata/tree/workspace/main"))
.expect("Find workspace root");
let workspace =
Workspace::open("testdata/tree/workspace/main").expect("Find workspace root");
}

#[test]
fn filter_by_single_package() {
let workspace = Workspace::open(Utf8Path::new("testdata/tree/workspace/main"))
.expect("Find workspace root");
let workspace =
Workspace::open("testdata/tree/workspace/main").expect("Find workspace root");
let root_dir = &workspace.dir;
assert_eq!(
root_dir.file_name(),
Expand Down Expand Up @@ -389,7 +389,7 @@ mod test {

#[test]
fn filter_by_multiple_packages() {
let workspace = Workspace::open(Utf8Path::new("testdata/tree/workspace/main")).unwrap();
let workspace = Workspace::open("testdata/tree/workspace/main").unwrap();
assert_eq!(
workspace.dir.file_name(),
Some("workspace"),
Expand Down

0 comments on commit 8e665ec

Please sign in to comment.