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: Make curr_dir work in/out of workspace #10658

Merged
merged 1 commit into from
May 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 14 additions & 1 deletion crates/cargo-test-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,23 @@ macro_rules! t {
#[macro_export]
macro_rules! curr_dir {
() => {
std::path::Path::new(file!()).parent().unwrap()
$crate::_curr_dir(std::path::Path::new(file!()));
};
}

#[doc(hidden)]
pub fn _curr_dir(mut file_path: &'static Path) -> &'static Path {
if !file_path.exists() {
// HACK: Must be running in the rust-lang/rust workspace, adjust the paths accordingly.
let prefix = PathBuf::from("src").join("tools").join("cargo");
if let Ok(crate_relative) = file_path.strip_prefix(prefix) {
file_path = crate_relative
}
}
assert!(file_path.exists(), "{} does not exist", file_path.display());
file_path.parent().unwrap()
}

#[track_caller]
pub fn panic_error(what: &str, err: impl Into<anyhow::Error>) -> ! {
let err = err.into();
Expand Down