Skip to content

Commit da846c6

Browse files
committed
test: remove the use of CARGO_RUSTC_CURRENT_DIR
The environment variable has been removed in rust-lang#14799. Switch to plain old `CARGO_MANIFEST_DIR` because snapbox's `current_rs` favors furthest Cargo.toml, blocking tests running in rust-lang/rust as a submodule. See also build failures in rust-lang/rust#133533
1 parent 3908f64 commit da846c6

File tree

5 files changed

+31
-7
lines changed

5 files changed

+31
-7
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ cargo-credential-macos-keychain = { version = "0.4.7", path = "credential/cargo-
3333
cargo-credential-wincred = { version = "0.4.7", path = "credential/cargo-credential-wincred" }
3434
cargo-platform = { path = "crates/cargo-platform", version = "0.2.0" }
3535
cargo-test-macro = { version = "0.3.0", path = "crates/cargo-test-macro" }
36-
cargo-test-support = { version = "0.6.0", path = "crates/cargo-test-support" }
36+
cargo-test-support = { version = "0.7.0", path = "crates/cargo-test-support" }
3737
cargo-util = { version = "0.2.14", path = "crates/cargo-util" }
3838
cargo-util-schemas = { version = "0.7.0", path = "crates/cargo-util-schemas" }
3939
cargo_metadata = "0.18.1"

crates/cargo-test-support/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cargo-test-support"
3-
version = "0.6.1"
3+
version = "0.7.0"
44
edition.workspace = true
55
rust-version = "1.83" # MSRV:1
66
license.workspace = true

crates/cargo-test-support/src/lib.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,32 @@ macro_rules! t {
8080
}
8181

8282
pub use cargo_util::ProcessBuilder;
83-
pub use snapbox::file;
8483
pub use snapbox::str;
85-
pub use snapbox::utils::current_dir;
84+
85+
/// Find the directory for your source file
86+
#[macro_export]
87+
macro_rules! current_dir {
88+
() => {{
89+
let root = ::std::path::Path::new(::std::env!("CARGO_MANIFEST_DIR"));
90+
let file = ::std::file!();
91+
let rel_path = ::std::path::Path::new(file).parent().unwrap();
92+
root.join(rel_path)
93+
}};
94+
}
95+
96+
/// Declare an expected value for an assert from a file
97+
///
98+
/// This is relative to the source file the macro is run from
99+
///
100+
/// Output type: [`snapbox::Data`]
101+
#[macro_export]
102+
macro_rules! file {
103+
[$path:literal] => {{
104+
let mut path = $crate::current_dir!();
105+
path.push($path);
106+
::snapbox::Data::read_from(&path, None)
107+
}};
108+
}
86109

87110
/// `panic!`, reporting the specified error , see also [`t!`]
88111
#[track_caller]

src/cargo/util/lints.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,7 @@ mod tests {
610610
use itertools::Itertools;
611611
use snapbox::ToDebug;
612612
use std::collections::HashSet;
613+
use std::path::Path;
613614

614615
#[test]
615616
fn ensure_sorted_lints() {
@@ -647,7 +648,7 @@ mod tests {
647648

648649
#[test]
649650
fn ensure_updated_lints() {
650-
let path = snapbox::utils::current_rs!();
651+
let path = Path::new(std::env!("CARGO_MANIFEST_DIR")).join(file!());
651652
let expected = std::fs::read_to_string(&path).unwrap();
652653
let expected = expected
653654
.lines()
@@ -686,7 +687,7 @@ mod tests {
686687

687688
#[test]
688689
fn ensure_updated_lint_groups() {
689-
let path = snapbox::utils::current_rs!();
690+
let path = Path::new(std::env!("CARGO_MANIFEST_DIR")).join(file!());
690691
let expected = std::fs::read_to_string(&path).unwrap();
691692
let expected = expected
692693
.lines()

0 commit comments

Comments
 (0)