diff --git a/Cargo.toml b/Cargo.toml index 88a15742b..4417f8596 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,10 +41,11 @@ same-file = { version = "1", optional = true } walkdir = { version = "2", optional = true } [dev-dependencies] -walkdir = "2" +filedescriptor = "0.8" +iai = { git = "https://github.com/reknih/iai" } tiny-skia = "0.6" usvg = { version = "0.15", default-features = false } -iai = { git = "https://github.com/reknih/iai" } +walkdir = "2" [[bin]] name = "typst" diff --git a/tests/typeset.rs b/tests/typeset.rs index 8f8556c4c..3011a3519 100644 --- a/tests/typeset.rs +++ b/tests/typeset.rs @@ -1,9 +1,10 @@ use std::env; use std::ffi::OsStr; -use std::fs; +use std::fs::{self, File}; use std::path::Path; use std::rc::Rc; +use filedescriptor::{FileDescriptor, StdioDescriptor::*}; use image::{GenericImageView, Rgba}; use tiny_skia as sk; use ttf_parser::{GlyphId, OutlineBuilder}; @@ -298,7 +299,7 @@ fn test_incremental( ctx.layouts.turnaround(); - let cached = layout(ctx, document); + let cached = silenced(|| layout(ctx, document)); let misses = ctx .layouts .entries() @@ -756,3 +757,18 @@ impl LengthExt for Length { self.to_pt() as f32 } } + +/// Disable stdout and stderr during execution of `f`. +fn silenced(f: F) -> T +where + F: FnOnce() -> T, +{ + let path = if cfg!(windows) { "NUL" } else { "/dev/null" }; + let null = File::create(path).unwrap(); + let stderr = FileDescriptor::redirect_stdio(&null, Stderr).unwrap(); + let stdout = FileDescriptor::redirect_stdio(&null, Stdout).unwrap(); + let result = f(); + FileDescriptor::redirect_stdio(&stderr, Stderr).unwrap(); + FileDescriptor::redirect_stdio(&stdout, Stdout).unwrap(); + result +}