use std::path::PathBuf; use status::Code; use xatu::SourceFile; fn source_file(path: &str, source: &str) -> SourceFile { SourceFile { path: PathBuf::from(path), source: source.to_owned(), } } #[test] fn future_sight_reports_clean_sources_as_clean() { let report = xatu::future_sight(vec![source_file( "clean.nix", include_str!("testdata/clean.nix"), )]) .expect("fixture should parse"); assert!(report.is_clean()); } #[test] fn future_sight_reports_empty_inherit_findings() { let report = xatu::future_sight(vec![source_file( "empty_inherit.nix", include_str!("testdata/empty_inherit.nix"), )]) .expect("fixture should parse"); assert_eq!(1, report.diagnostics.len()); let diagnostic = &report.diagnostics[0]; assert_eq!( PathBuf::from("empty_inherit.nix"), report.files.get(diagnostic.file_id).path, ); assert_eq!("empty_inherit", diagnostic.finding.rule_id); } #[test] fn future_sight_rejects_parse_errors() { let error = xatu::future_sight(vec![source_file( "invalid.nix", include_str!("testdata/invalid.nix"), )]) .expect_err("fixture should fail to parse"); assert_eq!(Code::FailedPrecondition, error.code()); }