Skip to content

Commit fcbf790

Browse files
committed
test: remove the use of CARGO_RUSTC_CURRENT_DIR
The environment variable has been removed in #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 81e0670 commit fcbf790

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

.cargo/config.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,3 @@ build-man = "run --package xtask-build-man --"
33
stale-label = "run --package xtask-stale-label --"
44
bump-check = "run --package xtask-bump-check --"
55
lint-docs = "run --package xtask-lint-docs --"
6-
7-
[env]
8-
# HACK: Until this is stabilized, `snapbox`s polyfill could get confused
9-
# inside of the rust-lang/rust repo because it looks for the furthest-away `Cargo.toml`
10-
CARGO_RUSTC_CURRENT_DIR = { value = "", relative = 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)