device_tests/print.rs
1use core::fmt;
2use std::io::{self, Write as _};
3
4/// Prints why the test can't run and returns `Ok(())` from it.
5#[macro_export]
6macro_rules! skip {
7 ($($arg:tt)+) => {{
8 $crate::print_skip(format_args!($($arg)+));
9 return Ok(());
10 }};
11}
12
13/// Prints why a test can't run.
14///
15/// libtest captures `eprintln!`, so this writes to the real stderr. The skip
16/// shows even without `--nocapture`.
17pub fn print_skip(reason: fmt::Arguments<'_>) {
18 print_stderr(format_args!("skipped: {reason}"));
19}
20
21/// Writes a line to the real stderr in one write and ignores errors.
22///
23/// One write stops lines of parallel tests from mixing. It never panics, so
24/// `Drop` impls can use it during unwinding.
25pub(crate) fn print_stderr(line: fmt::Arguments<'_>) {
26 let line = format!("{line}\n");
27 let _ignored = io::stderr().write_all(line.as_bytes());
28}