Skip to content
This repository was archived by the owner on Apr 10, 2026. It is now read-only.

Commit 45bf124

Browse files
committed
add expect-test crate to update rust-gpu rev in tests with cargo xtask update-expect
1 parent 7f19958 commit 45bf124

File tree

5 files changed

+47
-26
lines changed

5 files changed

+47
-26
lines changed

Cargo.lock

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ cargo_metadata = "0.21.0"
4242
cargo-util-schemas = "0.8.2"
4343
semver = "1.0.26"
4444
dunce = "1.0.5"
45+
expect-test = "1.5.1"
4546

4647

4748

crates/cargo-gpu-install/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ tempfile = { workspace = true, optional = true }
2929
test-log.workspace = true
3030
cargo_metadata = { workspace = true, features = ["builder"] }
3131
cargo-util-schemas = "0.8.2"
32+
expect-test = "1.5.1"
3233

3334
[lints]
3435
workspace = true

crates/cargo-gpu-install/src/spirv_source.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -267,24 +267,18 @@ mod test {
267267
use crate::test::TestEnv;
268268
use cargo_metadata::{PackageBuilder, PackageId, Source};
269269
use cargo_util_schemas::manifest::PackageName;
270+
use expect_test::expect;
270271

271272
#[test_log::test]
272273
fn parsing_spirv_std_dep_for_shader_template() {
273274
let shader_template_path = crate::test::shader_crate_template_path();
274275
let source = SpirvSource::get_rust_gpu_deps_from_shader(&shader_template_path).unwrap();
275-
assert_eq!(
276-
source,
277-
SpirvSource::Git {
278-
url: "https://github.com/Rust-GPU/rust-gpu".to_owned(),
279-
rev: "6a67e7b5954f37989ad540a555b5d6969073592e".to_owned()
280-
}
281-
);
282-
}
283-
284-
#[test_log::test]
285-
fn path_sanity() {
286-
let path = std::path::PathBuf::from("./");
287-
assert!(path.is_relative());
276+
expect![[r#"
277+
Git {
278+
url: "https://github.com/Rust-GPU/rust-gpu",
279+
rev: "6a67e7b5954f37989ad540a555b5d6969073592e",
280+
}"#]]
281+
.assert_eq(&format!("{source:#?}"));
288282
}
289283

290284
#[test_log::test]
@@ -299,7 +293,13 @@ mod test {
299293
.to_str()
300294
.map(std::string::ToString::to_string)
301295
.unwrap();
302-
assert_eq!("https___github_com_Rust-GPU_rust-gpu+6a67e7b5", &name);
296+
expect!["https___github_com_Rust-GPU_rust-gpu+6a67e7b5"].assert_eq(&name);
297+
}
298+
299+
#[test_log::test]
300+
fn path_sanity() {
301+
let path = std::path::PathBuf::from("./");
302+
assert!(path.is_relative());
303303
}
304304

305305
#[test_log::test]

crates/xtask/src/main.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
reason = "This is just a workflow tool"
77
)]
88

9+
use std::ffi::OsStr;
910
use anyhow::Context as _;
1011
use clap::Parser as _;
1112

@@ -34,23 +35,17 @@ enum Cli {
3435
#[clap(long)]
3536
git: Option<String>,
3637
},
38+
UpdateExpect,
3739
}
3840

3941
/// run some cmd
40-
fn cmd(args: impl IntoIterator<Item = impl AsRef<str>>) -> anyhow::Result<()> {
42+
fn cmd(args: impl IntoIterator<Item = impl AsRef<OsStr>>) -> anyhow::Result<()> {
4143
let mut args = args.into_iter();
42-
let mut cmd = std::process::Command::new(args.next().context("no args")?.as_ref());
43-
for arg in args {
44-
cmd.arg(arg.as_ref());
45-
}
46-
47-
let output = cmd
48-
.stdout(std::process::Stdio::inherit())
49-
.stderr(std::process::Stdio::inherit())
50-
.output()
44+
let status = std::process::Command::new(args.next().context("no args")?.as_ref())
45+
.args(args)
46+
.status()
5147
.context("cmd failed")?;
52-
anyhow::ensure!(output.status.success());
53-
48+
anyhow::ensure!(status.success());
5449
Ok(())
5550
}
5651

@@ -307,6 +302,13 @@ fn main() -> anyhow::Result<()> {
307302
&DependencyVersion::parse(version.clone(), git.clone())?,
308303
)?;
309304
}
305+
Cli::UpdateExpect => {
306+
let status = std::process::Command::new("cargo")
307+
.args(["nextest", "run"])
308+
.env("UPDATE_EXPECT", "1")
309+
.status()?;
310+
anyhow::ensure!(status.success());
311+
}
310312
}
311313
Ok(())
312314
}

0 commit comments

Comments
 (0)