]>
Commit | Line | Data |
---|---|---|
ea8adc8c XL |
1 | //! Helpers for tests which exercise the overall application, in particular |
2 | //! the `MDBook` initialization and build/rendering process. | |
3 | ||
4 | ||
5 | use std::path::Path; | |
6 | use std::fs::File; | |
7 | use std::io::Read; | |
8 | ||
9 | ||
10 | /// Read the contents of the provided file into memory and then iterate through | |
11 | /// the list of strings asserting that the file contains all of them. | |
12 | pub fn assert_contains_strings<P: AsRef<Path>>(filename: P, strings: &[&str]) { | |
13 | let filename = filename.as_ref(); | |
14 | ||
15 | let mut content = String::new(); | |
16 | File::open(&filename) | |
17 | .expect("Couldn't open the provided file") | |
18 | .read_to_string(&mut content) | |
19 | .expect("Couldn't read the file's contents"); | |
20 | ||
21 | for s in strings { | |
22 | assert!(content.contains(s), "Searching for {:?} in {}\n\n{}", s, filename.display(), content); | |
23 | } | |
24 | } |