diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-11-29 23:22:53 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-11-29 23:22:53 +0100 |
| commit | e915cc4ef04de70297a3e840a363382dd2689f7b (patch) | |
| tree | 0680648bd48a0bb2ad97ca532825c363fffeaac5 /tests | |
| parent | e4e4c1876ff0b08bb144dccf74cc2a83c0a6c6aa (diff) | |
No more duplicate debug prints due to incremental tests
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/typeset.rs | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/tests/typeset.rs b/tests/typeset.rs index 8f8556c4..3011a351 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, T>(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 +} |
