mirror of
https://github.com/typst/typst
synced 2025-05-13 20:46:23 +08:00
No more duplicate debug prints due to incremental tests
This commit is contained in:
parent
e4e4c1876f
commit
e915cc4ef0
@ -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"
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user