Skip to content

Commit

Permalink
Auto merge of #6768 - ehuss:cwd-relative, r=alexcrichton
Browse files Browse the repository at this point in the history
Testsuite: Make `cwd()` relative to project root.

It's a fairly common pattern, and it seemed natural to me.
  • Loading branch information
bors committed Mar 21, 2019
2 parents 5c54fcb + e7124ba commit bd60ac8
Show file tree
Hide file tree
Showing 15 changed files with 97 additions and 92 deletions.
4 changes: 2 additions & 2 deletions tests/testsuite/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn different_dir() {
assert!(p.build_dir().is_dir());

p.cargo("clean")
.cwd(&p.root().join("src"))
.cwd("src")
.with_stdout("")
.run();
assert!(!p.build_dir().is_dir());
Expand Down Expand Up @@ -78,7 +78,7 @@ fn clean_multiple_packages() {
assert!(d2_path.is_file());

p.cargo("clean -p d1 -p d2")
.cwd(&p.root().join("src"))
.cwd("src")
.with_stdout("")
.run();
assert!(p.bin("foo").is_file());
Expand Down
22 changes: 11 additions & 11 deletions tests/testsuite/concurrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ fn multiple_installs() {
.file("b/src/main.rs", "fn main() {}");
let p = p.build();

let mut a = p.cargo("install").cwd(p.root().join("a")).build_command();
let mut b = p.cargo("install").cwd(p.root().join("b")).build_command();
let mut a = p.cargo("install").cwd("a").build_command();
let mut b = p.cargo("install").cwd("b").build_command();

a.stdout(Stdio::piped()).stderr(Stdio::piped());
b.stdout(Stdio::piped()).stderr(Stdio::piped());
Expand Down Expand Up @@ -87,8 +87,8 @@ fn one_install_should_be_bad() {
.file("b/src/main.rs", "fn main() {}");
let p = p.build();

let mut a = p.cargo("install").cwd(p.root().join("a")).build_command();
let mut b = p.cargo("install").cwd(p.root().join("b")).build_command();
let mut a = p.cargo("install").cwd("a").build_command();
let mut b = p.cargo("install").cwd("b").build_command();

a.stdout(Stdio::piped()).stderr(Stdio::piped());
b.stdout(Stdio::piped()).stderr(Stdio::piped());
Expand Down Expand Up @@ -157,8 +157,8 @@ fn multiple_registry_fetches() {
.file("b/src/main.rs", "fn main() {}");
let p = p.build();

let mut a = p.cargo("build").cwd(p.root().join("a")).build_command();
let mut b = p.cargo("build").cwd(p.root().join("b")).build_command();
let mut a = p.cargo("build").cwd("a").build_command();
let mut b = p.cargo("build").cwd("b").build_command();

a.stdout(Stdio::piped()).stderr(Stdio::piped());
b.stdout(Stdio::piped()).stderr(Stdio::piped());
Expand Down Expand Up @@ -247,8 +247,8 @@ fn git_same_repo_different_tags() {
);
let p = p.build();

let mut a = p.cargo("build -v").cwd(p.root().join("a")).build_command();
let mut b = p.cargo("build -v").cwd(p.root().join("b")).build_command();
let mut a = p.cargo("build -v").cwd("a").build_command();
let mut b = p.cargo("build -v").cwd("b").build_command();

a.stdout(Stdio::piped()).stderr(Stdio::piped());
b.stdout(Stdio::piped()).stderr(Stdio::piped());
Expand Down Expand Up @@ -316,7 +316,7 @@ fn git_same_branch_different_revs() {

// Generate a Cargo.lock pointing at the current rev, then clear out the
// target directory
p.cargo("build").cwd(p.root().join("a")).run();
p.cargo("build").cwd("a").run();
fs::remove_dir_all(p.root().join("a/target")).unwrap();

// Make a new commit on the master branch
Expand All @@ -330,8 +330,8 @@ fn git_same_branch_different_revs() {

// Now run both builds in parallel. The build of `b` should pick up the
// newest commit while the build of `a` should use the locked old commit.
let mut a = p.cargo("build").cwd(p.root().join("a")).build_command();
let mut b = p.cargo("build").cwd(p.root().join("b")).build_command();
let mut a = p.cargo("build").cwd("a").build_command();
let mut b = p.cargo("build").cwd("b").build_command();

a.stdout(Stdio::piped()).stderr(Stdio::piped());
b.stdout(Stdio::piped()).stderr(Stdio::piped());
Expand Down
4 changes: 2 additions & 2 deletions tests/testsuite/directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -710,9 +710,9 @@ fn workspace_different_locations() {
)
.build();

p.cargo("build").cwd(p.root().join("foo")).run();
p.cargo("build").cwd("foo").run();
p.cargo("build")
.cwd(p.root().join("bar"))
.cwd("bar")
.with_stderr(
"\
[COMPILING] bar [..]
Expand Down
14 changes: 7 additions & 7 deletions tests/testsuite/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ fn broken_fixes_backed_out() {
.build();

// Build our rustc shim
p.cargo("build").cwd(p.root().join("foo")).run();
p.cargo("build").cwd("foo").run();

// Attempt to fix code, but our shim will always fail the second compile
p.cargo("fix --allow-no-vcs --lib")
.cwd(p.root().join("bar"))
.cwd("bar")
.env("__CARGO_FIX_YOLO", "1")
.env("RUSTC", p.root().join("foo/target/debug/foo"))
.with_stderr_contains(
Expand Down Expand Up @@ -259,7 +259,7 @@ fn do_not_fix_non_relevant_deps() {

p.cargo("fix --allow-no-vcs")
.env("__CARGO_FIX_YOLO", "1")
.cwd(p.root().join("foo"))
.cwd("foo")
.run();

assert!(p.read_file("bar/src/lib.rs").contains("mut"));
Expand Down Expand Up @@ -1254,11 +1254,11 @@ fn fix_to_broken_code() {
.build();

// Build our rustc shim
p.cargo("build").cwd(p.root().join("foo")).run();
p.cargo("build").cwd("foo").run();

// Attempt to fix code, but our shim will always fail the second compile
p.cargo("fix --allow-no-vcs --broken-code")
.cwd(p.root().join("bar"))
.cwd("bar")
.env("RUSTC", p.root().join("foo/target/debug/foo"))
.with_status(101)
.with_stderr_contains("[WARNING] failed to automatically apply fixes [..]")
Expand Down Expand Up @@ -1306,9 +1306,9 @@ fn fix_in_existing_repo_weird_ignore() {
// probably be checking if any source file for the current project is
// ignored.
p.cargo("fix")
.cwd(p.root().join("inner"))
.cwd("inner")
.with_stderr_contains("[ERROR] no VCS found[..]")
.with_status(101)
.run();
p.cargo("fix").cwd(p.root().join("src")).run();
p.cargo("fix").cwd("src").run();
}
24 changes: 12 additions & 12 deletions tests/testsuite/freshness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ fn changing_bin_paths_common_target_features_caches_targets() {

/* Build and rebuild a/. Ensure dep_crate only builds once */
p.cargo("run")
.cwd(p.root().join("a"))
.cwd("a")
.with_stdout("ftest off")
.with_stderr(
"\
Expand All @@ -350,9 +350,9 @@ fn changing_bin_paths_common_target_features_caches_targets() {
",
)
.run();
p.cargo("clean -p a").cwd(p.root().join("a")).run();
p.cargo("clean -p a").cwd("a").run();
p.cargo("run")
.cwd(p.root().join("a"))
.cwd("a")
.with_stdout("ftest off")
.with_stderr(
"\
Expand All @@ -365,7 +365,7 @@ fn changing_bin_paths_common_target_features_caches_targets() {

/* Build and rebuild b/. Ensure dep_crate only builds once */
p.cargo("run")
.cwd(p.root().join("b"))
.cwd("b")
.with_stdout("ftest on")
.with_stderr(
"\
Expand All @@ -376,9 +376,9 @@ fn changing_bin_paths_common_target_features_caches_targets() {
",
)
.run();
p.cargo("clean -p b").cwd(p.root().join("b")).run();
p.cargo("clean -p b").cwd("b").run();
p.cargo("run")
.cwd(p.root().join("b"))
.cwd("b")
.with_stdout("ftest on")
.with_stderr(
"\
Expand All @@ -391,9 +391,9 @@ fn changing_bin_paths_common_target_features_caches_targets() {

/* Build a/ package again. If we cache different feature dep builds correctly,
* this should not cause a rebuild of dep_crate */
p.cargo("clean -p a").cwd(p.root().join("a")).run();
p.cargo("clean -p a").cwd("a").run();
p.cargo("run")
.cwd(p.root().join("a"))
.cwd("a")
.with_stdout("ftest off")
.with_stderr(
"\
Expand All @@ -406,9 +406,9 @@ fn changing_bin_paths_common_target_features_caches_targets() {

/* Build b/ package again. If we cache different feature dep builds correctly,
* this should not cause a rebuild */
p.cargo("clean -p b").cwd(p.root().join("b")).run();
p.cargo("clean -p b").cwd("b").run();
p.cargo("run")
.cwd(p.root().join("b"))
.cwd("b")
.with_stdout("ftest on")
.with_stderr(
"\
Expand Down Expand Up @@ -681,7 +681,7 @@ fn same_build_dir_cached_packages() {
.build();

p.cargo("build")
.cwd(p.root().join("a1"))
.cwd("a1")
.with_stderr(&format!(
"\
[COMPILING] d v0.0.1 ({dir}/d)
Expand All @@ -694,7 +694,7 @@ fn same_build_dir_cached_packages() {
))
.run();
p.cargo("build")
.cwd(p.root().join("a2"))
.cwd("a2")
.with_stderr(
"\
[COMPILING] a2 v0.0.1 ([CWD])
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1311,7 +1311,7 @@ fn workspace_uses_workspace_target_dir() {
.file("bar/src/main.rs", "fn main() {}")
.build();

p.cargo("build --release").cwd(p.root().join("bar")).run();
p.cargo("build --release").cwd("bar").run();
cargo_process("install --path")
.arg(p.root().join("bar"))
.with_stderr(
Expand Down
4 changes: 2 additions & 2 deletions tests/testsuite/overrides.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,7 @@ fn no_warnings_when_replace_is_used_in_another_workspace_member() {
.build();

p.cargo("build")
.cwd(p.root().join("first_crate"))
.cwd("first_crate")
.with_stdout("")
.with_stderr(
"\
Expand All @@ -1108,7 +1108,7 @@ fn no_warnings_when_replace_is_used_in_another_workspace_member() {
.run();

p.cargo("build")
.cwd(p.root().join("second_crate"))
.cwd("second_crate")
.with_stdout("")
.with_stderr(
"\
Expand Down
4 changes: 2 additions & 2 deletions tests/testsuite/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ fn ignore_workspace_specifier() {
.build();

p.cargo("package --no-verify")
.cwd(p.root().join("bar"))
.cwd("bar")
.run();

let f = File::open(&p.root().join("target/package/bar-0.1.0.crate")).unwrap();
Expand Down Expand Up @@ -1184,7 +1184,7 @@ fn lock_file_and_workspace() {
.build();

p.cargo("package")
.cwd(p.root().join("foo"))
.cwd("foo")
.masquerade_as_nightly_cargo()
.run();

Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ fn override_and_depend() {
.file("b/.cargo/config", r#"paths = ["../a"]"#)
.build();
p.cargo("build")
.cwd(p.root().join("b"))
.cwd("b")
.with_stderr(
"\
[COMPILING] a2 v0.5.0 ([..])
Expand Down
4 changes: 2 additions & 2 deletions tests/testsuite/profiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ fn profile_in_non_root_manifest_triggers_a_warning() {
.build();

p.cargo("build -v")
.cwd(p.root().join("bar"))
.cwd("bar")
.with_stderr(
"\
[WARNING] profiles for the non root package will be ignored, specify profiles at the workspace root:
Expand Down Expand Up @@ -315,7 +315,7 @@ fn profile_in_virtual_manifest_works() {
.build();

p.cargo("build -v")
.cwd(p.root().join("bar"))
.cwd("bar")
.with_stderr(
"\
[COMPILING] bar v0.1.0 ([..])
Expand Down
4 changes: 2 additions & 2 deletions tests/testsuite/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ fn publish_in_sub_repo() {
.build();

p.cargo("publish")
.cwd(p.root().join("bar"))
.cwd("bar")
.arg("--index")
.arg(registry_url().to_string())
.run();
Expand Down Expand Up @@ -531,7 +531,7 @@ fn ignore_when_crate_ignored() {
)
.nocommit_file("bar/src/main.rs", "fn main() {}");
p.cargo("publish")
.cwd(p.root().join("bar"))
.cwd("bar")
.arg("--index")
.arg(registry_url().to_string())
.run();
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@ fn run_multiple_packages() {

let cargo = || {
let mut process_builder = p.cargo("run");
process_builder.cwd(p.root().join("foo"));
process_builder.cwd("foo");
process_builder
};

Expand Down
7 changes: 6 additions & 1 deletion tests/testsuite/support/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,12 @@ impl Execs {

pub fn cwd<T: AsRef<OsStr>>(&mut self, path: T) -> &mut Self {
if let Some(ref mut p) = self.process_builder {
p.cwd(path);
if let Some(cwd) = p.get_cwd() {
p.cwd(cwd.join(path.as_ref()));
} else {
p.cwd(path);

}
}
self
}
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/tool_paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ fn relative_tools() {

let prefix = p.root().into_os_string().into_string().unwrap();

p.cargo("build --verbose").cwd(p.root().join("bar")).with_stderr(&format!(
p.cargo("build --verbose").cwd("bar").with_stderr(&format!(
"\
[COMPILING] bar v0.5.0 ([CWD])
[RUNNING] `rustc [..] -C ar={prefix}/./nonexistent-ar -C linker={prefix}/./tools/nonexistent-linker [..]`
Expand Down
Loading

0 comments on commit bd60ac8

Please sign in to comment.