1 use std::fs;
2 use std::path::Path;
3 use std::path::PathBuf;
4
list_dir(p: &Path) -> Vec<PathBuf>5 fn list_dir(p: &Path) -> Vec<PathBuf> {
6 let mut children = fs::read_dir(p)
7 .unwrap()
8 .map(|r| r.map(|e| e.path()))
9 .collect::<Result<Vec<_>, _>>()
10 .unwrap();
11 children.sort();
12 children
13 }
14
assert_equal_recursively(a: &Path, b: &Path)15 fn assert_equal_recursively(a: &Path, b: &Path) {
16 assert_eq!(a.is_dir(), b.is_dir(), "{} {}", a.display(), b.display());
17 assert_eq!(a.is_file(), b.is_file(), "{} {}", a.display(), b.display());
18 if a.is_dir() {
19 let mut a_contents = list_dir(a).into_iter();
20 let mut b_contents = list_dir(b).into_iter();
21 loop {
22 let a_child = a_contents.next();
23 let b_child = b_contents.next();
24 match (a_child, b_child) {
25 (Some(a_child), Some(b_child)) => {
26 assert_eq!(a_child.file_name(), b_child.file_name());
27 assert_equal_recursively(&a_child, &b_child);
28 }
29 (None, None) => break,
30 _ => panic!(
31 "mismatched directories: {} and {}",
32 a.display(),
33 b.display()
34 ),
35 }
36 }
37 } else {
38 let a_contents = fs::read_to_string(a).unwrap();
39 let b_contents = fs::read_to_string(b).unwrap();
40 assert_eq!(a_contents, b_contents);
41 }
42 }
43
44 #[test]
test_bundled_google_proto_files_consistent()45 fn test_bundled_google_proto_files_consistent() {
46 let source = "../proto/google";
47 let our_copy = "src/proto/google";
48 assert_equal_recursively(Path::new(source), Path::new(our_copy));
49 }
50
51 #[test]
test_bundled_rustproto_proto_consistent()52 fn test_bundled_rustproto_proto_consistent() {
53 let source = "../proto/rustproto.proto";
54 let our_copy = "src/proto/rustproto.proto";
55 assert_equal_recursively(Path::new(source), Path::new(our_copy));
56 }
57