Skip to content

Commit 707319e

Browse files
committed
Migrate custom fonts with filled fonts.css to BookTest
1 parent bdd16e2 commit 707319e

File tree

6 files changed

+25
-35
lines changed

6 files changed

+25
-35
lines changed

tests/rendered_output.rs

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -305,38 +305,3 @@ fn summary_with_markdown_formatting() {
305305
"# <escaped tag>\n"
306306
);
307307
}
308-
309-
#[test]
310-
fn custom_fonts() {
311-
// Tests to ensure custom fonts are copied as expected.
312-
let actual_files = |path: &Path| -> Vec<String> {
313-
let mut actual: Vec<_> = path
314-
.read_dir()
315-
.unwrap()
316-
.map(|entry| entry.unwrap().file_name().into_string().unwrap())
317-
.collect();
318-
actual.sort();
319-
actual
320-
};
321-
let has_fonts_css = |path: &Path| -> bool {
322-
let contents = fs::read_to_string(path.join("book/index.html")).unwrap();
323-
contents.contains("fonts/fonts.css")
324-
};
325-
326-
// copy-fonts=false with fonts theme
327-
let temp = TempFileBuilder::new().prefix("mdbook").tempdir().unwrap();
328-
let p = temp.path();
329-
MDBook::init(p).build().unwrap();
330-
write_file(&p.join("theme/fonts"), "fonts.css", b"/*custom*/").unwrap();
331-
write_file(&p.join("theme/fonts"), "myfont.woff", b"").unwrap();
332-
let config = Config::from_str("output.html.copy-fonts = false").unwrap();
333-
MDBook::load_with_config(p, config)
334-
.unwrap()
335-
.build()
336-
.unwrap();
337-
assert!(has_fonts_css(p));
338-
assert_eq!(
339-
actual_files(&p.join("book/fonts")),
340-
&["fonts.css", "myfont.woff"]
341-
);
342-
}

tests/testsuite/theme.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,24 @@ fn copy_fonts_false_with_empty_fonts_css() {
170170
.check_file_doesnt_contain("book/index.html", "fonts.css")
171171
.check_file_list("book/fonts", str![[""]]);
172172
}
173+
174+
// copy-fonts=false, fonts.css has contents
175+
#[test]
176+
fn copy_fonts_false_with_fonts_css() {
177+
BookTest::from_dir("theme/copy_fonts_false_with_fonts_css")
178+
.run("build", |cmd| {
179+
cmd.expect_stderr(str![[r#"
180+
[TIMESTAMP] [INFO] (mdbook::book): Book building has started
181+
[TIMESTAMP] [INFO] (mdbook::book): Running the html backend
182+
183+
"#]]);
184+
})
185+
.check_file_contains("book/index.html", "fonts.css")
186+
.check_file_list(
187+
"book/fonts",
188+
str![[r#"
189+
book/fonts/fonts.css
190+
book/fonts/myfont.woff
191+
"#]],
192+
);
193+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[output.html]
2+
copy-fonts = false
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- [Intro](index.md)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/*custom*/

tests/testsuite/theme/copy_fonts_false_with_fonts_css/theme/fonts/myfont.woff

Whitespace-only changes.

0 commit comments

Comments
 (0)