forge
Explore
Log in

Don't you dare go Hollow

Switch from k9 to insta for snapshot testing

Browse files at this commit

2d3c36edae2cbce10ec57995c5a4418fb2424bd2Ivan MolodetskikhParent: 8dcc41a
We'll need some advanced features from insta.
Cargo.lockmodified+45 -40
@@ -714,16 +714,6 @@ version = "1.0.3"
714 source = "registry+https://github.com/rust-lang/crates.io-index"714 source = "registry+https://github.com/rust-lang/crates.io-index"
715 checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990"715 checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990"
716 716
717-[[package]]
718-name = "colored"
719-version = "2.1.0"
720-source = "registry+https://github.com/rust-lang/crates.io-index"
721-checksum = "cbf2150cce219b664a8a70df7a1f933836724b503f8a413af9365b4dcc4d90b8"
722-dependencies = [
723- "lazy_static",
724- "windows-sys 0.48.0",
725-]
726-
727 [[package]]717 [[package]]
728 name = "combine"718 name = "combine"
729 version = "4.6.7"719 version = "4.6.7"
@@ -743,6 +733,18 @@ dependencies = [
743 "crossbeam-utils",733 "crossbeam-utils",
744 ]734 ]
745 735
736+[[package]]
737+name = "console"
738+version = "0.15.10"
739+source = "registry+https://github.com/rust-lang/crates.io-index"
740+checksum = "ea3c6ecd8059b57859df5c69830340ed3c41d30e3da0c1cbed90a96ac853041b"
741+dependencies = [
742+ "encode_unicode",
743+ "libc",
744+ "once_cell",
745+ "windows-sys 0.59.0",
746+]
747+
746 [[package]]748 [[package]]
747 name = "convert_case"749 name = "convert_case"
748 version = "0.6.0"750 version = "0.6.0"
@@ -1018,6 +1020,12 @@ version = "1.13.0"
1018 source = "registry+https://github.com/rust-lang/crates.io-index"1020 source = "registry+https://github.com/rust-lang/crates.io-index"
1019 checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0"1021 checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0"
1020 1022
1023+[[package]]
1024+name = "encode_unicode"
1025+version = "1.0.0"
1026+source = "registry+https://github.com/rust-lang/crates.io-index"
1027+checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0"
1028+
1021 [[package]]1029 [[package]]
1022 name = "enumflags2"1030 name = "enumflags2"
1023 version = "0.7.10"1031 version = "0.7.10"
@@ -1878,6 +1886,18 @@ version = "1.18.0"
1878 source = "registry+https://github.com/rust-lang/crates.io-index"1886 source = "registry+https://github.com/rust-lang/crates.io-index"
1879 checksum = "bd4f5b4d1c00331c5245163aacfe5f20be75b564c7112d45893d4ae038119eb0"1887 checksum = "bd4f5b4d1c00331c5245163aacfe5f20be75b564c7112d45893d4ae038119eb0"
1880 1888
1889+[[package]]
1890+name = "insta"
1891+version = "1.41.1"
1892+source = "registry+https://github.com/rust-lang/crates.io-index"
1893+checksum = "7e9ffc4d4892617c50a928c52b2961cb5174b6fc6ebf252b2fac9d21955c48b8"
1894+dependencies = [
1895+ "console",
1896+ "lazy_static",
1897+ "linked-hash-map",
1898+ "similar",
1899+]
1900+
1881 [[package]]1901 [[package]]
1882 name = "instant"1902 name = "instant"
1883 version = "0.1.13"1903 version = "0.1.13"
@@ -1982,23 +2002,6 @@ dependencies = [
1982 "wasm-bindgen",2002 "wasm-bindgen",
1983 ]2003 ]
1984 2004
1985-[[package]]
1986-name = "k9"
1987-version = "0.12.0"
1988-source = "registry+https://github.com/rust-lang/crates.io-index"
1989-checksum = "088bcebb5b68b1b14b64d7f05b0f802719250b97fdc0338ec42529ea777ed614"
1990-dependencies = [
1991- "anyhow",
1992- "colored",
1993- "diff",
1994- "lazy_static",
1995- "libc",
1996- "proc-macro2",
1997- "regex",
1998- "syn 2.0.86",
1999- "terminal_size 0.2.6",
2000-]
2001-
2002 [[package]]2005 [[package]]
2003 name = "keyframe"2006 name = "keyframe"
2004 version = "1.1.1"2007 version = "1.1.1"
@@ -2203,6 +2206,12 @@ dependencies = [
2203 "pkg-config",2206 "pkg-config",
2204 ]2207 ]
2205 2208
2209+[[package]]
2210+name = "linked-hash-map"
2211+version = "0.5.6"
2212+source = "registry+https://github.com/rust-lang/crates.io-index"
2213+checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f"
2214+
2206 [[package]]2215 [[package]]
2207 name = "linux-raw-sys"2216 name = "linux-raw-sys"
2208 version = "0.3.8"2217 version = "0.3.8"
@@ -2325,7 +2334,7 @@ dependencies = [
2325 "supports-color",2334 "supports-color",
2326 "supports-hyperlinks",2335 "supports-hyperlinks",
2327 "supports-unicode",2336 "supports-unicode",
2328- "terminal_size 0.1.17",2337+ "terminal_size",
2329 "textwrap",2338 "textwrap",
2330 "thiserror",2339 "thiserror",
2331 "unicode-width",2340 "unicode-width",
@@ -2409,7 +2418,7 @@ dependencies = [
2409 "git-version",2418 "git-version",
2410 "glam",2419 "glam",
2411 "input",2420 "input",
2412- "k9",2421+ "insta",
2413 "keyframe",2422 "keyframe",
2414 "libc",2423 "libc",
2415 "libdisplay-info",2424 "libdisplay-info",
@@ -2448,7 +2457,7 @@ version = "0.1.10"
2448 dependencies = [2457 dependencies = [
2449 "bitflags 2.6.0",2458 "bitflags 2.6.0",
2450 "csscolorparser",2459 "csscolorparser",
2451- "k9",2460+ "insta",
2452 "knuffel",2461 "knuffel",
2453 "miette",2462 "miette",
2454 "niri-ipc",2463 "niri-ipc",
@@ -3628,6 +3637,12 @@ version = "0.3.7"
3628 source = "registry+https://github.com/rust-lang/crates.io-index"3637 source = "registry+https://github.com/rust-lang/crates.io-index"
3629 checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe"3638 checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe"
3630 3639
3640+[[package]]
3641+name = "similar"
3642+version = "2.6.0"
3643+source = "registry+https://github.com/rust-lang/crates.io-index"
3644+checksum = "1de1d4f81173b03af4c0cbed3c898f6bff5b870e4a7f5d6f4057d62a7a4b686e"
3645+
3631 [[package]]3646 [[package]]
3632 name = "siphasher"3647 name = "siphasher"
3633 version = "0.3.11"3648 version = "0.3.11"
@@ -3899,16 +3914,6 @@ dependencies = [
3899 "winapi",3914 "winapi",
3900 ]3915 ]
3901 3916
3902-[[package]]
3903-name = "terminal_size"
3904-version = "0.2.6"
3905-source = "registry+https://github.com/rust-lang/crates.io-index"
3906-checksum = "8e6bf6f19e9f8ed8d4048dc22981458ebcf406d67e94cd422e5ecd73d63b3237"
3907-dependencies = [
3908- "rustix 0.37.27",
3909- "windows-sys 0.48.0",
3910-]
3911-
3912 [[package]]3917 [[package]]
3913 name = "textwrap"3918 name = "textwrap"
3914 version = "0.15.2"3919 version = "0.15.2"
Cargo.tomlmodified+6 -2
@@ -14,7 +14,7 @@ rust-version = "1.80"
14 anyhow = "1.0.93"14 anyhow = "1.0.93"
15 bitflags = "2.6.0"15 bitflags = "2.6.0"
16 clap = { version = "4.5.20", features = ["derive"] }16 clap = { version = "4.5.20", features = ["derive"] }
17-k9 = "0.12.0"17+insta = "1.41.1"
18 serde = { version = "1.0.214", features = ["derive"] }18 serde = { version = "1.0.214", features = ["derive"] }
19 serde_json = "1.0.132"19 serde_json = "1.0.132"
20 tracing = { version = "0.1.40", features = ["max_level_trace", "release_max_level_debug"] }20 tracing = { version = "0.1.40", features = ["max_level_trace", "release_max_level_debug"] }
@@ -107,7 +107,7 @@ features = [
107 107
108 [dev-dependencies]108 [dev-dependencies]
109 approx = "0.5.1"109 approx = "0.5.1"
110-k9.workspace = true110+insta.workspace = true
111 proptest = "1.5.0"111 proptest = "1.5.0"
112 proptest-derive = { version = "0.5.0", features = ["boxed_union"] }112 proptest-derive = { version = "0.5.0", features = ["boxed_union"] }
113 xshell = "0.2.6"113 xshell = "0.2.6"
@@ -138,6 +138,10 @@ lto = "thin"
138 # knuffel with chomsky generates a metric ton of debuginfo.138 # knuffel with chomsky generates a metric ton of debuginfo.
139 debug = false139 debug = false
140 140
141+[profile.dev.package]
142+insta.opt-level = 3
143+similar.opt-level = 3
144+
141 [package.metadata.generate-rpm]145 [package.metadata.generate-rpm]
142 version = "0.1.10"146 version = "0.1.10"
143 assets = [147 assets = [
niri-config/Cargo.tomlmodified+1 -1
@@ -19,6 +19,6 @@ tracing.workspace = true
19 tracy-client.workspace = true19 tracy-client.workspace = true
20 20
21 [dev-dependencies]21 [dev-dependencies]
22-k9.workspace = true22+insta.workspace = true
23 miette = { version = "5.10.0", features = ["fancy"] }23 miette = { version = "5.10.0", features = ["fancy"] }
24 pretty_assertions = "1.4.1"24 pretty_assertions = "1.4.1"
niri-config/src/lib.rsmodified+3 -3
@@ -2933,7 +2933,7 @@ pub fn set_miette_hook() -> Result<(), miette::InstallError> {
2933 2933
2934 #[cfg(test)]2934 #[cfg(test)]
2935 mod tests {2935 mod tests {
2936- use k9::snapshot;2936+ use insta::assert_debug_snapshot;
2937 use pretty_assertions::assert_eq;2937 use pretty_assertions::assert_eq;
2938 2938
2939 use super::*;2939 use super::*;
@@ -3833,9 +3833,9 @@ mod tests {
3833 )3833 )
3834 })3834 })
3835 .collect::<Vec<_>>();3835 .collect::<Vec<_>>();
3836- snapshot!(3836+ assert_debug_snapshot!(
3837 names,3837 names,
3838- r#"3838+ @r#"
3839 [3839 [
3840 "Unknown A A | DP-3",3840 "Unknown A A | DP-3",
3841 "A Unknown A | DP-3",3841 "A Unknown A | DP-3",
src/dbus/mutter_display_config.rsmodified+6 -6
@@ -212,16 +212,16 @@ fn format_diagonal(diagonal_inches: f64) -> String {
212 212
213 #[cfg(test)]213 #[cfg(test)]
214 mod tests {214 mod tests {
215- use k9::snapshot;215+ use insta::assert_snapshot;
216 216
217 use super::*;217 use super::*;
218 218
219 #[test]219 #[test]
220 fn test_format_diagonal() {220 fn test_format_diagonal() {
221- snapshot!(format_diagonal(12.11), "12.1″");221+ assert_snapshot!(format_diagonal(12.11), @"12.1″");
222- snapshot!(format_diagonal(13.28), "13.3″");222+ assert_snapshot!(format_diagonal(13.28), @"13.3″");
223- snapshot!(format_diagonal(15.6), "15.6″");223+ assert_snapshot!(format_diagonal(15.6), @"15.6″");
224- snapshot!(format_diagonal(23.2), "23″");224+ assert_snapshot!(format_diagonal(23.2), @"23″");
225- snapshot!(format_diagonal(24.8), "25″");225+ assert_snapshot!(format_diagonal(24.8), @"25″");
226 }226 }
227 }227 }
src/utils/scale.rsmodified+23 -23
@@ -59,7 +59,7 @@ pub fn closest_representable_scale(scale: f64) -> f64 {
59 59
60 #[cfg(test)]60 #[cfg(test)]
61 mod tests {61 mod tests {
62- use k9::snapshot;62+ use insta::assert_snapshot;
63 63
64 use super::*;64 use super::*;
65 65
@@ -70,37 +70,37 @@ mod tests {
70 #[test]70 #[test]
71 fn test_guess_monitor_scale() {71 fn test_guess_monitor_scale() {
72 // Librem 5; not enough logical area when scaled72 // Librem 5; not enough logical area when scaled
73- snapshot!(check((65, 129), (720, 1440)), "1.5");73+ assert_snapshot!(check((65, 129), (720, 1440)), @"1.5");
74 // OnePlus 674 // OnePlus 6
75- snapshot!(check((68, 144), (1080, 2280)), "2.5");75+ assert_snapshot!(check((68, 144), (1080, 2280)), @"2.5");
76 // Google Pixel 6a76 // Google Pixel 6a
77- snapshot!(check((64, 142), (1080, 2400)), "2.5");77+ assert_snapshot!(check((64, 142), (1080, 2400)), @"2.5");
78 // 13" MacBook Retina78 // 13" MacBook Retina
79- snapshot!(check((286, 179), (2560, 1600)), "1.75");79+ assert_snapshot!(check((286, 179), (2560, 1600)), @"1.75");
80 // Surface Laptop Studio80 // Surface Laptop Studio
81- snapshot!(check((303, 202), (2400, 1600)), "1.5");81+ assert_snapshot!(check((303, 202), (2400, 1600)), @"1.5");
82 // Dell XPS 932082 // Dell XPS 9320
83- snapshot!(check((290, 180), (3840, 2400)), "2.5");83+ assert_snapshot!(check((290, 180), (3840, 2400)), @"2.5");
84 // Lenovo ThinkPad X1 Yoga Gen 684 // Lenovo ThinkPad X1 Yoga Gen 6
85- snapshot!(check((300, 190), (3840, 2400)), "2.5");85+ assert_snapshot!(check((300, 190), (3840, 2400)), @"2.5");
86 // Generic 23" 1080p86 // Generic 23" 1080p
87- snapshot!(check((509, 286), (1920, 1080)), "1.0");87+ assert_snapshot!(check((509, 286), (1920, 1080)), @"1");
88 // Generic 23" 4K88 // Generic 23" 4K
89- snapshot!(check((509, 286), (3840, 2160)), "1.75");89+ assert_snapshot!(check((509, 286), (3840, 2160)), @"1.75");
90 // Generic 27" 4K90 // Generic 27" 4K
91- snapshot!(check((598, 336), (3840, 2160)), "1.5");91+ assert_snapshot!(check((598, 336), (3840, 2160)), @"1.5");
92 // Generic 32" 4K92 // Generic 32" 4K
93- snapshot!(check((708, 398), (3840, 2160)), "1.25");93+ assert_snapshot!(check((708, 398), (3840, 2160)), @"1.25");
94 // Generic 25" 4K; ideal scale is 1.60, should round to 1.5 and 1.094 // Generic 25" 4K; ideal scale is 1.60, should round to 1.5 and 1.0
95- snapshot!(check((554, 312), (3840, 2160)), "1.5");95+ assert_snapshot!(check((554, 312), (3840, 2160)), @"1.5");
96 // Generic 23.5" 4K; ideal scale is 1.70, should round to 1.75 and 2.096 // Generic 23.5" 4K; ideal scale is 1.70, should round to 1.75 and 2.0
97- snapshot!(check((522, 294), (3840, 2160)), "1.75");97+ assert_snapshot!(check((522, 294), (3840, 2160)), @"1.75");
98 // Lenovo Legion 7 Gen 7 AMD 16"98 // Lenovo Legion 7 Gen 7 AMD 16"
99- snapshot!(check((340, 210), (2560, 1600)), "1.5");99+ assert_snapshot!(check((340, 210), (2560, 1600)), @"1.5");
100 // Acer Nitro XV320QU LV 31.5"100 // Acer Nitro XV320QU LV 31.5"
101- snapshot!(check((700, 390), (2560, 1440)), "1.0");101+ assert_snapshot!(check((700, 390), (2560, 1440)), @"1");
102 // Surface Pro 6102 // Surface Pro 6
103- snapshot!(check((260, 170), (2736, 1824)), "2.0");103+ assert_snapshot!(check((260, 170), (2736, 1824)), @"2");
104 }104 }
105 105
106 #[test]106 #[test]
@@ -110,11 +110,11 @@ mod tests {
110 110
111 #[test]111 #[test]
112 fn test_round_scale() {112 fn test_round_scale() {
113- snapshot!(closest_representable_scale(1.3), "1.3");113+ assert_snapshot!(closest_representable_scale(1.3), @"1.3");
114- snapshot!(closest_representable_scale(1.31), "1.3083333333333333");114+ assert_snapshot!(closest_representable_scale(1.31), @"1.3083333333333333");
115- snapshot!(closest_representable_scale(1.32), "1.3166666666666667");115+ assert_snapshot!(closest_representable_scale(1.32), @"1.3166666666666667");
116- snapshot!(closest_representable_scale(1.33), "1.3333333333333333");116+ assert_snapshot!(closest_representable_scale(1.33), @"1.3333333333333333");
117- snapshot!(closest_representable_scale(1.34), "1.3416666666666666");117+ assert_snapshot!(closest_representable_scale(1.34), @"1.3416666666666666");
118- snapshot!(closest_representable_scale(1.35), "1.35");118+ assert_snapshot!(closest_representable_scale(1.35), @"1.35");
119 }119 }
120 }120 }