From a6a60eef3115b4ce6df432fe2b0a490916e77763 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 11 Aug 2025 19:26:05 -0700 Subject: [PATCH] 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. --- tests/testsuite/main.rs | 2 +- tests/testsuite/search.rs | 2 +- tests/testsuite/toc.rs | 4 +--- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/tests/testsuite/main.rs b/tests/testsuite/main.rs index 6959f6dd..7a8aa7c2 100644 --- a/tests/testsuite/main.rs +++ b/tests/testsuite/main.rs @@ -24,6 +24,6 @@ mod theme; mod toc; mod prelude { - pub use crate::book_test::BookTest; + pub use crate::book_test::{BookTest, read_to_string}; pub use snapbox::str; } diff --git a/tests/testsuite/search.rs b/tests/testsuite/search.rs index 0a177276..89978e46 100644 --- a/tests/testsuite/search.rs +++ b/tests/testsuite/search.rs @@ -7,7 +7,7 @@ use std::path::Path; fn read_book_index(root: &Path) -> serde_json::Value { let index = root.join("book/searchindex.js"); - let index = std::fs::read_to_string(index).unwrap(); + let index = read_to_string(index); let index = index.trim_start_matches("window.search = Object.assign(window.search, JSON.parse('"); let index = index.trim_end_matches("'));"); diff --git a/tests/testsuite/toc.rs b/tests/testsuite/toc.rs index 35b5e5ab..b7e5629b 100644 --- a/tests/testsuite/toc.rs +++ b/tests/testsuite/toc.rs @@ -1,11 +1,9 @@ //! Tests for table of contents (sidebar). use crate::prelude::*; -use anyhow::Context; use anyhow::Result; use select::document::Document; use select::predicate::{Attr, Class, Name, Predicate}; -use std::fs; const TOC_TOP_LEVEL: &[&str] = &[ "1. With Readme", @@ -50,7 +48,7 @@ fn toc_fallback_html() -> Result { test.build(); let toc_path = test.dir.join("book").join("toc.html"); - let html = fs::read_to_string(toc_path).with_context(|| "Unable to read index.html")?; + let html = read_to_string(toc_path); Ok(Document::from(html.as_str())) }