Skip to content

Commit

Permalink
add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv committed Jun 3, 2024
1 parent f833331 commit e921d5e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/packaging/file_finder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ impl Files {
// If we have an files glob, we only include files that match the glob
.filter(|f| {
files.is_empty()
|| files
.is_match(f.strip_prefix(prefix).expect("File should be in prefix"))
|| files.is_match(f.strip_prefix(prefix).expect("File should be in prefix"))
})
.cloned()
.collect::<HashSet<_>>();
Expand Down
23 changes: 23 additions & 0 deletions src/recipe/parser/glob_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,29 @@ mod tests {
let parsed_again: GlobVec = serde_yaml::from_str(&as_yaml).unwrap();
assert_eq!(parsed_again.include.len(), 3);
assert_eq!(parsed_again.include_globset.len(), 3);

let yaml = r#"globs:
include: ["foo/", "bar", "baz/**/qux"]
exclude: ["foo/bar", "bar/*.txt"]
"#;

let yaml_root = RenderedNode::parse_yaml(0, yaml)
.map_err(|err| vec![err])
.unwrap();
let tests_node = yaml_root.as_mapping().unwrap().get("globs").unwrap();
let globvec: GlobVec = tests_node.try_convert("globs").unwrap();
assert_eq!(globvec.include.len(), 3);
assert_eq!(globvec.include_globset.len(), 3);
assert_eq!(globvec.exclude.len(), 2);
assert_eq!(globvec.exclude_globset.len(), 2);

let as_yaml = serde_yaml::to_string(&globvec).unwrap();
insta::assert_snapshot!(&as_yaml);
let parsed_again: GlobVec = serde_yaml::from_str(&as_yaml).unwrap();
assert_eq!(parsed_again.include.len(), 3);
assert_eq!(parsed_again.include_globset.len(), 3);
assert_eq!(parsed_again.exclude.len(), 2);
assert_eq!(parsed_again.exclude_globset.len(), 2);
}

#[test]
Expand Down

0 comments on commit e921d5e

Please sign in to comment.