Skip to content

Commit 64e146f

Browse files
Modify tests for more deterministic behavior (#1081)
* Modified tests to use insta's assert_yaml_snapshot * Sort maps to have a deterministic behaviour --------- Co-authored-by: Luni-4 <[email protected]>
1 parent 56f182a commit 64e146f

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ tree-sitter-mozcpp = { path = "./tree-sitter-mozcpp", version = "=0.20.2" }
3838
tree-sitter-mozjs = { path = "./tree-sitter-mozjs", version = "=0.20.1" }
3939

4040
[dev-dependencies]
41-
insta = { version = "1.29.0", features = ["yaml", "json"] }
41+
insta = { version = "1.29.0", features = ["yaml", "json", "redactions"] }
4242
pretty_assertions = "^1.3"
4343

4444
[profile.dev.package.insta]

tests/common/mod.rs

+12-13
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,20 @@ fn act_on_file(path: PathBuf, cfg: &Config) -> std::io::Result<()> {
4444
.join(path.strip_prefix(Path::new(REPO)).unwrap())
4545
.parent()
4646
.unwrap(),
47-
prepend_module_to_snapshot => false
47+
prepend_module_to_snapshot => false,
48+
sort_maps => true,
4849
}, {
49-
// Redact away the name since paths are different on windows.
50-
let value = format!(
51-
"{:#.3?}",
52-
FuncSpace {
53-
name: None,
54-
..funcspace_struct
55-
}
56-
);
57-
58-
insta::assert_snapshot!(
50+
insta::assert_yaml_snapshot!(
5951
path.file_name().unwrap().to_string_lossy().as_ref(),
60-
value,
61-
"funcspace_struct"
52+
funcspace_struct,
53+
{
54+
// Round floating point values to three decimal places since the can differ from
55+
// system to system.
56+
".spaces[].**.metrics.*.*" => insta::rounded_redaction(3),
57+
".metrics.*.*" => insta::rounded_redaction(3),
58+
// Redact away the name since paths are different on different systems.
59+
".name" => "[filepath]",
60+
}
6261
);
6362

6463
});

tests/repositories/rca-output

Submodule rca-output updated 1603 files

0 commit comments

Comments
 (0)