test: Auto-redact host target and alt target

This commit is contained in:
Scott Schafer 2024-06-10 10:07:48 -06:00
parent d7de93777d
commit 6a7b15a61e
No known key found for this signature in database
20 changed files with 46 additions and 36 deletions

View File

@ -36,8 +36,9 @@
//! a problem.
//! - Carriage returns are removed, which can help when running on Windows.
use crate::diff;
use crate::cross_compile::try_alternate;
use crate::paths;
use crate::{diff, rustc_host};
use anyhow::{bail, Context, Result};
use serde_json::Value;
use std::fmt;
@ -173,6 +174,10 @@ fn add_common_redactions(subs: &mut snapbox::Redactions) {
regex!("home/\\.cargo/registry/src/-(?<redacted>[a-z0-9]+)"),
)
.unwrap();
subs.insert("[HOST_TARGET]", rustc_host()).unwrap();
if let Some(alt_target) = try_alternate() {
subs.insert("[ALT_TARGET]", alt_target).unwrap();
}
}
static MIN_LITERAL_REDACTIONS: &[(&str, &str)] = &[

View File

@ -209,18 +209,23 @@ pub fn native_arch() -> &'static str {
///
/// Only use this function on tests that check `cross_compile::disabled`.
pub fn alternate() -> &'static str {
try_alternate().expect("This test should be gated on cross_compile::disabled.")
}
/// A possible alternate target-triple to build with.
pub(crate) fn try_alternate() -> Option<&'static str> {
if cfg!(all(target_os = "macos", target_arch = "aarch64")) {
"x86_64-apple-darwin"
Some("x86_64-apple-darwin")
} else if cfg!(target_os = "macos") {
"x86_64-apple-ios"
Some("x86_64-apple-ios")
} else if cfg!(target_os = "linux") {
"i686-unknown-linux-gnu"
Some("i686-unknown-linux-gnu")
} else if cfg!(all(target_os = "windows", target_env = "msvc")) {
"i686-pc-windows-msvc"
Some("i686-pc-windows-msvc")
} else if cfg!(all(target_os = "windows", target_env = "gnu")) {
"i686-pc-windows-gnu"
Some("i686-pc-windows-gnu")
} else {
panic!("This test should be gated on cross_compile::disabled.");
None
}
}

View File

