Skip to content

Commit a6a60ee

Browse files
committed
Add read_to_string to the prelude
This adds the `read_to_string` test helper to the test prelude so that it is easier to use.
1 parent 4a2d3a7 commit a6a60ee

File tree

3 files changed

+3
-5
lines changed

3 files changed

+3
-5
lines changed

tests/testsuite/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ mod theme;
2424
mod toc;
2525

2626
mod prelude {
27-
pub use crate::book_test::BookTest;
27+
pub use crate::book_test::{BookTest, read_to_string};
2828
pub use snapbox::str;
2929
}

tests/testsuite/search.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::path::Path;
77

88
fn read_book_index(root: &Path) -> serde_json::Value {
99
let index = root.join("book/searchindex.js");
10-
let index = std::fs::read_to_string(index).unwrap();
10+
let index = read_to_string(index);
1111
let index =
1212
index.trim_start_matches("window.search = Object.assign(window.search, JSON.parse('");
1313
let index = index.trim_end_matches("'));");

tests/testsuite/toc.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
//! Tests for table of contents (sidebar).
22
33
use crate::prelude::*;
4-
use anyhow::Context;
54
use anyhow::Result;
65
use select::document::Document;
76
use select::predicate::{Attr, Class, Name, Predicate};
8-
use std::fs;
97

108
const TOC_TOP_LEVEL: &[&str] = &[
119
"1. With Readme",
@@ -50,7 +48,7 @@ fn toc_fallback_html() -> Result<Document> {
5048
test.build();
5149

5250
let toc_path = test.dir.join("book").join("toc.html");
53-
let html = fs::read_to_string(toc_path).with_context(|| "Unable to read index.html")?;
51+
let html = read_to_string(toc_path);
5452
Ok(Document::from(html.as_str()))
5553
}
5654

0 commit comments

Comments
 (0)