-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check for
[workspace]
when finding workspace root
Before, the top-most `Cargo.toml` file was used. Now we use the nearest `Cargo.toml` file which contain a line saying `[workspace]`. This should avoid false positives when Cargo workspaces are nested inside each other: in this case, the inner package will have an empty `[workspace]` table.
- Loading branch information
Showing
3 changed files
with
53 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,6 @@ members = ["xtask"] | |
[dependencies] | ||
once_cell = "1" | ||
dissimilar = "1" | ||
|
||
[dev-dependencies] | ||
tempfile = "3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Because this test modifies CARGO_MANIFEST_DIR, it has to be run as | ||
// an integration test. This way we can isolate the modification to | ||
// just one process. | ||
|
||
use std::env; | ||
use std::fs; | ||
use std::path::Path; | ||
|
||
use expect_test::ExpectFile; | ||
|
||
#[test] | ||
fn test_nested_workspaces() -> Result<(), std::io::Error> { | ||
let tmpdir = tempfile::tempdir()?; | ||
let outer_toml = tmpdir.path().join("Cargo.toml"); | ||
let nested = tmpdir.path().join("nested"); | ||
let nested_src = nested.join("src"); | ||
let inner_toml = nested.join("Cargo.toml"); | ||
|
||
fs::write(&outer_toml, r#"[package]\nname = "foo""#)?; | ||
|
||
fs::create_dir(&nested)?; | ||
fs::create_dir(&nested_src)?; | ||
fs::write(&inner_toml, r#"[package]\nname = "bar"\n[workspace]\n"#)?; | ||
|
||
// Fabricate a ExpectFile as if had been created with expect_file! | ||
// inside the nested project. | ||
env::set_var("CARGO_MANIFEST_DIR", nested.as_os_str()); | ||
let expect_file = ExpectFile { path: Path::new("bar.txt").to_owned(), position: "src/lib.rs" }; | ||
// Populate nested/src/bar.txt. | ||
env::set_var("UPDATE_EXPECT", "1"); | ||
expect_file.assert_eq("Expected content"); | ||
|
||
assert_eq!(fs::read_to_string(nested_src.join("bar.txt"))?, "Expected content"); | ||
|
||
Ok(()) | ||
} |