From 9835e2ae736235810b4ea1c162ca5e65c547e770 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 18 May 2024 04:49:50 +0200 Subject: Merging upstream version 1.71.1+dfsg1. Signed-off-by: Daniel Baumann --- vendor/snapbox/examples/snap-example-fixture.rs | 60 +++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 vendor/snapbox/examples/snap-example-fixture.rs (limited to 'vendor/snapbox/examples') diff --git a/vendor/snapbox/examples/snap-example-fixture.rs b/vendor/snapbox/examples/snap-example-fixture.rs new file mode 100644 index 000000000..6e13448a7 --- /dev/null +++ b/vendor/snapbox/examples/snap-example-fixture.rs @@ -0,0 +1,60 @@ +//! For `snapbox`s tests only + +use std::env; +use std::error::Error; +use std::io; +use std::io::Write; +use std::process; + +fn run() -> Result<(), Box> { + if let Ok(text) = env::var("stdout") { + println!("{}", text); + } + if let Ok(text) = env::var("stderr") { + eprintln!("{}", text); + } + + if env::var("echo_large").as_deref() == Ok("1") { + for i in 0..(128 * 1024) { + println!("{}", i); + } + } + + if env::var("echo_cwd").as_deref() == Ok("1") { + if let Ok(cwd) = std::env::current_dir() { + eprintln!("{}", cwd.display()); + } + } + + if let Ok(raw) = env::var("write") { + let (path, text) = raw.split_once('=').unwrap_or((raw.as_str(), "")); + std::fs::write(path.trim(), text.trim()).unwrap(); + } + + if let Ok(path) = env::var("cat") { + let text = std::fs::read_to_string(path).unwrap(); + eprintln!("{}", text); + } + + if let Some(timeout) = env::var("sleep").ok().and_then(|s| s.parse().ok()) { + std::thread::sleep(std::time::Duration::from_secs(timeout)); + } + + let code = env::var("exit") + .ok() + .map(|v| v.parse::()) + .map_or(Ok(None), |r| r.map(Some))? + .unwrap_or(0); + process::exit(code); +} + +fn main() { + let code = match run() { + Ok(_) => 0, + Err(ref e) => { + write!(&mut io::stderr(), "{}", e).expect("writing to stderr won't fail"); + 1 + } + }; + process::exit(code); +} -- cgit v1.2.3