From 575b0fde0de443a8b46ced7d6772d1c698efbe5a Mon Sep 17 00:00:00 2001 From: alexion Date: Sat, 19 Sep 2026 11:10:16 -0400 Subject: [PATCH] test(xatu): relax diagnostic count assertions --- src/xatu/xatu_test.rs | 54 ++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 29 deletions(-) diff --git a/src/xatu/xatu_test.rs b/src/xatu/xatu_test.rs index b1cecc0..9fd446d 100644 --- a/src/xatu/xatu_test.rs +++ b/src/xatu/xatu_test.rs @@ -21,11 +21,6 @@ fn fixture_path(path: &str) -> PathBuf { runfiles.join(workspace).join("src/xatu").join(path) } -fn only_diagnostic(report: &xatu::Report) -> &xatu::Diagnostic { - assert_eq!(report.diagnostics.len(), 1); - &report.diagnostics[0] -} - #[test] fn future_sight_reports_clean_sources_as_clean() { let report = xatu::future_sight(vec![fixture_source("testdata/clean.nix")]) @@ -46,29 +41,29 @@ fn future_sight_rejects_parse_errors() { } #[test] -fn future_sight_reports_deprecated_to_path_ident_findings() { - let report = xatu::future_sight(vec![SourceFile { - path: PathBuf::from("deprecated_to_path_ident.nix"), - source: "toPath x\n".to_owned(), - }]) +fn future_sight_reports_deprecated_to_path_findings() { + let report = xatu::future_sight(vec![ + SourceFile { + path: PathBuf::from("deprecated_to_path_ident.nix"), + source: "toPath x\n".to_owned(), + }, + SourceFile { + path: PathBuf::from("deprecated_to_path_select.nix"), + source: "builtins.toPath x\n".to_owned(), + }, + ]) .expect("fixture should parse"); - let diagnostic = only_diagnostic(&report); - - assert_eq!(diagnostic.finding.rule_id, "deprecated_to_path"); -} - -#[test] -fn future_sight_reports_deprecated_to_path_select_findings() { - let report = xatu::future_sight(vec![SourceFile { - path: PathBuf::from("deprecated_to_path_select.nix"), - source: "builtins.toPath x\n".to_owned(), - }]) - .expect("fixture should parse"); - - let diagnostic = only_diagnostic(&report); - - assert_eq!(diagnostic.finding.rule_id, "deprecated_to_path"); + assert!(report.diagnostics.iter().any(|diagnostic| { + report.files.get(diagnostic.file_id).path.as_path() + == Path::new("deprecated_to_path_ident.nix") + && diagnostic.finding.rule_id == "deprecated_to_path" + })); + assert!(report.diagnostics.iter().any(|diagnostic| { + report.files.get(diagnostic.file_id).path.as_path() + == Path::new("deprecated_to_path_select.nix") + && diagnostic.finding.rule_id == "deprecated_to_path" + })); } #[test] @@ -76,7 +71,8 @@ fn future_sight_reports_empty_inherit_findings() { let report = xatu::future_sight(vec![fixture_source("testdata/empty_inherit.nix")]) .expect("fixture should parse"); - let diagnostic = only_diagnostic(&report); - - assert_eq!(diagnostic.finding.rule_id, "empty_inherit"); + assert!(report.diagnostics.iter().any(|diagnostic| { + report.files.get(diagnostic.file_id).path.as_path() == Path::new("testdata/empty_inherit.nix") + && diagnostic.finding.rule_id == "empty_inherit" + })); }