summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.toml5
-rw-r--r--tests/typeset.rs20
2 files changed, 21 insertions, 4 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 88a15742..4417f859 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 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
+}