Skip to content

Introduce test/Project#within #5986

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 13 additions & 16 deletions tests/testsuite/freshness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,11 @@ fn changing_bin_paths_common_target_features_caches_targets() {
"#,
).build();

let a = p.within("a");
let b = p.within("b");

/* Build and rebuild a/. Ensure dep_crate only builds once */
p.cargo("run")
.cwd(p.root().join("a"))
a.cargo("run")
.with_stdout("ftest off")
.with_stderr(
"\
Expand All @@ -323,9 +325,8 @@ fn changing_bin_paths_common_target_features_caches_targets() {
[RUNNING] `[..]target/debug/a[EXE]`
",
).run();
p.cargo("clean -p a").cwd(p.root().join("a")).run();
p.cargo("run")
.cwd(p.root().join("a"))
a.cargo("clean -p a").run();
a.cargo("run")
.with_stdout("ftest off")
.with_stderr(
"\
Expand All @@ -336,8 +337,7 @@ fn changing_bin_paths_common_target_features_caches_targets() {
).run();

/* Build and rebuild b/. Ensure dep_crate only builds once */
p.cargo("run")
.cwd(p.root().join("b"))
b.cargo("run")
.with_stdout("ftest on")
.with_stderr(
"\
Expand All @@ -347,9 +347,8 @@ fn changing_bin_paths_common_target_features_caches_targets() {
[RUNNING] `[..]target/debug/b[EXE]`
",
).run();
p.cargo("clean -p b").cwd(p.root().join("b")).run();
p.cargo("run")
.cwd(p.root().join("b"))
b.cargo("clean -p b").run();
b.cargo("run")
.with_stdout("ftest on")
.with_stderr(
"\
Expand All @@ -361,9 +360,8 @@ 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("run")
.cwd(p.root().join("a"))
a.cargo("clean -p a").run();
a.cargo("run")
.with_stdout("ftest off")
.with_stderr(
"\
Expand All @@ -375,9 +373,8 @@ 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("run")
.cwd(p.root().join("b"))
b.cargo("clean -p b").run();
b.cargo("run")
.with_stdout("ftest on")
.with_stderr(
"\
Expand Down
4 changes: 4 additions & 0 deletions tests/testsuite/support/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,10 @@ impl Project {
self.root.clone()
}

pub fn within<P: AsRef<Path>>(&self, path: P) -> Self {
Project { root: self.root.join(path) }
}

/// Project's target dir, ex: `/path/to/cargo/target/cit/t0/foo/target`
pub fn build_dir(&self) -> PathBuf {
self.root().join("target")
Expand Down
26 changes: 11 additions & 15 deletions tests/testsuite/workspaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1005,20 +1005,18 @@ fn rebuild_please() {
"#,
);
let p = p.build();
let bin = p.within("bin");
let lib = p.within("lib");

p.cargo("run").cwd(p.root().join("bin")).run();
bin.cargo("run").run();

sleep_ms(1000);

t!(t!(File::create(p.root().join("lib/src/lib.rs")))
.write_all(br#"pub fn foo() -> u32 { 1 }"#));

p.cargo("build").cwd(p.root().join("lib")).run();

p.cargo("run")
.cwd(p.root().join("bin"))
.with_status(101)
.run();
lib.cargo("build").run();
bin.cargo("run").with_status(101).run();
}

#[test]
Expand Down Expand Up @@ -1676,13 +1674,14 @@ fn dep_used_with_separate_features() {
).run();
assert!(p.bin("caller1").is_file());
assert!(p.bin("caller2").is_file());
let caller1 = p.within("caller1");
let caller2 = p.within("caller2");

// Build caller1. should build the dep library. Because the features
// are different than the full workspace, it rebuilds.
// Ideally once we solve https://github.com/rust-lang/cargo/issues/3620, then
// a single cargo build at the top level will be enough.
p.cargo("build")
.cwd(p.root().join("caller1"))
caller1.cargo("build")
.with_stderr(
"\
[..]Compiling feat_lib v0.1.0 ([..])
Expand All @@ -1693,16 +1692,13 @@ fn dep_used_with_separate_features() {

// Alternate building caller2/caller1 a few times, just to make sure
// features are being built separately. Should not rebuild anything
p.cargo("build")
.cwd(p.root().join("caller2"))
caller2.cargo("build")
.with_stderr("[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]")
.run();
p.cargo("build")
.cwd(p.root().join("caller1"))
caller1.cargo("build")
.with_stderr("[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]")
.run();
p.cargo("build")
.cwd(p.root().join("caller2"))
caller2.cargo("build")
.with_stderr("[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]")
.run();
}
Expand Down