From 10ee2acdd26a7f1298c6f6d6b7af9b469fe29b87 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 4 May 2024 14:41:41 +0200 Subject: Merging upstream version 1.70.0+dfsg2. Signed-off-by: Daniel Baumann --- vendor/snapbox/src/bin/snap-fixture.rs | 60 ++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 vendor/snapbox/src/bin/snap-fixture.rs (limited to 'vendor/snapbox/src/bin') diff --git a/vendor/snapbox/src/bin/snap-fixture.rs b/vendor/snapbox/src/bin/snap-fixture.rs new file mode 100644 index 000000000..6e13448a7 --- /dev/null +++ b/vendor/snapbox/src/bin/snap-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