MCPcopy Create free account
hub / github.com/archlinux/alpm / ensure_parse_errors

Function ensure_parse_errors

alpm-repo-db/tests/parse_errors.rs:16–48  ·  view source on GitHub ↗
(#[files("tests/parse_errors/desc/*.desc")] case: PathBuf)

Source from the content-addressed store, hash-verified

14 /// and the file's contents as description.
15 #[rstest]
16 fn ensure_parse_errors(#[files("tests/parse_errors/desc/*.desc")] case: PathBuf) -> TestResult {
17 let input = read_to_string(&case)?;
18 let name = case
19 .file_stem()
20 .and_then(|s| s.to_str())
21 .unwrap_or("unknown_case");
22
23 // Try both V1 and V2 constructors, as syntax errors should fail on either.
24 let res_v1 = RepoDescFileV1::from_str(&input);
25 let res_v2 = RepoDescFileV2::from_str(&input);
26
27 // ensure at least one parser fails
28 if res_v1.is_ok() || res_v2.is_ok() {
29 unreachable!("parser unexpectedly succeeded");
30 }
31
32 let error = res_v1
33 .err()
34 .map(|e| e.to_string())
35 .or_else(|| res_v2.err().map(|e| e.to_string()))
36 .unwrap_or_else(|| "unknown parser failure".to_string());
37
38 let input_clone = input.clone();
39 insta::with_settings!({
40 description => input_clone,
41 snapshot_path => "parse_errors/desc/snapshots",
42 prepend_module_to_snapshot => false,
43 }, {
44 assert_snapshot!(name, error);
45 });
46
47 Ok(())
48 }
49}
50
51mod files {

Callers

nothing calls this directly

Calls 1

from_strFunction · 0.85

Tested by

no test coverage detected