Skip to content

Commit

Permalink
test(build-std): isolate tests for asserting complete error messages
Browse files Browse the repository at this point in the history
For test `basic, an isolated CARGO_HOME environment is used elesewhere
in this test to ensure no extra index updates is performed.
It is achieve by asserting the complete stderr without any wildcard.

Hence we need to provide a `build_std_isolated` method for it.
  • Loading branch information
weihanglo committed Dec 16, 2024
1 parent 0b9313e commit 2a54190
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions tests/build-std/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ use cargo_test_support::{basic_manifest, paths, project, rustc_host, str, Execs}
use std::env;
use std::path::Path;

fn enable_build_std(e: &mut Execs, arg: Option<&str>) {
e.env_remove("CARGO_HOME");
e.env_remove("HOME");
fn enable_build_std(e: &mut Execs, arg: Option<&str>, isolated: bool) {
if !isolated {
e.env_remove("CARGO_HOME");
e.env_remove("HOME");
}

// And finally actually enable `build-std` for now
let arg = match arg {
Expand All @@ -42,17 +44,23 @@ fn enable_build_std(e: &mut Execs, arg: Option<&str>) {
trait BuildStd: Sized {
fn build_std(&mut self) -> &mut Self;
fn build_std_arg(&mut self, arg: &str) -> &mut Self;
fn build_std_isolated(&mut self) -> &mut Self;
fn target_host(&mut self) -> &mut Self;
}

impl BuildStd for Execs {
fn build_std(&mut self) -> &mut Self {
enable_build_std(self, None);
enable_build_std(self, None, false);
self
}

fn build_std_arg(&mut self, arg: &str) -> &mut Self {
enable_build_std(self, Some(arg));
enable_build_std(self, Some(arg), false);
self
}

fn build_std_isolated(&mut self) -> &mut Self {
enable_build_std(self, None, true);
self
}

Expand Down Expand Up @@ -107,9 +115,12 @@ fn basic() {
)
.build();

p.cargo("check").build_std().target_host().run();
// An isolated CARGO_HOME environment is used elesewhere in this test
// to ensure no extra index updates is performed.
// It is achieve by asserting the complete stderr without any wildcard.
p.cargo("check").build_std_isolated().target_host().run();
p.cargo("build")
.build_std()
.build_std_isolated()
.target_host()
// Importantly, this should not say [UPDATING]
// There have been multiple bugs where every build triggers and update.
Expand All @@ -120,7 +131,7 @@ fn basic() {
"#]])
.run();
p.cargo("run")
.build_std()
.build_std_isolated()
.target_host()
.with_stderr_data(str![[r#"
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
Expand All @@ -129,7 +140,7 @@ fn basic() {
"#]])
.run();
p.cargo("test")
.build_std()
.build_std_isolated()
.target_host()
.with_stderr_data(str![[r#"
[COMPILING] rustc-std-workspace-std [..]
Expand Down Expand Up @@ -379,13 +390,11 @@ fn test_proc_macro() {
.file("src/lib.rs", "")
.build();

// Download dependencies first,
// so we can compare `cargo test` output without any wildcard
p.cargo("fetch").build_std().run();
p.cargo("test --lib")
.env_remove(cargo_util::paths::dylib_path_envvar())
.build_std()
.with_stderr_data(str![[r#"
...
[COMPILING] foo v0.0.0 ([ROOT]/foo)
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] unittests src/lib.rs (target/debug/deps/foo-[HASH])
Expand Down

0 comments on commit 2a54190

Please sign in to comment.