]> git.proxmox.com Git - rustc.git/blame - src/vendor/mdbook/tests/helpers/mod.rs
New upstream version 1.24.1+dfsg1
[rustc.git] / src / vendor / mdbook / tests / helpers / mod.rs
CommitLineData
ea8adc8c
XL
1//! Helpers for tests which exercise the overall application, in particular
2//! the `MDBook` initialization and build/rendering process.
3
4
5use std::path::Path;
6use std::fs::File;
7use 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.
12pub 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}