Skip to content

Commit d4450f3

Browse files
authored
Remove a bunch of duplication in show_settings tests by using diffs (#19654)
## Summary The `show_settings` tests are kind of a volumetric nightmare to look at and work with. This PR reduces a bunch of their bulk by using diffs between consecutive snapshots to highlight differences in output rather than snapshotting the same gigantic settings dump every time. The next step would be to use some common baseline "default" output and diff against that for the initial snapshots, but one thing at a time... I've carefully checked that the tests are fully preserved and no test case has been lost or mangled... ## Test Plan N/A
1 parent 8d28332 commit d4450f3

2 files changed

Lines changed: 2442 additions & 4749 deletions

File tree

‎crates/uv-test/src/lib.rs‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1980,6 +1980,40 @@ pub fn diff_snapshot(old: &str, new: &str) -> String {
19801980
.into_owned()
19811981
}
19821982

1983+
/// Assert a snapshot of the diff between `old` and a command's output.
1984+
///
1985+
/// Returns the command's snapshot, this is useful for chaining diffs.
1986+
#[macro_export]
1987+
macro_rules! diff_uv_snapshot {
1988+
($filters:expr, $old:expr, $spawnable:expr, @$snapshot:literal) => {{
1989+
let (new, _) = $crate::run_and_format(
1990+
$spawnable,
1991+
&$filters,
1992+
$crate::function_name!(),
1993+
Some($crate::WindowsFilters::Platform),
1994+
None,
1995+
);
1996+
::insta::assert_snapshot!($crate::diff_snapshot($old, &new), @$snapshot);
1997+
new
1998+
}};
1999+
}
2000+
2001+
/// Assert and capture a snapshot of a command's output.
2002+
#[macro_export]
2003+
macro_rules! capture_uv_snapshot {
2004+
($filters:expr, $spawnable:expr, @$snapshot:literal) => {{
2005+
let (snapshot, _) = $crate::run_and_format(
2006+
$spawnable,
2007+
&$filters,
2008+
$crate::function_name!(),
2009+
Some($crate::WindowsFilters::Platform),
2010+
None,
2011+
);
2012+
::insta::assert_snapshot!(snapshot, @$snapshot);
2013+
snapshot
2014+
}};
2015+
}
2016+
19832017
pub fn site_packages_path(venv: &Path, python: &str) -> PathBuf {
19842018
if cfg!(unix) {
19852019
venv.join("lib").join(python).join("site-packages")

0 commit comments

Comments
 (0)