Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: remove the use of CARGO_RUSTC_CURRENT_DIR #14869

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ cargo-credential-macos-keychain = { version = "0.4.7", path = "credential/cargo-
cargo-credential-wincred = { version = "0.4.7", path = "credential/cargo-credential-wincred" }
cargo-platform = { path = "crates/cargo-platform", version = "0.2.0" }
cargo-test-macro = { version = "0.3.0", path = "crates/cargo-test-macro" }
cargo-test-support = { version = "0.6.0", path = "crates/cargo-test-support" }
cargo-test-support = { version = "0.7.0", path = "crates/cargo-test-support" }
cargo-util = { version = "0.2.14", path = "crates/cargo-util" }
cargo-util-schemas = { version = "0.7.0", path = "crates/cargo-util-schemas" }
cargo_metadata = "0.18.1"
Expand Down
2 changes: 1 addition & 1 deletion crates/cargo-test-support/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cargo-test-support"
version = "0.6.1"
version = "0.7.0"
edition.workspace = true
rust-version = "1.83" # MSRV:1
license.workspace = true
Expand Down
27 changes: 25 additions & 2 deletions crates/cargo-test-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,32 @@ macro_rules! t {
}

pub use cargo_util::ProcessBuilder;
pub use snapbox::file;
pub use snapbox::str;
pub use snapbox::utils::current_dir;

/// Find the directory for your source file
#[macro_export]
macro_rules! current_dir {
() => {{
let root = ::std::path::Path::new(::std::env!("CARGO_MANIFEST_DIR"));
let file = ::std::file!();
let rel_path = ::std::path::Path::new(file).parent().unwrap();
root.join(rel_path)
}};
}

/// Declare an expected value for an assert from a file
///
/// This is relative to the source file the macro is run from
///
/// Output type: [`snapbox::Data`]
#[macro_export]
macro_rules! file {
[$path:literal] => {{
let mut path = $crate::current_dir!();
path.push($path);
::snapbox::Data::read_from(&path, None)
}};
}

/// `panic!`, reporting the specified error , see also [`t!`]
#[track_caller]
Expand Down
5 changes: 3 additions & 2 deletions src/cargo/util/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@ mod tests {
use itertools::Itertools;
use snapbox::ToDebug;
use std::collections::HashSet;
use std::path::Path;

#[test]
fn ensure_sorted_lints() {
Expand Down Expand Up @@ -647,7 +648,7 @@ mod tests {

#[test]
fn ensure_updated_lints() {
let path = snapbox::utils::current_rs!();
let path = Path::new(std::env!("CARGO_MANIFEST_DIR")).join(file!());
let expected = std::fs::read_to_string(&path).unwrap();
let expected = expected
.lines()
Expand Down Expand Up @@ -686,7 +687,7 @@ mod tests {

#[test]
fn ensure_updated_lint_groups() {
let path = snapbox::utils::current_rs!();
let path = Path::new(std::env!("CARGO_MANIFEST_DIR")).join(file!());
let expected = std::fs::read_to_string(&path).unwrap();
let expected = expected
.lines()
Expand Down