1#[macro_export]
43macro_rules! assert_command_stderr_gt_x_as_result {
44 ($a_command:expr, $b_expr:expr $(,)?) => {
45 match ($a_command.output(), &$b_expr) {
46 (Ok(a_output), b_expr) => {
47 let a = a_output.stderr;
48 if a.gt(b_expr) {
49 Ok(a)
50 } else {
51 Err(format!(
52 concat!(
53 "assertion failed: `assert_command_stderr_gt_x!(command, expr)`\n",
54 "https://docs.rs/assertables/9.8.6/assertables/macro.assert_command_stderr_gt_x.html\n",
55 " command label: `{}`,\n",
56 " command debug: `{:?}`,\n",
57 " command value: `{:?}`,\n",
58 " expr label: `{}`,\n",
59 " expr debug: `{:?}`,\n",
60 " expr value: `{:?}`"
61 ),
62 stringify!($a_command),
63 $a_command,
64 a,
65 stringify!($b_expr),
66 $b_expr,
67 b_expr
68 ))
69 }
70 }
71 (a, b) => Err(format!(
72 concat!(
73 "assertion failed: `assert_command_stderr_gt_x!(command, expr)`\n",
74 "https://docs.rs/assertables/9.8.6/assertables/macro.assert_command_stderr_gt_x.html\n",
75 " command label: `{}`,\n",
76 " command debug: `{:?}`,\n",
77 " command value: `{:?}`,\n",
78 " expr label: `{}`,\n",
79 " expr debug: `{:?}`,\n",
80 " expr value: `{:?}`"
81 ),
82 stringify!($a_command),
83 $a_command,
84 a,
85 stringify!($b_expr),
86 $b_expr,
87 b
88 )),
89 }
90 };
91}
92
93#[cfg(test)]
94mod test_assert_command_stderr_gt_x_as_result {
95 use std::process::Command;
96 use std::sync::Once;
97
98 #[test]
99 fn gt() {
100 let mut a = Command::new("bin/printf-stderr");
101 a.args(["%s", "alfa"]);
102 let b = vec![b'a', b'a'];
103 for _ in 0..1 {
104 let actual = assert_command_stderr_gt_x_as_result!(a, b);
105 assert_eq!(actual.unwrap(), vec![b'a', b'l', b'f', b'a']);
106 }
107 }
108
109 #[test]
110 fn gt_once() {
111 static A: Once = Once::new();
112 fn a() -> Command {
113 if A.is_completed() {
114 panic!("A.is_completed()")
115 } else {
116 A.call_once(|| {})
117 }
118 let mut a = Command::new("bin/printf-stderr");
119 a.args(["%s", "alfa"]);
120 a
121 }
122
123 static B: Once = Once::new();
124 fn b() -> Vec<u8> {
125 if B.is_completed() {
126 panic!("B.is_completed()")
127 } else {
128 B.call_once(|| {})
129 }
130 vec![b'a', b'a']
131 }
132
133 assert_eq!(A.is_completed(), false);
134 assert_eq!(B.is_completed(), false);
135 let result = assert_command_stderr_gt_x_as_result!(a(), b());
136 assert!(result.is_ok());
137 assert_eq!(A.is_completed(), true);
138 assert_eq!(B.is_completed(), true);
139 }
140
141 #[test]
142 fn eq() {
143 let mut a = Command::new("bin/printf-stderr");
144 a.args(["%s", "alfa"]);
145 let b = vec![b'a', b'l', b'f', b'a'];
146 let actual = assert_command_stderr_gt_x_as_result!(a, b);
147 let message = concat!(
148 "assertion failed: `assert_command_stderr_gt_x!(command, expr)`\n",
149 "https://docs.rs/assertables/9.8.6/assertables/macro.assert_command_stderr_gt_x.html\n",
150 " command label: `a`,\n",
151 " command debug: `\"bin/printf-stderr\" \"%s\" \"alfa\"`,\n",
152 " command value: `[97, 108, 102, 97]`,\n",
153 " expr label: `b`,\n",
154 " expr debug: `[97, 108, 102, 97]`,\n",
155 " expr value: `[97, 108, 102, 97]`"
156 );
157 assert_eq!(actual.unwrap_err(), message);
158 }
159
160 #[test]
161 fn lt() {
162 let mut a = Command::new("bin/printf-stderr");
163 a.args(["%s", "alfa"]);
164 let b = vec![b'z', b'z'];
165 let actual = assert_command_stderr_gt_x_as_result!(a, b);
166 let message = concat!(
167 "assertion failed: `assert_command_stderr_gt_x!(command, expr)`\n",
168 "https://docs.rs/assertables/9.8.6/assertables/macro.assert_command_stderr_gt_x.html\n",
169 " command label: `a`,\n",
170 " command debug: `\"bin/printf-stderr\" \"%s\" \"alfa\"`,\n",
171 " command value: `[97, 108, 102, 97]`,\n",
172 " expr label: `b`,\n",
173 " expr debug: `[122, 122]`,\n",
174 " expr value: `[122, 122]`"
175 );
176 assert_eq!(actual.unwrap_err(), message);
177 }
178}
179
180#[macro_export]
240macro_rules! assert_command_stderr_gt_x {
241 ($a_command:expr, $b_expr:expr $(,)?) => {
242 match $crate::assert_command_stderr_gt_x_as_result!($a_command, $b_expr) {
243 Ok(x) => x,
244 Err(err) => panic!("{}", err),
245 }
246 };
247 ($a_command:expr, $b_expr:expr, $($message:tt)+) => {
248 match $crate::assert_command_stderr_gt_x_as_result!($a_command, $b_expr) {
249 Ok(x) => x,
250 Err(err) => panic!("{}\n{}", format_args!($($message)+), err),
251 }
252 };
253}
254
255#[cfg(test)]
256mod test_assert_command_stderr_gt_x {
257 use std::panic;
258 use std::process::Command;
259
260 #[test]
261 fn gt() {
262 let mut a = Command::new("bin/printf-stderr");
263 a.args(["%s", "alfa"]);
264 let b = vec![b'a', b'a'];
265 for _ in 0..1 {
266 let actual = assert_command_stderr_gt_x!(a, b);
267 assert_eq!(actual, vec![b'a', b'l', b'f', b'a']);
268 }
269 }
270
271 #[test]
272 fn eq() {
273 let result = panic::catch_unwind(|| {
274 let mut a = Command::new("bin/printf-stderr");
275 a.args(["%s", "alfa"]);
276 let b = vec![b'a', b'l', b'f', b'a'];
277 let _actual = assert_command_stderr_gt_x!(a, b);
278 });
279 let message = concat!(
280 "assertion failed: `assert_command_stderr_gt_x!(command, expr)`\n",
281 "https://docs.rs/assertables/9.8.6/assertables/macro.assert_command_stderr_gt_x.html\n",
282 " command label: `a`,\n",
283 " command debug: `\"bin/printf-stderr\" \"%s\" \"alfa\"`,\n",
284 " command value: `[97, 108, 102, 97]`,\n",
285 " expr label: `b`,\n",
286 " expr debug: `[97, 108, 102, 97]`,\n",
287 " expr value: `[97, 108, 102, 97]`"
288 );
289 assert_eq!(
290 result
291 .unwrap_err()
292 .downcast::<String>()
293 .unwrap()
294 .to_string(),
295 message
296 );
297 }
298
299 #[test]
300 fn lt() {
301 let result = panic::catch_unwind(|| {
302 let mut a = Command::new("bin/printf-stderr");
303 a.args(["%s", "alfa"]);
304 let b = vec![b'z', b'z'];
305 let _actual = assert_command_stderr_gt_x!(a, b);
306 });
307 let message = concat!(
308 "assertion failed: `assert_command_stderr_gt_x!(command, expr)`\n",
309 "https://docs.rs/assertables/9.8.6/assertables/macro.assert_command_stderr_gt_x.html\n",
310 " command label: `a`,\n",
311 " command debug: `\"bin/printf-stderr\" \"%s\" \"alfa\"`,\n",
312 " command value: `[97, 108, 102, 97]`,\n",
313 " expr label: `b`,\n",
314 " expr debug: `[122, 122]`,\n",
315 " expr value: `[122, 122]`"
316 );
317 assert_eq!(
318 result
319 .unwrap_err()
320 .downcast::<String>()
321 .unwrap()
322 .to_string(),
323 message
324 );
325 }
326}
327
328#[macro_export]
360macro_rules! debug_assert_command_stderr_gt_x {
361 ($($arg:tt)*) => {
362 if cfg!(debug_assertions) {
363 $crate::assert_command_stderr_gt_x!($($arg)*);
364 }
365 };
366}
367
368#[cfg(test)]
369mod test_debug_assert_command_stderr_gt_x {
370 use std::panic;
371 use std::process::Command;
372
373 #[test]
374 fn gt() {
375 let mut a = Command::new("bin/printf-stderr");
376 a.args(["%s", "alfa"]);
377 let b = vec![b'a', b'a'];
378 for _ in 0..1 {
379 let _actual = debug_assert_command_stderr_gt_x!(a, b);
380 }
382 }
383
384 #[test]
385 fn eq() {
386 let result = panic::catch_unwind(|| {
387 let mut a = Command::new("bin/printf-stderr");
388 a.args(["%s", "alfa"]);
389 let b = vec![b'a', b'l', b'f', b'a'];
390 let _actual = debug_assert_command_stderr_gt_x!(a, b);
391 });
392 let message = concat!(
393 "assertion failed: `assert_command_stderr_gt_x!(command, expr)`\n",
394 "https://docs.rs/assertables/9.8.6/assertables/macro.assert_command_stderr_gt_x.html\n",
395 " command label: `a`,\n",
396 " command debug: `\"bin/printf-stderr\" \"%s\" \"alfa\"`,\n",
397 " command value: `[97, 108, 102, 97]`,\n",
398 " expr label: `b`,\n",
399 " expr debug: `[97, 108, 102, 97]`,\n",
400 " expr value: `[97, 108, 102, 97]`"
401 );
402 assert_eq!(
403 result
404 .unwrap_err()
405 .downcast::<String>()
406 .unwrap()
407 .to_string(),
408 message
409 );
410 }
411
412 #[test]
413 fn lt() {
414 let result = panic::catch_unwind(|| {
415 let mut a = Command::new("bin/printf-stderr");
416 a.args(["%s", "alfa"]);
417 let b = vec![b'z', b'z'];
418 let _actual = debug_assert_command_stderr_gt_x!(a, b);
419 });
420 let message = concat!(
421 "assertion failed: `assert_command_stderr_gt_x!(command, expr)`\n",
422 "https://docs.rs/assertables/9.8.6/assertables/macro.assert_command_stderr_gt_x.html\n",
423 " command label: `a`,\n",
424 " command debug: `\"bin/printf-stderr\" \"%s\" \"alfa\"`,\n",
425 " command value: `[97, 108, 102, 97]`,\n",
426 " expr label: `b`,\n",
427 " expr debug: `[122, 122]`,\n",
428 " expr value: `[122, 122]`"
429 );
430 assert_eq!(
431 result
432 .unwrap_err()
433 .downcast::<String>()
434 .unwrap()
435 .to_string(),
436 message
437 );
438 }
439}