1 #![cfg(test)]
2 
3 use std::fs;
4 use std::io::Read;
5 use std::path::Path;
6 
7 use anyhow::Context;
8 
9 use crate::model;
10 
parse_recursively(path: &Path)11 fn parse_recursively(path: &Path) {
12     assert!(path.exists());
13 
14     let file_name = path
15         .file_name()
16         .expect("file_name")
17         .to_str()
18         .expect("to_str");
19     if path.is_dir() {
20         for entry in fs::read_dir(path).expect("read_dir") {
21             parse_recursively(&entry.expect("entry").path());
22         }
23     } else if file_name.ends_with(".proto") {
24         println!("checking {}", path.display());
25         let mut content = String::new();
26         fs::File::open(path)
27             .expect("open")
28             .read_to_string(&mut content)
29             .expect("read");
30         model::FileDescriptor::parse(&content)
31             .with_context(|| format!("testing `{}`", path.display()))
32             .expect("parse");
33     }
34 }
35 
36 #[test]
test()37 fn test() {
38     let path = &Path::new("../google-protobuf-all-protos/protobuf");
39     parse_recursively(&Path::new(path));
40 }
41