@ -28,7 +28,7 @@ fn case() {
snapbox::cmd::Command::cargo_ui()
.arg("add")
.arg_line("my-package1 my-package2 --target i686-unknown-linux-gnu")
.arg_line("my-package1 my-package2 --target wasm32-unknown-unknown")
.current_dir(cwd)
.assert()
.success()

View File

@ -5,6 +5,6 @@ name = "cargo-list-test-fixture"
version = "0.0.0"
edition = "2015"
[target.i686-unknown-linux-gnu.dependencies]
[target.wasm32-unknown-unknown.dependencies]
my-package1 = "99999.0.0"
my-package2 = "99999.0.0"

View File

@ -20,9 +20,9 @@
<text xml:space="preserve" class="container fg">
<tspan x="10px" y="28px"><tspan class="fg-green bold"> Updating</tspan><tspan> `dummy-registry` index</tspan>
</tspan>
<tspan x="10px" y="46px"><tspan class="fg-green bold"> Adding</tspan><tspan> my-package1 v99999.0.0 to dependencies for target `i686-unknown-linux-gnu`</tspan>
<tspan x="10px" y="46px"><tspan class="fg-green bold"> Adding</tspan><tspan> my-package1 v99999.0.0 to dependencies for target `wasm32-unknown-unknown`</tspan>
</tspan>
<tspan x="10px" y="64px"><tspan class="fg-green bold"> Adding</tspan><tspan> my-package2 v99999.0.0 to dependencies for target `i686-unknown-linux-gnu`</tspan>
<tspan x="10px" y="64px"><tspan class="fg-green bold"> Adding</tspan><tspan> my-package2 v99999.0.0 to dependencies for target `wasm32-unknown-unknown`</tspan>
</tspan>
<tspan x="10px" y="82px"><tspan class="fg-green bold"> Locking</tspan><tspan> 3 packages to latest compatible versions</tspan>
</tspan>

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -10,7 +10,7 @@ path = "src/main.rs"
[target.x86_64-unknown-freebsd.build-dependencies]
semver = "0.1.0"
[target.x86_64-unknown-linux-gnu.build-dependencies]
[target.wasm32-unknown-unknown.build-dependencies]
semver = "0.1.0"
[dependencies]
@ -20,14 +20,14 @@ semver = "0.1"
toml = "0.1"
clippy = "0.4"
[target.x86_64-unknown-linux-gnu.dependencies]
[target.wasm32-unknown-unknown.dependencies]
dbus = "0.6.2"
[dev-dependencies]
regex = "0.1.1"
serde = "1.0.90"
[target.x86_64-unknown-linux-gnu.dev-dependencies]
[target.wasm32-unknown-unknown.dev-dependencies]
ncurses = "20.0"
[features]

View File

@ -21,7 +21,7 @@
<text xml:space="preserve" class="container fg">
<tspan x="10px" y="28px"><tspan class="fg-green bold"> Removing</tspan><tspan> dbus from dependencies for target `powerpc-unknown-linux-gnu`</tspan>
</tspan>
<tspan x="10px" y="46px"><tspan class="fg-red bold">error</tspan><tspan class="bold">:</tspan><tspan> the dependency `dbus` could not be found in `target.powerpc-unknown-linux-gnu.dependencies`; it is present in `target.x86_64-unknown-linux-gnu.dependencies`</tspan>
<tspan x="10px" y="46px"><tspan class="fg-red bold">error</tspan><tspan class="bold">:</tspan><tspan> the dependency `dbus` could not be found in `target.powerpc-unknown-linux-gnu.dependencies`; it is present in `target.wasm32-unknown-unknown.dependencies`</tspan>
</tspan>
<tspan x="10px" y="64px">
</tspan>

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -28,7 +28,7 @@ fn case() {
snapbox::cmd::Command::cargo_ui()
.arg("remove")
.args(["--target", "x86_64-unknown-linux-gnu", "toml"])
.args(["--target", "wasm32-unknown-unknown", "toml"])
.current_dir(cwd)
.assert()
.code(101)

View File

@ -10,7 +10,7 @@ path = "src/main.rs"
[target.x86_64-unknown-freebsd.build-dependencies]
semver = "0.1.0"
[target.x86_64-unknown-linux-gnu.build-dependencies]
[target.wasm32-unknown-unknown.build-dependencies]
semver = "0.1.0"
[dependencies]
@ -20,14 +20,14 @@ semver = "0.1"
toml = "0.1"
clippy = "0.4"
[target.x86_64-unknown-linux-gnu.dependencies]
[target.wasm32-unknown-unknown.dependencies]
dbus = "0.6.2"
[dev-dependencies]
regex = "0.1.1"
serde = "1.0.90"
[target.x86_64-unknown-linux-gnu.dev-dependencies]
[target.wasm32-unknown-unknown.dev-dependencies]
ncurses = "20.0"
[features]

View File

@ -19,9 +19,9 @@
<rect width="100%" height="100%" y="0" rx="4.5" class="bg" />
<text xml:space="preserve" class="container fg">
<tspan x="10px" y="28px"><tspan class="fg-green bold"> Removing</tspan><tspan> toml from dependencies for target `x86_64-unknown-linux-gnu`</tspan>
<tspan x="10px" y="28px"><tspan class="fg-green bold"> Removing</tspan><tspan> toml from dependencies for target `wasm32-unknown-unknown`</tspan>
</tspan>
<tspan x="10px" y="46px"><tspan class="fg-red bold">error</tspan><tspan class="bold">:</tspan><tspan> the dependency `toml` could not be found in `target.x86_64-unknown-linux-gnu.dependencies`; it is present in `dependencies`</tspan>
<tspan x="10px" y="46px"><tspan class="fg-red bold">error</tspan><tspan class="bold">:</tspan><tspan> the dependency `toml` could not be found in `target.wasm32-unknown-unknown.dependencies`; it is present in `dependencies`</tspan>
</tspan>
<tspan x="10px" y="64px">
</tspan>

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

@ -10,7 +10,7 @@ path = "src/main.rs"
[target.x86_64-unknown-freebsd.build-dependencies]
semver = "0.1.0"
[target.x86_64-unknown-linux-gnu.build-dependencies]
[target.wasm32-unknown-unknown.build-dependencies]
semver = "0.1.0"
[dependencies]
@ -20,14 +20,14 @@ semver = "0.1"
toml = "0.1"
clippy = "0.4"
[target.x86_64-unknown-linux-gnu.dependencies]
[target.wasm32-unknown-unknown.dependencies]
dbus = "0.6.2"
[dev-dependencies]
regex = "0.1.1"
serde = "1.0.90"
[target.x86_64-unknown-linux-gnu.dev-dependencies]
[target.wasm32-unknown-unknown.dev-dependencies]
ncurses = "20.0"
[features]

View File

@ -28,7 +28,7 @@ fn case() {
snapbox::cmd::Command::cargo_ui()
.arg("remove")
.args(["--target", "x86_64-unknown-linux-gnu", "dbus"])
.args(["--target", "wasm32-unknown-unknown", "dbus"])
.current_dir(cwd)
.assert()
.success()

View File

@ -10,7 +10,7 @@ path = "src/main.rs"
[target.x86_64-unknown-freebsd.build-dependencies]
semver = "0.1.0"
[target.x86_64-unknown-linux-gnu.build-dependencies]
[target.wasm32-unknown-unknown.build-dependencies]
semver = "0.1.0"
[dependencies]
@ -24,7 +24,7 @@ clippy = "0.4"
regex = "0.1.1"
serde = "1.0.90"
[target.x86_64-unknown-linux-gnu.dev-dependencies]
[target.wasm32-unknown-unknown.dev-dependencies]
ncurses = "20.0"
[features]

View File

@ -18,7 +18,7 @@
<rect width="100%" height="100%" y="0" rx="4.5" class="bg" />
<text xml:space="preserve" class="container fg">
<tspan x="10px" y="28px"><tspan class="fg-green bold"> Removing</tspan><tspan> dbus from dependencies for target `x86_64-unknown-linux-gnu`</tspan>
<tspan x="10px" y="28px"><tspan class="fg-green bold"> Removing</tspan><tspan> dbus from dependencies for target `wasm32-unknown-unknown`</tspan>
</tspan>
<tspan x="10px" y="46px">
</tspan>

Before

Width:  |  Height:  |  Size: 767 B

After

Width:  |  Height:  |  Size: 765 B

View File

@ -28,7 +28,7 @@ fn case() {
snapbox::cmd::Command::cargo_ui()
.arg("remove")
.args(["--build", "--target", "x86_64-unknown-linux-gnu", "semver"])
.args(["--build", "--target", "wasm32-unknown-unknown", "semver"])
.current_dir(cwd)
.assert()
.success()

View File

@ -17,14 +17,14 @@ semver = "0.1"
toml = "0.1"
clippy = "0.4"
[target.x86_64-unknown-linux-gnu.dependencies]
[target.wasm32-unknown-unknown.dependencies]
dbus = "0.6.2"
[dev-dependencies]
regex = "0.1.1"
serde = "1.0.90"
[target.x86_64-unknown-linux-gnu.dev-dependencies]
[target.wasm32-unknown-unknown.dev-dependencies]
ncurses = "20.0"
[features]

View File

@ -18,7 +18,7 @@
<rect width="100%" height="100%" y="0" rx="4.5" class="bg" />
<text xml:space="preserve" class="container fg">
<tspan x="10px" y="28px"><tspan class="fg-green bold"> Removing</tspan><tspan> semver from build-dependencies for target `x86_64-unknown-linux-gnu`</tspan>
<tspan x="10px" y="28px"><tspan class="fg-green bold"> Removing</tspan><tspan> semver from build-dependencies for target `wasm32-unknown-unknown`</tspan>
</tspan>
<tspan x="10px" y="46px">
</tspan>

Before

Width:  |  Height:  |  Size: 775 B

After

Width:  |  Height:  |  Size: 773 B

View File

@ -28,7 +28,7 @@ fn case() {
snapbox::cmd::Command::cargo_ui()
.arg("remove")
.args(["--dev", "--target", "x86_64-unknown-linux-gnu", "ncurses"])
.args(["--dev", "--target", "wasm32-unknown-unknown", "ncurses"])
.current_dir(cwd)
.assert()
.success()

View File

@ -10,7 +10,7 @@ path = "src/main.rs"
[target.x86_64-unknown-freebsd.build-dependencies]
semver = "0.1.0"
[target.x86_64-unknown-linux-gnu.build-dependencies]
[target.wasm32-unknown-unknown.build-dependencies]
semver = "0.1.0"
[dependencies]
@ -20,7 +20,7 @@ semver = "0.1"
toml = "0.1"
clippy = "0.4"
[target.x86_64-unknown-linux-gnu.dependencies]
[target.wasm32-unknown-unknown.dependencies]
dbus = "0.6.2"
[dev-dependencies]

View File

@ -18,7 +18,7 @@
<rect width="100%" height="100%" y="0" rx="4.5" class="bg" />
<text xml:space="preserve" class="container fg">
<tspan x="10px" y="28px"><tspan class="fg-green bold"> Removing</tspan><tspan> ncurses from dev-dependencies for target `x86_64-unknown-linux-gnu`</tspan>
<tspan x="10px" y="28px"><tspan class="fg-green bold"> Removing</tspan><tspan> ncurses from dev-dependencies for target `wasm32-unknown-unknown`</tspan>
</tspan>
<tspan x="10px" y="46px">
</tspan>

Before

Width:  |  Height:  |  Size: 774 B

After

Width:  |  Height:  |  Size: 772 B