Skip to content

Commit bd60ac8

Browse files
committed
Auto merge of #6768 - ehuss:cwd-relative, r=alexcrichton
Testsuite: Make `cwd()` relative to project root. It's a fairly common pattern, and it seemed natural to me.
2 parents 5c54fcb + e7124ba commit bd60ac8

15 files changed

+97
-92
lines changed

tests/testsuite/clean.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fn different_dir() {
2929
assert!(p.build_dir().is_dir());
3030

3131
p.cargo("clean")
32-
.cwd(&p.root().join("src"))
32+
.cwd("src")
3333
.with_stdout("")
3434
.run();
3535
assert!(!p.build_dir().is_dir());
@@ -78,7 +78,7 @@ fn clean_multiple_packages() {
7878
assert!(d2_path.is_file());
7979

8080
p.cargo("clean -p d1 -p d2")
81-
.cwd(&p.root().join("src"))
81+
.cwd("src")
8282
.with_stdout("")
8383
.run();
8484
assert!(p.bin("foo").is_file());

tests/testsuite/concurrent.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ fn multiple_installs() {
2929
.file("b/src/main.rs", "fn main() {}");
3030
let p = p.build();
3131

32-
let mut a = p.cargo("install").cwd(p.root().join("a")).build_command();
33-
let mut b = p.cargo("install").cwd(p.root().join("b")).build_command();
32+
let mut a = p.cargo("install").cwd("a").build_command();
33+
let mut b = p.cargo("install").cwd("b").build_command();
3434

3535
a.stdout(Stdio::piped()).stderr(Stdio::piped());
3636
b.stdout(Stdio::piped()).stderr(Stdio::piped());
@@ -87,8 +87,8 @@ fn one_install_should_be_bad() {
8787
.file("b/src/main.rs", "fn main() {}");
8888
let p = p.build();
8989

90-
let mut a = p.cargo("install").cwd(p.root().join("a")).build_command();
91-
let mut b = p.cargo("install").cwd(p.root().join("b")).build_command();
90+
let mut a = p.cargo("install").cwd("a").build_command();
91+
let mut b = p.cargo("install").cwd("b").build_command();
9292

9393
a.stdout(Stdio::piped()).stderr(Stdio::piped());
9494
b.stdout(Stdio::piped()).stderr(Stdio::piped());
@@ -157,8 +157,8 @@ fn multiple_registry_fetches() {
157157
.file("b/src/main.rs", "fn main() {}");
158158
let p = p.build();
159159

160-
let mut a = p.cargo("build").cwd(p.root().join("a")).build_command();
161-
let mut b = p.cargo("build").cwd(p.root().join("b")).build_command();
160+
let mut a = p.cargo("build").cwd("a").build_command();
161+
let mut b = p.cargo("build").cwd("b").build_command();
162162

163163
a.stdout(Stdio::piped()).stderr(Stdio::piped());
164164
b.stdout(Stdio::piped()).stderr(Stdio::piped());
@@ -247,8 +247,8 @@ fn git_same_repo_different_tags() {
247247
);
248248
let p = p.build();
249249

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

253253
a.stdout(Stdio::piped()).stderr(Stdio::piped());
254254
b.stdout(Stdio::piped()).stderr(Stdio::piped());
@@ -316,7 +316,7 @@ fn git_same_branch_different_revs() {
316316

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

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

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

336336
a.stdout(Stdio::piped()).stderr(Stdio::piped());
337337
b.stdout(Stdio::piped()).stderr(Stdio::piped());

tests/testsuite/directory.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -710,9 +710,9 @@ fn workspace_different_locations() {
710710
)
711711
.build();
712712

713-
p.cargo("build").cwd(p.root().join("foo")).run();
713+
p.cargo("build").cwd("foo").run();
714714
p.cargo("build")
715-
.cwd(p.root().join("bar"))
715+
.cwd("bar")
716716
.with_stderr(
717717
"\
718718
[COMPILING] bar [..]

tests/testsuite/fix.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,11 @@ fn broken_fixes_backed_out() {
134134
.build();
135135

136136
// Build our rustc shim
137-
p.cargo("build").cwd(p.root().join("foo")).run();
137+
p.cargo("build").cwd("foo").run();
138138

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

260260
p.cargo("fix --allow-no-vcs")
261261
.env("__CARGO_FIX_YOLO", "1")
262-
.cwd(p.root().join("foo"))
262+
.cwd("foo")
263263
.run();
264264

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

12561256
// Build our rustc shim
1257-
p.cargo("build").cwd(p.root().join("foo")).run();
1257+
p.cargo("build").cwd("foo").run();
12581258

12591259
// Attempt to fix code, but our shim will always fail the second compile
12601260
p.cargo("fix --allow-no-vcs --broken-code")
1261-
.cwd(p.root().join("bar"))
1261+
.cwd("bar")
12621262
.env("RUSTC", p.root().join("foo/target/debug/foo"))
12631263
.with_status(101)
12641264
.with_stderr_contains("[WARNING] failed to automatically apply fixes [..]")
@@ -1306,9 +1306,9 @@ fn fix_in_existing_repo_weird_ignore() {
13061306
// probably be checking if any source file for the current project is
13071307
// ignored.
13081308
p.cargo("fix")
1309-
.cwd(p.root().join("inner"))
1309+
.cwd("inner")
13101310
.with_stderr_contains("[ERROR] no VCS found[..]")
13111311
.with_status(101)
13121312
.run();
1313-
p.cargo("fix").cwd(p.root().join("src")).run();
1313+
p.cargo("fix").cwd("src").run();
13141314
}

tests/testsuite/freshness.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ fn changing_bin_paths_common_target_features_caches_targets() {
339339

340340
/* Build and rebuild a/. Ensure dep_crate only builds once */
341341
p.cargo("run")
342-
.cwd(p.root().join("a"))
342+
.cwd("a")
343343
.with_stdout("ftest off")
344344
.with_stderr(
345345
"\
@@ -350,9 +350,9 @@ fn changing_bin_paths_common_target_features_caches_targets() {
350350
",
351351
)
352352
.run();
353-
p.cargo("clean -p a").cwd(p.root().join("a")).run();
353+
p.cargo("clean -p a").cwd("a").run();
354354
p.cargo("run")
355-
.cwd(p.root().join("a"))
355+
.cwd("a")
356356
.with_stdout("ftest off")
357357
.with_stderr(
358358
"\
@@ -365,7 +365,7 @@ fn changing_bin_paths_common_target_features_caches_targets() {
365365

366366
/* Build and rebuild b/. Ensure dep_crate only builds once */
367367
p.cargo("run")
368-
.cwd(p.root().join("b"))
368+
.cwd("b")
369369
.with_stdout("ftest on")
370370
.with_stderr(
371371
"\
@@ -376,9 +376,9 @@ fn changing_bin_paths_common_target_features_caches_targets() {
376376
",
377377
)
378378
.run();
379-
p.cargo("clean -p b").cwd(p.root().join("b")).run();
379+
p.cargo("clean -p b").cwd("b").run();
380380
p.cargo("run")
381-
.cwd(p.root().join("b"))
381+
.cwd("b")
382382
.with_stdout("ftest on")
383383
.with_stderr(
384384
"\
@@ -391,9 +391,9 @@ fn changing_bin_paths_common_target_features_caches_targets() {
391391

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

407407
/* Build b/ package again. If we cache different feature dep builds correctly,
408408
* this should not cause a rebuild */
409-
p.cargo("clean -p b").cwd(p.root().join("b")).run();
409+
p.cargo("clean -p b").cwd("b").run();
410410
p.cargo("run")
411-
.cwd(p.root().join("b"))
411+
.cwd("b")
412412
.with_stdout("ftest on")
413413
.with_stderr(
414414
"\
@@ -681,7 +681,7 @@ fn same_build_dir_cached_packages() {
681681
.build();
682682

683683
p.cargo("build")
684-
.cwd(p.root().join("a1"))
684+
.cwd("a1")
685685
.with_stderr(&format!(
686686
"\
687687
[COMPILING] d v0.0.1 ({dir}/d)
@@ -694,7 +694,7 @@ fn same_build_dir_cached_packages() {
694694
))
695695
.run();
696696
p.cargo("build")
697-
.cwd(p.root().join("a2"))
697+
.cwd("a2")
698698
.with_stderr(
699699
"\
700700
[COMPILING] a2 v0.0.1 ([CWD])

tests/testsuite/install.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1311,7 +1311,7 @@ fn workspace_uses_workspace_target_dir() {
13111311
.file("bar/src/main.rs", "fn main() {}")
13121312
.build();
13131313

1314-
p.cargo("build --release").cwd(p.root().join("bar")).run();
1314+
p.cargo("build --release").cwd("bar").run();
13151315
cargo_process("install --path")
13161316
.arg(p.root().join("bar"))
13171317
.with_stderr(

tests/testsuite/overrides.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,7 @@ fn no_warnings_when_replace_is_used_in_another_workspace_member() {
10961096
.build();
10971097

10981098
p.cargo("build")
1099-
.cwd(p.root().join("first_crate"))
1099+
.cwd("first_crate")
11001100
.with_stdout("")
11011101
.with_stderr(
11021102
"\
@@ -1108,7 +1108,7 @@ fn no_warnings_when_replace_is_used_in_another_workspace_member() {
11081108
.run();
11091109

11101110
p.cargo("build")
1111-
.cwd(p.root().join("second_crate"))
1111+
.cwd("second_crate")
11121112
.with_stdout("")
11131113
.with_stderr(
11141114
"\

tests/testsuite/package.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ fn ignore_workspace_specifier() {
885885
.build();
886886

887887
p.cargo("package --no-verify")
888-
.cwd(p.root().join("bar"))
888+
.cwd("bar")
889889
.run();
890890

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

11861186
p.cargo("package")
1187-
.cwd(p.root().join("foo"))
1187+
.cwd("foo")
11881188
.masquerade_as_nightly_cargo()
11891189
.run();
11901190

tests/testsuite/path.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ fn override_and_depend() {
881881
.file("b/.cargo/config", r#"paths = ["../a"]"#)
882882
.build();
883883
p.cargo("build")
884-
.cwd(p.root().join("b"))
884+
.cwd("b")
885885
.with_stderr(
886886
"\
887887
[COMPILING] a2 v0.5.0 ([..])

tests/testsuite/profiles.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ fn profile_in_non_root_manifest_triggers_a_warning() {
273273
.build();
274274

275275
p.cargo("build -v")
276-
.cwd(p.root().join("bar"))
276+
.cwd("bar")
277277
.with_stderr(
278278
"\
279279
[WARNING] profiles for the non root package will be ignored, specify profiles at the workspace root:
@@ -315,7 +315,7 @@ fn profile_in_virtual_manifest_works() {
315315
.build();
316316

317317
p.cargo("build -v")
318-
.cwd(p.root().join("bar"))
318+
.cwd("bar")
319319
.with_stderr(
320320
"\
321321
[COMPILING] bar v0.1.0 ([..])

tests/testsuite/publish.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ fn publish_in_sub_repo() {
457457
.build();
458458

459459
p.cargo("publish")
460-
.cwd(p.root().join("bar"))
460+
.cwd("bar")
461461
.arg("--index")
462462
.arg(registry_url().to_string())
463463
.run();
@@ -531,7 +531,7 @@ fn ignore_when_crate_ignored() {
531531
)
532532
.nocommit_file("bar/src/main.rs", "fn main() {}");
533533
p.cargo("publish")
534-
.cwd(p.root().join("bar"))
534+
.cwd("bar")
535535
.arg("--index")
536536
.arg(registry_url().to_string())
537537
.run();

tests/testsuite/run.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,7 @@ fn run_multiple_packages() {
10291029

10301030
let cargo = || {
10311031
let mut process_builder = p.cargo("run");
1032-
process_builder.cwd(p.root().join("foo"));
1032+
process_builder.cwd("foo");
10331033
process_builder
10341034
};
10351035

tests/testsuite/support/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,12 @@ impl Execs {
749749

750750
pub fn cwd<T: AsRef<OsStr>>(&mut self, path: T) -> &mut Self {
751751
if let Some(ref mut p) = self.process_builder {
752-
p.cwd(path);
752+
if let Some(cwd) = p.get_cwd() {
753+
p.cwd(cwd.join(path.as_ref()));
754+
} else {
755+
p.cwd(path);
756+
757+
}
753758
}
754759
self
755760
}

tests/testsuite/tool_paths.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ fn relative_tools() {
105105

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

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

0 commit comments

Comments
 (0)