From 15ca92fb370d0d0dc40bae3a7063f8fdb4e00864 Mon Sep 17 00:00:00 2001 From: Amos Wenger Date: Tue, 19 Jul 2022 12:22:53 +0200 Subject: [PATCH 1/2] Use 'CARGO_WORKSPACE_DIR' if present, closes #33 --- src/lib.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 6d2c29c..83fcf35 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -591,11 +591,7 @@ fn lit_kind_for_patch(patch: &str) -> StrLitKind { let has_dquote = patch.chars().any(|c| c == '"'); if !has_dquote { let has_bslash_or_newline = patch.chars().any(|c| matches!(c, '\\' | '\n')); - return if has_bslash_or_newline { - StrLitKind::Raw(1) - } else { - StrLitKind::Normal - }; + return if has_bslash_or_newline { StrLitKind::Raw(1) } else { StrLitKind::Normal }; } // Find the maximum number of hashes that follow a double quote in the string. @@ -649,9 +645,15 @@ fn to_abs_ws_path(path: &Path) -> PathBuf { static WORKSPACE_ROOT: OnceCell = OnceCell::new(); WORKSPACE_ROOT .get_or_try_init(|| { - let my_manifest = env::var("CARGO_MANIFEST_DIR")?; + // Until https://github.com/rust-lang/cargo/issues/3946 is resolved, this + // is set with a hack like https://github.com/rust-lang/cargo/issues/3946#issuecomment-973132993 + if let Ok(workspace_root) = env::var("CARGO_WORKSPACE_DIR") { + return Ok(workspace_root.into()); + } - // Heuristic, see https://github.com/rust-lang/cargo/issues/3946 + // If a hack isn't used, we use a heuristic to find the "top-level" workspace. + // This fails in some cases, see https://github.com/rust-analyzer/expect-test/issues/33 + let my_manifest = env::var("CARGO_MANIFEST_DIR")?; let workspace_root = Path::new(&my_manifest) .ancestors() .filter(|it| it.join("Cargo.toml").exists()) From 8d5c954af18c303177fec02027593fa6387c6b33 Mon Sep 17 00:00:00 2001 From: Amos Wenger Date: Tue, 19 Jul 2022 12:49:07 +0200 Subject: [PATCH 2/2] :arrow_up: 1.4.0 (with changelog entry) --- CHANGELOG.md | 5 +++++ Cargo.toml | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a5ee07d..0d1e5e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 1.4.0 + +* Prefer `CARGO_WORKSPACE_DIR` if set, use heuristic as fallback to find cargo workspace ([#34]) + # 1.3.0 * Add `data()` getter to Expect ([#31]) @@ -13,6 +17,7 @@ * No changelog until this point :-( +[#34]: https://github.com/rust-analyzer/expect-test/pull/34 [#31]: https://github.com/rust-analyzer/expect-test/pull/31 [#27]: https://github.com/rust-analyzer/expect-test/pull/27 [#26]: https://github.com/rust-analyzer/expect-test/pull/26 diff --git a/Cargo.toml b/Cargo.toml index 2139c08..12d2bd6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "expect-test" -version = "1.3.0" +version = "1.4.0" description = "Minimalistic snapshot testing library" keywords = ["snapshot", "testing", "expect"] categories = ["development-tools::testing"]