summaryrefslogtreecommitdiffstats
path: root/vendor/anyhow/tests
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/anyhow/tests')
-rw-r--r--vendor/anyhow/tests/common/mod.rs14
-rw-r--r--vendor/anyhow/tests/compiletest.rs7
-rw-r--r--vendor/anyhow/tests/drop/mod.rs53
-rw-r--r--vendor/anyhow/tests/test_autotrait.rs13
-rw-r--r--vendor/anyhow/tests/test_backtrace.rs13
-rw-r--r--vendor/anyhow/tests/test_boxed.rs45
-rw-r--r--vendor/anyhow/tests/test_chain.rs68
-rw-r--r--vendor/anyhow/tests/test_context.rs172
-rw-r--r--vendor/anyhow/tests/test_convert.rs46
-rw-r--r--vendor/anyhow/tests/test_downcast.rs123
-rw-r--r--vendor/anyhow/tests/test_ensure.rs698
-rw-r--r--vendor/anyhow/tests/test_ffi.rs18
-rw-r--r--vendor/anyhow/tests/test_fmt.rs94
-rw-r--r--vendor/anyhow/tests/test_macros.rs80
-rw-r--r--vendor/anyhow/tests/test_repr.rs29
-rw-r--r--vendor/anyhow/tests/test_source.rs62
-rw-r--r--vendor/anyhow/tests/ui/chained-comparison.rs8
-rw-r--r--vendor/anyhow/tests/ui/chained-comparison.stderr10
-rw-r--r--vendor/anyhow/tests/ui/empty-ensure.rs6
-rw-r--r--vendor/anyhow/tests/ui/empty-ensure.stderr7
-rw-r--r--vendor/anyhow/tests/ui/must-use.rs11
-rw-r--r--vendor/anyhow/tests/ui/must-use.stderr12
-rw-r--r--vendor/anyhow/tests/ui/no-impl.rs8
-rw-r--r--vendor/anyhow/tests/ui/no-impl.stderr31
-rw-r--r--vendor/anyhow/tests/ui/temporary-value.rs5
-rw-r--r--vendor/anyhow/tests/ui/temporary-value.stderr9
-rw-r--r--vendor/anyhow/tests/ui/wrong-interpolation.rs5
-rw-r--r--vendor/anyhow/tests/ui/wrong-interpolation.stderr5
28 files changed, 1652 insertions, 0 deletions
diff --git a/vendor/anyhow/tests/common/mod.rs b/vendor/anyhow/tests/common/mod.rs
new file mode 100644
index 000000000..fc165a5be
--- /dev/null
+++ b/vendor/anyhow/tests/common/mod.rs
@@ -0,0 +1,14 @@
+use anyhow::{bail, Result};
+use std::io;
+
+pub fn bail_literal() -> Result<()> {
+ bail!("oh no!");
+}
+
+pub fn bail_fmt() -> Result<()> {
+ bail!("{} {}!", "oh", "no");
+}
+
+pub fn bail_error() -> Result<()> {
+ bail!(io::Error::new(io::ErrorKind::Other, "oh no!"));
+}
diff --git a/vendor/anyhow/tests/compiletest.rs b/vendor/anyhow/tests/compiletest.rs
new file mode 100644
index 000000000..7974a6249
--- /dev/null
+++ b/vendor/anyhow/tests/compiletest.rs
@@ -0,0 +1,7 @@
+#[rustversion::attr(not(nightly), ignore)]
+#[cfg_attr(miri, ignore)]
+#[test]
+fn ui() {
+ let t = trybuild::TestCases::new();
+ t.compile_fail("tests/ui/*.rs");
+}
diff --git a/vendor/anyhow/tests/drop/mod.rs b/vendor/anyhow/tests/drop/mod.rs
new file mode 100644
index 000000000..7da4bf55a
--- /dev/null
+++ b/vendor/anyhow/tests/drop/mod.rs
@@ -0,0 +1,53 @@
+#![allow(clippy::module_name_repetitions)]
+
+use std::error::Error as StdError;
+use std::fmt::{self, Display};
+use std::sync::atomic::{AtomicBool, Ordering};
+use std::sync::Arc;
+
+#[derive(Debug)]
+pub struct Flag {
+ atomic: Arc<AtomicBool>,
+}
+
+impl Flag {
+ pub fn new() -> Self {
+ Flag {
+ atomic: Arc::new(AtomicBool::new(false)),
+ }
+ }
+
+ pub fn get(&self) -> bool {
+ self.atomic.load(Ordering::Relaxed)
+ }
+}
+
+#[derive(Debug)]
+pub struct DetectDrop {
+ has_dropped: Flag,
+}
+
+impl DetectDrop {
+ pub fn new(has_dropped: &Flag) -> Self {
+ DetectDrop {
+ has_dropped: Flag {
+ atomic: Arc::clone(&has_dropped.atomic),
+ },
+ }
+ }
+}
+
+impl StdError for DetectDrop {}
+
+impl Display for DetectDrop {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ write!(f, "oh no!")
+ }
+}
+
+impl Drop for DetectDrop {
+ fn drop(&mut self) {
+ let already_dropped = self.has_dropped.atomic.swap(true, Ordering::Relaxed);
+ assert!(!already_dropped);
+ }
+}
diff --git a/vendor/anyhow/tests/test_autotrait.rs b/vendor/anyhow/tests/test_autotrait.rs
new file mode 100644
index 000000000..0c9326dad
--- /dev/null
+++ b/vendor/anyhow/tests/test_autotrait.rs
@@ -0,0 +1,13 @@
+use anyhow::Error;
+
+#[test]
+fn test_send() {
+ fn assert_send<T: Send>() {}
+ assert_send::<Error>();
+}
+
+#[test]
+fn test_sync() {
+ fn assert_sync<T: Sync>() {}
+ assert_sync::<Error>();
+}
diff --git a/vendor/anyhow/tests/test_backtrace.rs b/vendor/anyhow/tests/test_backtrace.rs
new file mode 100644
index 000000000..ce385f501
--- /dev/null
+++ b/vendor/anyhow/tests/test_backtrace.rs
@@ -0,0 +1,13 @@
+#[rustversion::not(nightly)]
+#[ignore]
+#[test]
+fn test_backtrace() {}
+
+#[rustversion::nightly]
+#[test]
+fn test_backtrace() {
+ use anyhow::anyhow;
+
+ let error = anyhow!("oh no!");
+ let _ = error.backtrace();
+}
diff --git a/vendor/anyhow/tests/test_boxed.rs b/vendor/anyhow/tests/test_boxed.rs
new file mode 100644
index 000000000..fb1fb132d
--- /dev/null
+++ b/vendor/anyhow/tests/test_boxed.rs
@@ -0,0 +1,45 @@
+#![allow(
+ // Clippy bug: https://github.com/rust-lang/rust-clippy/issues/7422
+ clippy::nonstandard_macro_braces,
+)]
+
+use anyhow::anyhow;
+use std::error::Error as StdError;
+use std::io;
+use thiserror::Error;
+
+#[derive(Error, Debug)]
+#[error("outer")]
+struct MyError {
+ source: io::Error,
+}
+
+#[test]
+fn test_boxed_str() {
+ let error = Box::<dyn StdError + Send + Sync>::from("oh no!");
+ let error = anyhow!(error);
+ assert_eq!("oh no!", error.to_string());
+ assert_eq!(
+ "oh no!",
+ error
+ .downcast_ref::<Box<dyn StdError + Send + Sync>>()
+ .unwrap()
+ .to_string()
+ );
+}
+
+#[test]
+fn test_boxed_thiserror() {
+ let error = MyError {
+ source: io::Error::new(io::ErrorKind::Other, "oh no!"),
+ };
+ let error = anyhow!(error);
+ assert_eq!("oh no!", error.source().unwrap().to_string());
+}
+
+#[test]
+fn test_boxed_anyhow() {
+ let error = anyhow!("oh no!").context("it failed");
+ let error = anyhow!(error);
+ assert_eq!("oh no!", error.source().unwrap().to_string());
+}
diff --git a/vendor/anyhow/tests/test_chain.rs b/vendor/anyhow/tests/test_chain.rs
new file mode 100644
index 000000000..47d98afe2
--- /dev/null
+++ b/vendor/anyhow/tests/test_chain.rs
@@ -0,0 +1,68 @@
+use anyhow::{anyhow, Chain, Error};
+
+fn error() -> Error {
+ anyhow!({ 0 }).context(1).context(2).context(3)
+}
+
+#[test]
+fn test_iter() {
+ let e = error();
+ let mut chain = e.chain();
+ assert_eq!("3", chain.next().unwrap().to_string());
+ assert_eq!("2", chain.next().unwrap().to_string());
+ assert_eq!("1", chain.next().unwrap().to_string());
+ assert_eq!("0", chain.next().unwrap().to_string());
+ assert!(chain.next().is_none());
+ assert!(chain.next_back().is_none());
+}
+
+#[test]
+fn test_rev() {
+ let e = error();
+ let mut chain = e.chain().rev();
+ assert_eq!("0", chain.next().unwrap().to_string());
+ assert_eq!("1", chain.next().unwrap().to_string());
+ assert_eq!("2", chain.next().unwrap().to_string());
+ assert_eq!("3", chain.next().unwrap().to_string());
+ assert!(chain.next().is_none());
+ assert!(chain.next_back().is_none());
+}
+
+#[test]
+fn test_len() {
+ let e = error();
+ let mut chain = e.chain();
+ assert_eq!(4, chain.len());
+ assert_eq!((4, Some(4)), chain.size_hint());
+ assert_eq!("3", chain.next().unwrap().to_string());
+ assert_eq!(3, chain.len());
+ assert_eq!((3, Some(3)), chain.size_hint());
+ assert_eq!("0", chain.next_back().unwrap().to_string());
+ assert_eq!(2, chain.len());
+ assert_eq!((2, Some(2)), chain.size_hint());
+ assert_eq!("2", chain.next().unwrap().to_string());
+ assert_eq!(1, chain.len());
+ assert_eq!((1, Some(1)), chain.size_hint());
+ assert_eq!("1", chain.next_back().unwrap().to_string());
+ assert_eq!(0, chain.len());
+ assert_eq!((0, Some(0)), chain.size_hint());
+ assert!(chain.next().is_none());
+}
+
+#[test]
+fn test_default() {
+ let mut c = Chain::default();
+ assert!(c.next().is_none());
+}
+
+#[test]
+fn test_clone() {
+ let e = error();
+ let mut chain = e.chain().clone();
+ assert_eq!("3", chain.next().unwrap().to_string());
+ assert_eq!("2", chain.next().unwrap().to_string());
+ assert_eq!("1", chain.next().unwrap().to_string());
+ assert_eq!("0", chain.next().unwrap().to_string());
+ assert!(chain.next().is_none());
+ assert!(chain.next_back().is_none());
+}
diff --git a/vendor/anyhow/tests/test_context.rs b/vendor/anyhow/tests/test_context.rs
new file mode 100644
index 000000000..2053fc9e5
--- /dev/null
+++ b/vendor/anyhow/tests/test_context.rs
@@ -0,0 +1,172 @@
+#![allow(
+ // Clippy bug: https://github.com/rust-lang/rust-clippy/issues/7422
+ clippy::nonstandard_macro_braces,
+)]
+
+mod drop;
+
+use crate::drop::{DetectDrop, Flag};
+use anyhow::{Context, Error, Result};
+use std::fmt::{self, Display};
+use thiserror::Error;
+
+// https://github.com/dtolnay/anyhow/issues/18
+#[test]
+fn test_inference() -> Result<()> {
+ let x = "1";
+ let y: u32 = x.parse().context("...")?;
+ assert_eq!(y, 1);
+ Ok(())
+}
+
+macro_rules! context_type {
+ ($name:ident) => {
+ #[derive(Debug)]
+ struct $name {
+ message: &'static str,
+ #[allow(dead_code)]
+ drop: DetectDrop,
+ }
+
+ impl Display for $name {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ f.write_str(self.message)
+ }
+ }
+ };
+}
+
+context_type!(HighLevel);
+context_type!(MidLevel);
+
+#[derive(Error, Debug)]
+#[error("{message}")]
+struct LowLevel {
+ message: &'static str,
+ drop: DetectDrop,
+}
+
+struct Dropped {
+ low: Flag,
+ mid: Flag,
+ high: Flag,
+}
+
+impl Dropped {
+ fn none(&self) -> bool {
+ !self.low.get() && !self.mid.get() && !self.high.get()
+ }
+
+ fn all(&self) -> bool {
+ self.low.get() && self.mid.get() && self.high.get()
+ }
+}
+
+fn make_chain() -> (Error, Dropped) {
+ let dropped = Dropped {
+ low: Flag::new(),
+ mid: Flag::new(),
+ high: Flag::new(),
+ };
+
+ let low = LowLevel {
+ message: "no such file or directory",
+ drop: DetectDrop::new(&dropped.low),
+ };
+
+ // impl Context for Result<T, E>
+ let mid = Err::<(), LowLevel>(low)
+ .context(MidLevel {
+ message: "failed to load config",
+ drop: DetectDrop::new(&dropped.mid),
+ })
+ .unwrap_err();
+
+ // impl Context for Result<T, Error>
+ let high = Err::<(), Error>(mid)
+ .context(HighLevel {
+ message: "failed to start server",
+ drop: DetectDrop::new(&dropped.high),
+ })
+ .unwrap_err();
+
+ (high, dropped)
+}
+
+#[test]
+fn test_downcast_ref() {
+ let (err, dropped) = make_chain();
+
+ assert!(!err.is::<String>());
+ assert!(err.downcast_ref::<String>().is_none());
+
+ assert!(err.is::<HighLevel>());
+ let high = err.downcast_ref::<HighLevel>().unwrap();
+ assert_eq!(high.to_string(), "failed to start server");
+
+ assert!(err.is::<MidLevel>());
+ let mid = err.downcast_ref::<MidLevel>().unwrap();
+ assert_eq!(mid.to_string(), "failed to load config");
+
+ assert!(err.is::<LowLevel>());
+ let low = err.downcast_ref::<LowLevel>().unwrap();
+ assert_eq!(low.to_string(), "no such file or directory");
+
+ assert!(dropped.none());
+ drop(err);
+ assert!(dropped.all());
+}
+
+#[test]
+fn test_downcast_high() {
+ let (err, dropped) = make_chain();
+
+ let err = err.downcast::<HighLevel>().unwrap();
+ assert!(!dropped.high.get());
+ assert!(dropped.low.get() && dropped.mid.get());
+
+ drop(err);
+ assert!(dropped.all());
+}
+
+#[test]
+fn test_downcast_mid() {
+ let (err, dropped) = make_chain();
+
+ let err = err.downcast::<MidLevel>().unwrap();
+ assert!(!dropped.mid.get());
+ assert!(dropped.low.get() && dropped.high.get());
+
+ drop(err);
+ assert!(dropped.all());
+}
+
+#[test]
+fn test_downcast_low() {
+ let (err, dropped) = make_chain();
+
+ let err = err.downcast::<LowLevel>().unwrap();
+ assert!(!dropped.low.get());
+ assert!(dropped.mid.get() && dropped.high.get());
+
+ drop(err);
+ assert!(dropped.all());
+}
+
+#[test]
+fn test_unsuccessful_downcast() {
+ let (err, dropped) = make_chain();
+
+ let err = err.downcast::<String>().unwrap_err();
+ assert!(dropped.none());
+
+ drop(err);
+ assert!(dropped.all());
+}
+
+#[test]
+fn test_root_cause() {
+ let (err, _) = make_chain();
+
+ assert_eq!(err.root_cause().to_string(), "no such file or directory");
+}
diff --git a/vendor/anyhow/tests/test_convert.rs b/vendor/anyhow/tests/test_convert.rs
new file mode 100644
index 000000000..6da171d1b
--- /dev/null
+++ b/vendor/anyhow/tests/test_convert.rs
@@ -0,0 +1,46 @@
+#![allow(clippy::unnecessary_wraps)]
+
+mod drop;
+
+use self::drop::{DetectDrop, Flag};
+use anyhow::{Error, Result};
+use std::error::Error as StdError;
+
+#[test]
+fn test_convert() {
+ let has_dropped = Flag::new();
+ let error = Error::new(DetectDrop::new(&has_dropped));
+ let box_dyn = Box::<dyn StdError>::from(error);
+ assert_eq!("oh no!", box_dyn.to_string());
+ drop(box_dyn);
+ assert!(has_dropped.get());
+}
+
+#[test]
+fn test_convert_send() {
+ let has_dropped = Flag::new();
+ let error = Error::new(DetectDrop::new(&has_dropped));
+ let box_dyn = Box::<dyn StdError + Send>::from(error);
+ assert_eq!("oh no!", box_dyn.to_string());
+ drop(box_dyn);
+ assert!(has_dropped.get());
+}
+
+#[test]
+fn test_convert_send_sync() {
+ let has_dropped = Flag::new();
+ let error = Error::new(DetectDrop::new(&has_dropped));
+ let box_dyn = Box::<dyn StdError + Send + Sync>::from(error);
+ assert_eq!("oh no!", box_dyn.to_string());
+ drop(box_dyn);
+ assert!(has_dropped.get());
+}
+
+#[test]
+fn test_question_mark() -> Result<(), Box<dyn StdError>> {
+ fn f() -> Result<()> {
+ Ok(())
+ }
+ f()?;
+ Ok(())
+}
diff --git a/vendor/anyhow/tests/test_downcast.rs b/vendor/anyhow/tests/test_downcast.rs
new file mode 100644
index 000000000..b4470d551
--- /dev/null
+++ b/vendor/anyhow/tests/test_downcast.rs
@@ -0,0 +1,123 @@
+#![allow(clippy::assertions_on_result_states, clippy::wildcard_imports)]
+
+mod common;
+mod drop;
+
+use self::common::*;
+use self::drop::{DetectDrop, Flag};
+use anyhow::Error;
+use std::error::Error as StdError;
+use std::fmt::{self, Display};
+use std::io;
+
+#[test]
+fn test_downcast() {
+ assert_eq!(
+ "oh no!",
+ bail_literal().unwrap_err().downcast::<&str>().unwrap(),
+ );
+ assert_eq!(
+ "oh no!",
+ bail_fmt().unwrap_err().downcast::<String>().unwrap(),
+ );
+ assert_eq!(
+ "oh no!",
+ bail_error()
+ .unwrap_err()
+ .downcast::<io::Error>()
+ .unwrap()
+ .to_string(),
+ );
+}
+
+#[test]
+fn test_downcast_ref() {
+ assert_eq!(
+ "oh no!",
+ *bail_literal().unwrap_err().downcast_ref::<&str>().unwrap(),
+ );
+ assert_eq!(
+ "oh no!",
+ bail_fmt().unwrap_err().downcast_ref::<String>().unwrap(),
+ );
+ assert_eq!(
+ "oh no!",
+ bail_error()
+ .unwrap_err()
+ .downcast_ref::<io::Error>()
+ .unwrap()
+ .to_string(),
+ );
+}
+
+#[test]
+fn test_downcast_mut() {
+ assert_eq!(
+ "oh no!",
+ *bail_literal().unwrap_err().downcast_mut::<&str>().unwrap(),
+ );
+ assert_eq!(
+ "oh no!",
+ bail_fmt().unwrap_err().downcast_mut::<String>().unwrap(),
+ );
+ assert_eq!(
+ "oh no!",
+ bail_error()
+ .unwrap_err()
+ .downcast_mut::<io::Error>()
+ .unwrap()
+ .to_string(),
+ );
+
+ let mut bailed = bail_fmt().unwrap_err();
+ *bailed.downcast_mut::<String>().unwrap() = "clobber".to_string();
+ assert_eq!(bailed.downcast_ref::<String>().unwrap(), "clobber");
+ assert_eq!(bailed.downcast_mut::<String>().unwrap(), "clobber");
+ assert_eq!(bailed.downcast::<String>().unwrap(), "clobber");
+}
+
+#[test]
+fn test_drop() {
+ let has_dropped = Flag::new();
+ let error = Error::new(DetectDrop::new(&has_dropped));
+ drop(error.downcast::<DetectDrop>().unwrap());
+ assert!(has_dropped.get());
+}
+
+#[test]
+fn test_as_ref() {
+ let error = bail_error().unwrap_err();
+ let ref_dyn: &dyn StdError = error.as_ref();
+ assert_eq!("oh no!", ref_dyn.to_string());
+ let ref_dyn_send_sync: &(dyn StdError + Send + Sync) = error.as_ref();
+ assert_eq!("oh no!", ref_dyn_send_sync.to_string());
+}
+
+#[test]
+fn test_large_alignment() {
+ #[repr(align(64))]
+ #[derive(Debug)]
+ struct LargeAlignedError(&'static str);
+
+ impl Display for LargeAlignedError {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ f.write_str(self.0)
+ }
+ }
+
+ impl StdError for LargeAlignedError {}
+
+ let error = Error::new(LargeAlignedError("oh no!"));
+ assert_eq!(
+ "oh no!",
+ error.downcast_ref::<LargeAlignedError>().unwrap().0
+ );
+}
+
+#[test]
+fn test_unsuccessful_downcast() {
+ let mut error = bail_error().unwrap_err();
+ assert!(error.downcast_ref::<&str>().is_none());
+ assert!(error.downcast_mut::<&str>().is_none());
+ assert!(error.downcast::<&str>().is_err());
+}
diff --git a/vendor/anyhow/tests/test_ensure.rs b/vendor/anyhow/tests/test_ensure.rs
new file mode 100644
index 000000000..4bb12f9fa
--- /dev/null
+++ b/vendor/anyhow/tests/test_ensure.rs
@@ -0,0 +1,698 @@
+#![allow(
+ clippy::diverging_sub_expression,
+ clippy::if_same_then_else,
+ clippy::ifs_same_cond,
+ clippy::items_after_statements,
+ clippy::let_and_return,
+ clippy::let_underscore_drop,
+ clippy::logic_bug,
+ clippy::match_bool,
+ clippy::never_loop,
+ clippy::redundant_closure_call,
+ clippy::redundant_pattern_matching,
+ clippy::too_many_lines,
+ clippy::unit_arg,
+ clippy::while_immutable_condition,
+ clippy::zero_ptr,
+ irrefutable_let_patterns
+)]
+
+use anyhow::{anyhow, ensure, Chain, Error, Result};
+use std::fmt::Debug;
+use std::iter;
+use std::marker::{PhantomData, PhantomData as P};
+use std::ops::Add;
+use std::ptr;
+
+struct S;
+
+impl<T> Add<T> for S {
+ type Output = bool;
+ fn add(self, rhs: T) -> Self::Output {
+ let _ = rhs;
+ false
+ }
+}
+
+trait Trait: Sized {
+ const V: usize = 0;
+ fn t(self, i: i32) -> i32 {
+ i
+ }
+}
+
+impl<T> Trait for T {}
+
+#[track_caller]
+fn assert_err<T: Debug>(result: impl FnOnce() -> Result<T>, expected: &'static str) {
+ let actual = result().unwrap_err().to_string();
+
+ // In general different rustc versions will format the interpolated lhs and
+ // rhs $:expr fragment with insignificant differences in whitespace or
+ // punctuation, so we check the message in full against nightly and do just
+ // a cursory test on older toolchains.
+ if rustversion::cfg!(nightly) && !cfg!(miri) {
+ assert_eq!(actual, expected);
+ } else {
+ assert_eq!(actual.contains(" vs "), expected.contains(" vs "));
+ }
+}
+
+#[test]
+fn test_recursion() {
+ // Must not blow the default #[recursion_limit], which is 128.
+ #[rustfmt::skip]
+ let test = || Ok(ensure!(
+ false | false | false | false | false | false | false | false | false |
+ false | false | false | false | false | false | false | false | false |
+ false | false | false | false | false | false | false | false | false |
+ false | false | false | false | false | false | false | false | false |
+ false | false | false | false | false | false | false | false | false |
+ false | false | false | false | false | false | false | false | false |
+ false | false | false | false | false | false | false | false | false
+ ));
+
+ test().unwrap_err();
+}
+
+#[test]
+fn test_low_precedence_control_flow() {
+ #[allow(unreachable_code)]
+ let test = || {
+ let val = loop {
+ // Break has lower precedence than the comparison operators so the
+ // expression here is `S + (break (1 == 1))`. It would be bad if the
+ // ensure macro partitioned this input into `(S + break 1) == (1)`
+ // because that means a different thing than what was written.
+ ensure!(S + break 1 == 1);
+ };
+ Ok(val)
+ };
+
+ assert!(test().unwrap());
+}
+
+#[test]
+fn test_low_precedence_binary_operator() {
+ // Must not partition as `false == (true && false)`.
+ let test = || Ok(ensure!(false == true && false));
+ assert_err(test, "Condition failed: `false == true && false`");
+
+ // But outside the root level, it is fine.
+ let test = || Ok(ensure!(while false == true && false {} < ()));
+ assert_err(
+ test,
+ "Condition failed: `while false == true && false {} < ()` (() vs ())",
+ );
+}
+
+#[test]
+fn test_closure() {
+ // Must not partition as `(S + move) || (1 == 1)` by treating move as an
+ // identifier, nor as `(S + move || 1) == (1)` by misinterpreting the
+ // closure precedence.
+ let test = || Ok(ensure!(S + move || 1 == 1));
+ assert_err(test, "Condition failed: `S + (move || 1 == 1)`");
+
+ let test = || Ok(ensure!(S + || 1 == 1));
+ assert_err(test, "Condition failed: `S + (|| 1 == 1)`");
+
+ // Must not partition as `S + ((move | ()) | 1) == 1` by treating those
+ // pipes as bitwise-or.
+ let test = || Ok(ensure!(S + move |()| 1 == 1));
+ assert_err(test, "Condition failed: `S + (move |()| 1 == 1)`");
+
+ let test = || Ok(ensure!(S + |()| 1 == 1));
+ assert_err(test, "Condition failed: `S + (|()| 1 == 1)`");
+}
+
+#[test]
+fn test_unary() {
+ let mut x = &1;
+ let test = || Ok(ensure!(*x == 2));
+ assert_err(test, "Condition failed: `*x == 2` (1 vs 2)");
+
+ let test = || Ok(ensure!(!x == 1));
+ assert_err(test, "Condition failed: `!x == 1` (-2 vs 1)");
+
+ let test = || Ok(ensure!(-x == 1));
+ assert_err(test, "Condition failed: `-x == 1` (-1 vs 1)");
+
+ let test = || Ok(ensure!(&x == &&2));
+ assert_err(test, "Condition failed: `&x == &&2` (1 vs 2)");
+
+ let test = || Ok(ensure!(&mut x == *&&mut &2));
+ assert_err(test, "Condition failed: `&mut x == *&&mut &2` (1 vs 2)");
+}
+
+#[test]
+fn test_if() {
+ #[rustfmt::skip]
+ let test = || Ok(ensure!(if false {}.t(1) == 2));
+ assert_err(test, "Condition failed: `if false {}.t(1) == 2` (1 vs 2)");
+
+ #[rustfmt::skip]
+ let test = || Ok(ensure!(if false {} else {}.t(1) == 2));
+ assert_err(
+ test,
+ "Condition failed: `if false {} else {}.t(1) == 2` (1 vs 2)",
+ );
+
+ #[rustfmt::skip]
+ let test = || Ok(ensure!(if false {} else if false {}.t(1) == 2));
+ assert_err(
+ test,
+ "Condition failed: `if false {} else if false {}.t(1) == 2` (1 vs 2)",
+ );
+
+ #[rustfmt::skip]
+ let test = || Ok(ensure!(if let 1 = 2 {}.t(1) == 2));
+ assert_err(
+ test,
+ "Condition failed: `if let 1 = 2 {}.t(1) == 2` (1 vs 2)",
+ );
+
+ #[rustfmt::skip]
+ let test = || Ok(ensure!(if let 1 | 2 = 2 {}.t(1) == 2));
+ assert_err(
+ test,
+ "Condition failed: `if let 1 | 2 = 2 {}.t(1) == 2` (1 vs 2)",
+ );
+
+ #[rustfmt::skip]
+ let test = || Ok(ensure!(if let | 1 | 2 = 2 {}.t(1) == 2));
+ assert_err(
+ test,
+ "Condition failed: `if let 1 | 2 = 2 {}.t(1) == 2` (1 vs 2)",
+ );
+}
+
+#[test]
+fn test_loop() {
+ #[rustfmt::skip]
+ let test = || Ok(ensure!(1 + loop { break 1 } == 1));
+ assert_err(
+ test,
+ "Condition failed: `1 + loop { break 1 } == 1` (2 vs 1)",
+ );
+
+ #[rustfmt::skip]
+ let test = || Ok(ensure!(1 + 'a: loop { break 'a 1 } == 1));
+ assert_err(
+ test,
+ "Condition failed: `1 + 'a: loop { break 'a 1 } == 1` (2 vs 1)",
+ );
+
+ #[rustfmt::skip]
+ let test = || Ok(ensure!(while false {}.t(1) == 2));
+ assert_err(
+ test,
+ "Condition failed: `while false {}.t(1) == 2` (1 vs 2)",
+ );
+
+ #[rustfmt::skip]
+ let test = || Ok(ensure!(while let None = Some(1) {}.t(1) == 2));
+ assert_err(
+ test,
+ "Condition failed: `while let None = Some(1) {}.t(1) == 2` (1 vs 2)",
+ );
+
+ #[rustfmt::skip]
+ let test = || Ok(ensure!(for _x in iter::once(0) {}.t(1) == 2));
+ assert_err(
+ test,
+ "Condition failed: `for _x in iter::once(0) {}.t(1) == 2` (1 vs 2)",
+ );
+
+ #[rustfmt::skip]
+ let test = || Ok(ensure!(for | _x in iter::once(0) {}.t(1) == 2));
+ assert_err(
+ test,
+ "Condition failed: `for _x in iter::once(0) {}.t(1) == 2` (1 vs 2)",
+ );
+
+ #[rustfmt::skip]
+ let test = || Ok(ensure!(for true | false in iter::empty() {}.t(1) == 2));
+ assert_err(
+ test,
+ "Condition failed: `for true | false in iter::empty() {}.t(1) == 2` (1 vs 2)",
+ );
+}
+
+#[test]
+fn test_match() {
+ #[rustfmt::skip]
+ let test = || Ok(ensure!(match 1 == 1 { true => 1, false => 0 } == 2));
+ assert_err(
+ test,
+ "Condition failed: `match 1 == 1 { true => 1, false => 0, } == 2` (1 vs 2)",
+ );
+}
+
+#[test]
+fn test_atom() {
+ let test = || Ok(ensure!([false, false].len() > 3));
+ assert_err(
+ test,
+ "Condition failed: `[false, false].len() > 3` (2 vs 3)",
+ );
+
+ #[rustfmt::skip]
+ let test = || Ok(ensure!({ let x = 1; x } >= 3));
+ assert_err(test, "Condition failed: `{ let x = 1; x } >= 3` (1 vs 3)");
+
+ let test = || Ok(ensure!(S + async { 1 } == true));
+ assert_err(
+ test,
+ "Condition failed: `S + async { 1 } == true` (false vs true)",
+ );
+
+ let test = || Ok(ensure!(S + async move { 1 } == true));
+ assert_err(
+ test,
+ "Condition failed: `S + async move { 1 } == true` (false vs true)",
+ );
+
+ let x = &1;
+ let test = || Ok(ensure!(S + unsafe { ptr::read(x) } == true));
+ assert_err(
+ test,
+ "Condition failed: `S + unsafe { ptr::read(x) } == true` (false vs true)",
+ );
+}
+
+#[test]
+fn test_path() {
+ let test = || Ok(ensure!(crate::S.t(1) == 2));
+ assert_err(test, "Condition failed: `crate::S.t(1) == 2` (1 vs 2)");
+
+ let test = || Ok(ensure!(::anyhow::Error::root_cause.t(1) == 2));
+ assert_err(
+ test,
+ "Condition failed: `::anyhow::Error::root_cause.t(1) == 2` (1 vs 2)",
+ );
+
+ let test = || Ok(ensure!(Error::msg::<&str>.t(1) == 2));
+ assert_err(
+ test,
+ "Condition failed: `Error::msg::<&str>.t(1) == 2` (1 vs 2)",
+ );
+
+ #[rustfmt::skip]
+ let test = || Ok(ensure!(Error::msg::<&str,>.t(1) == 2));
+ assert_err(
+ test,
+ "Condition failed: `Error::msg::<&str>.t(1) == 2` (1 vs 2)",
+ );
+
+ let test = || Ok(ensure!(Error::msg::<<str as ToOwned>::Owned>.t(1) == 2));
+ assert_err(
+ test,
+ "Condition failed: `Error::msg::<<str as ToOwned>::Owned>.t(1) == 2` (1 vs 2)",
+ );
+
+ let test = || Ok(ensure!(Chain::<'static>::new.t(1) == 2));
+ assert_err(
+ test,
+ "Condition failed: `Chain::<'static>::new.t(1) == 2` (1 vs 2)",
+ );
+
+ #[rustfmt::skip]
+ let test = || Ok(ensure!(Chain::<'static,>::new.t(1) == 2));
+ assert_err(
+ test,
+ "Condition failed: `Chain::<'static>::new.t(1) == 2` (1 vs 2)",
+ );
+
+ fn f<const I: isize>() {}
+ let test = || Ok(ensure!(f::<1>() != ()));
+ assert_err(test, "Condition failed: `f::<1>() != ()` (() vs ())");
+ let test = || Ok(ensure!(f::<-1>() != ()));
+ assert_err(test, "Condition failed: `f::<-1>() != ()` (() vs ())");
+
+ fn g<T, const I: isize>() {}
+ let test = || Ok(ensure!(g::<u8, 1>() != ()));
+ assert_err(test, "Condition failed: `g::<u8, 1>() != ()` (() vs ())");
+ let test = || Ok(ensure!(g::<u8, -1>() != ()));
+ assert_err(test, "Condition failed: `g::<u8, -1>() != ()` (() vs ())");
+
+ #[derive(PartialOrd, PartialEq, Debug)]
+ enum E<'a, T> {
+ #[allow(dead_code)]
+ T(&'a T),
+ U,
+ }
+
+ #[rustfmt::skip]
+ let test = || Ok(ensure!(E::U::<>>E::U::<u8>));
+ assert_err(test, "Condition failed: `E::U::<> > E::U::<u8>` (U vs U)");
+
+ #[rustfmt::skip]
+ let test = || Ok(ensure!(E::U::<u8>>E::U));
+ assert_err(test, "Condition failed: `E::U::<u8> > E::U` (U vs U)");
+
+ #[rustfmt::skip]
+ let test = || Ok(ensure!(E::U::<u8,>>E::U));
+ assert_err(test, "Condition failed: `E::U::<u8> > E::U` (U vs U)");
+
+ let test = || Ok(ensure!(PhantomData::<dyn Debug + Sync> != PhantomData));
+ assert_err(
+ test,
+ "Condition failed: `PhantomData::<dyn Debug + Sync> != PhantomData` (PhantomData vs PhantomData)",
+ );
+
+ let test = || Ok(ensure!(PhantomData::<dyn Fn() + Sync> != PhantomData));
+ assert_err(
+ test,
+ "Condition failed: `PhantomData::<dyn Fn() + Sync> != PhantomData` (PhantomData vs PhantomData)",
+ );
+
+ #[rustfmt::skip]
+ let test = || {
+ Ok(ensure!(
+ PhantomData::<dyn Fn::() + ::std::marker::Sync> != PhantomData
+ ))
+ };
+ assert_err(
+ test,
+ "Condition failed: `PhantomData::<dyn Fn() + ::std::marker::Sync> != PhantomData` (PhantomData vs PhantomData)",
+ );
+}
+
+#[test]
+fn test_macro() {
+ let test = || Ok(ensure!(anyhow!("...").to_string().len() <= 1));
+ assert_err(
+ test,
+ "Condition failed: `anyhow!(\"...\").to_string().len() <= 1` (3 vs 1)",
+ );
+
+ let test = || Ok(ensure!(vec![1].len() < 1));
+ assert_err(test, "Condition failed: `vec![1].len() < 1` (1 vs 1)");
+
+ let test = || Ok(ensure!(stringify! {} != ""));
+ assert_err(
+ test,
+ "Condition failed: `stringify! {} != \"\"` (\"\" vs \"\")",
+ );
+}
+
+#[test]
+fn test_trailer() {
+ let test = || Ok(ensure!((|| 1)() == 2));
+ assert_err(test, "Condition failed: `(|| 1)() == 2` (1 vs 2)");
+
+ let test = || Ok(ensure!(b"hmm"[1] == b'c'));
+ assert_err(test, "Condition failed: `b\"hmm\"[1] == b'c'` (109 vs 99)");
+
+ let test = || Ok(ensure!(PhantomData::<u8> {} != PhantomData));
+ assert_err(
+ test,
+ "Condition failed: `PhantomData::<u8> {} != PhantomData` (PhantomData vs PhantomData)",
+ );
+
+ let result = Ok::<_, Error>(1);
+ let test = || Ok(ensure!(result? == 2));
+ assert_err(test, "Condition failed: `result? == 2` (1 vs 2)");
+
+ let test = || Ok(ensure!((2, 3).1 == 2));
+ assert_err(test, "Condition failed: `(2, 3).1 == 2` (3 vs 2)");
+
+ #[rustfmt::skip]
+ let test = || Ok(ensure!((2, (3, 4)). 1.1 == 2));
+ assert_err(test, "Condition failed: `(2, (3, 4)).1.1 == 2` (4 vs 2)");
+
+ let err = anyhow!("");
+ let test = || Ok(ensure!(err.is::<&str>() == false));
+ assert_err(
+ test,
+ "Condition failed: `err.is::<&str>() == false` (true vs false)",
+ );
+
+ let test = || Ok(ensure!(err.is::<<str as ToOwned>::Owned>() == true));
+ assert_err(
+ test,
+ "Condition failed: `err.is::<<str as ToOwned>::Owned>() == true` (false vs true)",
+ );
+}
+
+#[test]
+fn test_whitespace() {
+ #[derive(Debug)]
+ pub struct Point {
+ pub x: i32,
+ pub y: i32,
+ }
+
+ let point = Point { x: 0, y: 0 };
+ let test = || Ok(ensure!("" == format!("{:#?}", point)));
+ assert_err(
+ test,
+ "Condition failed: `\"\" == format!(\"{:#?}\", point)`",
+ );
+}
+
+#[test]
+fn test_too_long() {
+ let test = || Ok(ensure!("" == "x".repeat(10)));
+ assert_err(
+ test,
+ "Condition failed: `\"\" == \"x\".repeat(10)` (\"\" vs \"xxxxxxxxxx\")",
+ );
+
+ let test = || Ok(ensure!("" == "x".repeat(80)));
+ assert_err(test, "Condition failed: `\"\" == \"x\".repeat(80)`");
+}
+
+#[test]
+fn test_as() {
+ let test = || Ok(ensure!('\0' as u8 > 1));
+ assert_err(test, "Condition failed: `'\\0' as u8 > 1` (0 vs 1)");
+
+ let test = || Ok(ensure!('\0' as ::std::primitive::u8 > 1));
+ assert_err(
+ test,
+ "Condition failed: `'\\0' as ::std::primitive::u8 > 1` (0 vs 1)",
+ );
+
+ let test = || Ok(ensure!(&[0] as &[i32] == [1]));
+ assert_err(
+ test,
+ "Condition failed: `&[0] as &[i32] == [1]` ([0] vs [1])",
+ );
+
+ let test = || Ok(ensure!(0 as *const () as *mut _ == 1 as *mut ()));
+ assert_err(
+ test,
+ "Condition failed: `0 as *const () as *mut _ == 1 as *mut ()` (0x0 vs 0x1)",
+ );
+
+ let s = "";
+ let test = || Ok(ensure!(s as &str != s));
+ assert_err(test, "Condition failed: `s as &str != s` (\"\" vs \"\")");
+
+ let test = || Ok(ensure!(&s as &&str != &s));
+ assert_err(test, "Condition failed: `&s as &&str != &s` (\"\" vs \"\")");
+
+ let test = || Ok(ensure!(s as &'static str != s));
+ assert_err(
+ test,
+ "Condition failed: `s as &'static str != s` (\"\" vs \"\")",
+ );
+
+ let test = || Ok(ensure!(&s as &&'static str != &s));
+ assert_err(
+ test,
+ "Condition failed: `&s as &&'static str != &s` (\"\" vs \"\")",
+ );
+
+ let m: &mut str = Default::default();
+ let test = || Ok(ensure!(m as &mut str != s));
+ assert_err(
+ test,
+ "Condition failed: `m as &mut str != s` (\"\" vs \"\")",
+ );
+
+ let test = || Ok(ensure!(&m as &&mut str != &s));
+ assert_err(
+ test,
+ "Condition failed: `&m as &&mut str != &s` (\"\" vs \"\")",
+ );
+
+ let test = || Ok(ensure!(&m as &&'static mut str != &s));
+ assert_err(
+ test,
+ "Condition failed: `&m as &&'static mut str != &s` (\"\" vs \"\")",
+ );
+
+ let f = || {};
+ let test = || Ok(ensure!(f as fn() as usize * 0 != 0));
+ assert_err(
+ test,
+ "Condition failed: `f as fn() as usize * 0 != 0` (0 vs 0)",
+ );
+
+ let test = || Ok(ensure!(f as fn() -> () as usize * 0 != 0));
+ assert_err(
+ test,
+ "Condition failed: `f as fn() -> () as usize * 0 != 0` (0 vs 0)",
+ );
+
+ let test = || Ok(ensure!(f as for<'a> fn() as usize * 0 != 0));
+ assert_err(
+ test,
+ "Condition failed: `f as for<'a> fn() as usize * 0 != 0` (0 vs 0)",
+ );
+
+ let test = || Ok(ensure!(f as unsafe fn() as usize * 0 != 0));
+ assert_err(
+ test,
+ "Condition failed: `f as unsafe fn() as usize * 0 != 0` (0 vs 0)",
+ );
+
+ #[rustfmt::skip]
+ let test = || Ok(ensure!(f as extern "Rust" fn() as usize * 0 != 0));
+ assert_err(
+ test,
+ "Condition failed: `f as extern \"Rust\" fn() as usize * 0 != 0` (0 vs 0)",
+ );
+
+ extern "C" fn extern_fn() {}
+ #[rustfmt::skip]
+ let test = || Ok(ensure!(extern_fn as extern fn() as usize * 0 != 0));
+ assert_err(
+ test,
+ "Condition failed: `extern_fn as extern fn() as usize * 0 != 0` (0 vs 0)",
+ );
+
+ let f = || -> ! { panic!() };
+ let test = || Ok(ensure!(f as fn() -> ! as usize * 0 != 0));
+ assert_err(
+ test,
+ "Condition failed: `f as fn() -> ! as usize * 0 != 0` (0 vs 0)",
+ );
+
+ trait EqDebug<T>: PartialEq<T> + Debug {
+ type Assoc;
+ }
+
+ impl<S, T> EqDebug<T> for S
+ where
+ S: PartialEq<T> + Debug,
+ {
+ type Assoc = bool;
+ }
+
+ let test = || Ok(ensure!(&0 as &dyn EqDebug<i32, Assoc = bool> != &0));
+ assert_err(
+ test,
+ "Condition failed: `&0 as &dyn EqDebug<i32, Assoc = bool> != &0` (0 vs 0)",
+ );
+
+ let test = || {
+ Ok(ensure!(
+ PhantomData as PhantomData<<i32 as ToOwned>::Owned> != PhantomData
+ ))
+ };
+ assert_err(
+ test,
+ "Condition failed: `PhantomData as PhantomData<<i32 as ToOwned>::Owned> != PhantomData` (PhantomData vs PhantomData)",
+ );
+
+ macro_rules! int {
+ (...) => {
+ u8
+ };
+ }
+
+ let test = || Ok(ensure!(0 as int!(...) != 0));
+ assert_err(test, "Condition failed: `0 as int!(...) != 0` (0 vs 0)");
+
+ let test = || Ok(ensure!(0 as int![...] != 0));
+ assert_err(test, "Condition failed: `0 as int![...] != 0` (0 vs 0)");
+
+ let test = || Ok(ensure!(0 as int! {...} != 0));
+ assert_err(test, "Condition failed: `0 as int! { ... } != 0` (0 vs 0)");
+}
+
+#[test]
+fn test_pat() {
+ let test = || Ok(ensure!(if let ref mut _x @ 0 = 0 { 0 } else { 1 } == 1));
+ assert_err(
+ test,
+ "Condition failed: `if let ref mut _x @ 0 = 0 { 0 } else { 1 } == 1` (0 vs 1)",
+ );
+
+ let test = || Ok(ensure!(if let -1..=1 = 0 { 0 } else { 1 } == 1));
+ assert_err(
+ test,
+ "Condition failed: `if let -1..=1 = 0 { 0 } else { 1 } == 1` (0 vs 1)",
+ );
+
+ let test = || Ok(ensure!(if let &0 = &0 { 0 } else { 1 } == 1));
+ assert_err(
+ test,
+ "Condition failed: `if let &0 = &0 { 0 } else { 1 } == 1` (0 vs 1)",
+ );
+
+ let test = || Ok(ensure!(if let &&0 = &&0 { 0 } else { 1 } == 1));
+ assert_err(
+ test,
+ "Condition failed: `if let &&0 = &&0 { 0 } else { 1 } == 1` (0 vs 1)",
+ );
+
+ let test = || Ok(ensure!(if let &mut 0 = &mut 0 { 0 } else { 1 } == 1));
+ assert_err(
+ test,
+ "Condition failed: `if let &mut 0 = &mut 0 { 0 } else { 1 } == 1` (0 vs 1)",
+ );
+
+ let test = || Ok(ensure!(if let &&mut 0 = &&mut 0 { 0 } else { 1 } == 1));
+ assert_err(
+ test,
+ "Condition failed: `if let &&mut 0 = &&mut 0 { 0 } else { 1 } == 1` (0 vs 1)",
+ );
+
+ let test = || Ok(ensure!(if let (0, 1) = (0, 1) { 0 } else { 1 } == 1));
+ assert_err(
+ test,
+ "Condition failed: `if let (0, 1) = (0, 1) { 0 } else { 1 } == 1` (0 vs 1)",
+ );
+
+ let test = || Ok(ensure!(if let [0] = b"\0" { 0 } else { 1 } == 1));
+ assert_err(
+ test,
+ "Condition failed: `if let [0] = b\"\\0\" { 0 } else { 1 } == 1` (0 vs 1)",
+ );
+
+ let p = PhantomData::<u8>;
+ let test = || Ok(ensure!(if let P::<u8> {} = p { 0 } else { 1 } == 1));
+ assert_err(
+ test,
+ "Condition failed: `if let P::<u8> {} = p { 0 } else { 1 } == 1` (0 vs 1)",
+ );
+
+ let test = || Ok(ensure!(if let ::std::marker::PhantomData = p {} != ()));
+ assert_err(
+ test,
+ "Condition failed: `if let ::std::marker::PhantomData = p {} != ()` (() vs ())",
+ );
+
+ let test = || Ok(ensure!(if let <S as Trait>::V = 0 { 0 } else { 1 } == 1));
+ assert_err(
+ test,
+ "Condition failed: `if let <S as Trait>::V = 0 { 0 } else { 1 } == 1` (0 vs 1)",
+ );
+
+ let test = || Ok(ensure!(for _ in iter::once(()) {} != ()));
+ assert_err(
+ test,
+ "Condition failed: `for _ in iter::once(()) {} != ()` (() vs ())",
+ );
+
+ let test = || Ok(ensure!(if let stringify!(x) = "x" { 0 } else { 1 } == 1));
+ assert_err(
+ test,
+ "Condition failed: `if let stringify!(x) = \"x\" { 0 } else { 1 } == 1` (0 vs 1)",
+ );
+}
diff --git a/vendor/anyhow/tests/test_ffi.rs b/vendor/anyhow/tests/test_ffi.rs
new file mode 100644
index 000000000..0321fc1b0
--- /dev/null
+++ b/vendor/anyhow/tests/test_ffi.rs
@@ -0,0 +1,18 @@
+#![deny(improper_ctypes, improper_ctypes_definitions)]
+
+use anyhow::anyhow;
+
+#[no_mangle]
+pub extern "C" fn anyhow1(err: anyhow::Error) {
+ println!("{:?}", err);
+}
+
+#[no_mangle]
+pub extern "C" fn anyhow2(err: &mut Option<anyhow::Error>) {
+ *err = Some(anyhow!("ffi error"));
+}
+
+#[no_mangle]
+pub extern "C" fn anyhow3() -> Option<anyhow::Error> {
+ Some(anyhow!("ffi error"))
+}
diff --git a/vendor/anyhow/tests/test_fmt.rs b/vendor/anyhow/tests/test_fmt.rs
new file mode 100644
index 000000000..cc4929197
--- /dev/null
+++ b/vendor/anyhow/tests/test_fmt.rs
@@ -0,0 +1,94 @@
+use anyhow::{bail, Context, Result};
+use std::io;
+
+fn f() -> Result<()> {
+ bail!(io::Error::new(io::ErrorKind::PermissionDenied, "oh no!"));
+}
+
+fn g() -> Result<()> {
+ f().context("f failed")
+}
+
+fn h() -> Result<()> {
+ g().context("g failed")
+}
+
+const EXPECTED_ALTDISPLAY_F: &str = "oh no!";
+
+const EXPECTED_ALTDISPLAY_G: &str = "f failed: oh no!";
+
+const EXPECTED_ALTDISPLAY_H: &str = "g failed: f failed: oh no!";
+
+const EXPECTED_DEBUG_F: &str = "oh no!";
+
+const EXPECTED_DEBUG_G: &str = "\
+f failed
+
+Caused by:
+ oh no!\
+";
+
+const EXPECTED_DEBUG_H: &str = "\
+g failed
+
+Caused by:
+ 0: f failed
+ 1: oh no!\
+";
+
+const EXPECTED_ALTDEBUG_F: &str = "\
+Custom {
+ kind: PermissionDenied,
+ error: \"oh no!\",
+}\
+";
+
+const EXPECTED_ALTDEBUG_G: &str = "\
+Error {
+ context: \"f failed\",
+ source: Custom {
+ kind: PermissionDenied,
+ error: \"oh no!\",
+ },
+}\
+";
+
+const EXPECTED_ALTDEBUG_H: &str = "\
+Error {
+ context: \"g failed\",
+ source: Error {
+ context: \"f failed\",
+ source: Custom {
+ kind: PermissionDenied,
+ error: \"oh no!\",
+ },
+ },
+}\
+";
+
+#[test]
+fn test_display() {
+ assert_eq!("g failed", h().unwrap_err().to_string());
+}
+
+#[test]
+fn test_altdisplay() {
+ assert_eq!(EXPECTED_ALTDISPLAY_F, format!("{:#}", f().unwrap_err()));
+ assert_eq!(EXPECTED_ALTDISPLAY_G, format!("{:#}", g().unwrap_err()));
+ assert_eq!(EXPECTED_ALTDISPLAY_H, format!("{:#}", h().unwrap_err()));
+}
+
+#[test]
+#[cfg_attr(not(backtrace), ignore)]
+fn test_debug() {
+ assert_eq!(EXPECTED_DEBUG_F, format!("{:?}", f().unwrap_err()));
+ assert_eq!(EXPECTED_DEBUG_G, format!("{:?}", g().unwrap_err()));
+ assert_eq!(EXPECTED_DEBUG_H, format!("{:?}", h().unwrap_err()));
+}
+
+#[test]
+fn test_altdebug() {
+ assert_eq!(EXPECTED_ALTDEBUG_F, format!("{:#?}", f().unwrap_err()));
+ assert_eq!(EXPECTED_ALTDEBUG_G, format!("{:#?}", g().unwrap_err()));
+ assert_eq!(EXPECTED_ALTDEBUG_H, format!("{:#?}", h().unwrap_err()));
+}
diff --git a/vendor/anyhow/tests/test_macros.rs b/vendor/anyhow/tests/test_macros.rs
new file mode 100644
index 000000000..a3342ab77
--- /dev/null
+++ b/vendor/anyhow/tests/test_macros.rs
@@ -0,0 +1,80 @@
+#![allow(
+ clippy::assertions_on_result_states,
+ clippy::eq_op,
+ clippy::items_after_statements,
+ clippy::needless_pass_by_value,
+ clippy::shadow_unrelated,
+ clippy::wildcard_imports
+)]
+
+mod common;
+
+use self::common::*;
+use anyhow::{anyhow, ensure};
+use std::cell::Cell;
+use std::future;
+
+#[test]
+fn test_messages() {
+ assert_eq!("oh no!", bail_literal().unwrap_err().to_string());
+ assert_eq!("oh no!", bail_fmt().unwrap_err().to_string());
+ assert_eq!("oh no!", bail_error().unwrap_err().to_string());
+}
+
+#[test]
+fn test_ensure() {
+ let f = || {
+ ensure!(1 + 1 == 2, "This is correct");
+ Ok(())
+ };
+ assert!(f().is_ok());
+
+ let v = 1;
+ let f = || {
+ ensure!(v + v == 2, "This is correct, v: {}", v);
+ Ok(())
+ };
+ assert!(f().is_ok());
+
+ let f = || {
+ ensure!(v + v == 1, "This is not correct, v: {}", v);
+ Ok(())
+ };
+ assert!(f().is_err());
+
+ let f = || {
+ ensure!(v + v == 1);
+ Ok(())
+ };
+ assert_eq!(
+ f().unwrap_err().to_string(),
+ "Condition failed: `v + v == 1` (2 vs 1)",
+ );
+}
+
+#[test]
+fn test_temporaries() {
+ fn require_send_sync(_: impl Send + Sync) {}
+
+ require_send_sync(async {
+ // If anyhow hasn't dropped any temporary format_args it creates by the
+ // time it's done evaluating, those will stick around until the
+ // semicolon, which is on the other side of the await point, making the
+ // enclosing future non-Send.
+ future::ready(anyhow!("...")).await;
+ });
+
+ fn message(cell: Cell<&str>) -> &str {
+ cell.get()
+ }
+
+ require_send_sync(async {
+ future::ready(anyhow!(message(Cell::new("...")))).await;
+ });
+}
+
+#[test]
+fn test_brace_escape() {
+ let err = anyhow!("unterminated ${{..}} expression");
+ assert_eq!("unterminated ${..} expression", err.to_string());
+}
diff --git a/vendor/anyhow/tests/test_repr.rs b/vendor/anyhow/tests/test_repr.rs
new file mode 100644
index 000000000..72f5002ae
--- /dev/null
+++ b/vendor/anyhow/tests/test_repr.rs
@@ -0,0 +1,29 @@
+mod drop;
+
+use self::drop::{DetectDrop, Flag};
+use anyhow::Error;
+use std::marker::Unpin;
+use std::mem;
+
+#[test]
+fn test_error_size() {
+ assert_eq!(mem::size_of::<Error>(), mem::size_of::<usize>());
+}
+
+#[test]
+fn test_null_pointer_optimization() {
+ assert_eq!(mem::size_of::<Result<(), Error>>(), mem::size_of::<usize>());
+}
+
+#[test]
+fn test_autotraits() {
+ fn assert<E: Unpin + Send + Sync + 'static>() {}
+ assert::<Error>();
+}
+
+#[test]
+fn test_drop() {
+ let has_dropped = Flag::new();
+ drop(Error::new(DetectDrop::new(&has_dropped)));
+ assert!(has_dropped.get());
+}
diff --git a/vendor/anyhow/tests/test_source.rs b/vendor/anyhow/tests/test_source.rs
new file mode 100644
index 000000000..018267d31
--- /dev/null
+++ b/vendor/anyhow/tests/test_source.rs
@@ -0,0 +1,62 @@
+use anyhow::anyhow;
+use std::error::Error as StdError;
+use std::fmt::{self, Display};
+use std::io;
+
+#[derive(Debug)]
+enum TestError {
+ Io(io::Error),
+}
+
+impl Display for TestError {
+ fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
+ match self {
+ TestError::Io(e) => Display::fmt(e, formatter),
+ }
+ }
+}
+
+impl StdError for TestError {
+ fn source(&self) -> Option<&(dyn StdError + 'static)> {
+ match self {
+ TestError::Io(io) => Some(io),
+ }
+ }
+}
+
+#[test]
+fn test_literal_source() {
+ let error = anyhow!("oh no!");
+ assert!(error.source().is_none());
+}
+
+#[test]
+fn test_variable_source() {
+ let msg = "oh no!";
+ let error = anyhow!(msg);
+ assert!(error.source().is_none());
+
+ let msg = msg.to_owned();
+ let error = anyhow!(msg);
+ assert!(error.source().is_none());
+}
+
+#[test]
+fn test_fmt_source() {
+ let error = anyhow!("{} {}!", "oh", "no");
+ assert!(error.source().is_none());
+}
+
+#[test]
+fn test_io_source() {
+ let io = io::Error::new(io::ErrorKind::Other, "oh no!");
+ let error = anyhow!(TestError::Io(io));
+ assert_eq!("oh no!", error.source().unwrap().to_string());
+}
+
+#[test]
+fn test_anyhow_from_anyhow() {
+ let error = anyhow!("oh no!").context("context");
+ let error = anyhow!(error);
+ assert_eq!("oh no!", error.source().unwrap().to_string());
+}
diff --git a/vendor/anyhow/tests/ui/chained-comparison.rs b/vendor/anyhow/tests/ui/chained-comparison.rs
new file mode 100644
index 000000000..4521b51c8
--- /dev/null
+++ b/vendor/anyhow/tests/ui/chained-comparison.rs
@@ -0,0 +1,8 @@
+use anyhow::{ensure, Result};
+
+fn main() -> Result<()> {
+ // `ensure!` must not partition this into `(false) == (false == true)`
+ // because Rust doesn't ordinarily allow this form of expression.
+ ensure!(false == false == true);
+ Ok(())
+}
diff --git a/vendor/anyhow/tests/ui/chained-comparison.stderr b/vendor/anyhow/tests/ui/chained-comparison.stderr
new file mode 100644
index 000000000..2a4c66508
--- /dev/null
+++ b/vendor/anyhow/tests/ui/chained-comparison.stderr
@@ -0,0 +1,10 @@
+error: comparison operators cannot be chained
+ --> tests/ui/chained-comparison.rs:6:19
+ |
+6 | ensure!(false == false == true);
+ | ^^ ^^
+ |
+help: split the comparison into two
+ |
+6 | ensure!(false == false && false == true);
+ | ++++++++
diff --git a/vendor/anyhow/tests/ui/empty-ensure.rs b/vendor/anyhow/tests/ui/empty-ensure.rs
new file mode 100644
index 000000000..139b743bb
--- /dev/null
+++ b/vendor/anyhow/tests/ui/empty-ensure.rs
@@ -0,0 +1,6 @@
+use anyhow::{ensure, Result};
+
+fn main() -> Result<()> {
+ ensure!();
+ Ok(())
+}
diff --git a/vendor/anyhow/tests/ui/empty-ensure.stderr b/vendor/anyhow/tests/ui/empty-ensure.stderr
new file mode 100644
index 000000000..91e0a9803
--- /dev/null
+++ b/vendor/anyhow/tests/ui/empty-ensure.stderr
@@ -0,0 +1,7 @@
+error: unexpected end of macro invocation
+ --> tests/ui/empty-ensure.rs:4:5
+ |
+4 | ensure!();
+ | ^^^^^^^^^ missing tokens in macro arguments
+ |
+ = note: this error originates in the macro `$crate::__parse_ensure` which comes from the expansion of the macro `ensure` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/vendor/anyhow/tests/ui/must-use.rs b/vendor/anyhow/tests/ui/must-use.rs
new file mode 100644
index 000000000..ea4e58f55
--- /dev/null
+++ b/vendor/anyhow/tests/ui/must-use.rs
@@ -0,0 +1,11 @@
+#![deny(unused_must_use)]
+
+use anyhow::anyhow;
+
+fn main() -> anyhow::Result<()> {
+ if true {
+ // meant to write bail!
+ anyhow!("it failed");
+ }
+ Ok(())
+}
diff --git a/vendor/anyhow/tests/ui/must-use.stderr b/vendor/anyhow/tests/ui/must-use.stderr
new file mode 100644
index 000000000..e9ee24b09
--- /dev/null
+++ b/vendor/anyhow/tests/ui/must-use.stderr
@@ -0,0 +1,12 @@
+error: unused return value of `anyhow::private::must_use` that must be used
+ --> tests/ui/must-use.rs:8:9
+ |
+8 | anyhow!("it failed");
+ | ^^^^^^^^^^^^^^^^^^^^
+ |
+note: the lint level is defined here
+ --> tests/ui/must-use.rs:1:9
+ |
+1 | #![deny(unused_must_use)]
+ | ^^^^^^^^^^^^^^^
+ = note: this error originates in the macro `anyhow` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/vendor/anyhow/tests/ui/no-impl.rs b/vendor/anyhow/tests/ui/no-impl.rs
new file mode 100644
index 000000000..d2e89afc1
--- /dev/null
+++ b/vendor/anyhow/tests/ui/no-impl.rs
@@ -0,0 +1,8 @@
+use anyhow::anyhow;
+
+#[derive(Debug)]
+struct Error;
+
+fn main() {
+ let _ = anyhow!(Error);
+}
diff --git a/vendor/anyhow/tests/ui/no-impl.stderr b/vendor/anyhow/tests/ui/no-impl.stderr
new file mode 100644
index 000000000..7c5ec503f
--- /dev/null
+++ b/vendor/anyhow/tests/ui/no-impl.stderr
@@ -0,0 +1,31 @@
+error[E0599]: the method `anyhow_kind` exists for reference `&Error`, but its trait bounds were not satisfied
+ --> tests/ui/no-impl.rs:7:13
+ |
+4 | struct Error;
+ | ------------
+ | |
+ | doesn't satisfy `Error: Into<anyhow::Error>`
+ | doesn't satisfy `Error: anyhow::kind::TraitKind`
+ | doesn't satisfy `Error: std::fmt::Display`
+...
+7 | let _ = anyhow!(Error);
+ | ^^^^^^^^^^^^^^ method cannot be called on `&Error` due to unsatisfied trait bounds
+ |
+ = note: the following trait bounds were not satisfied:
+ `Error: Into<anyhow::Error>`
+ which is required by `Error: anyhow::kind::TraitKind`
+ `Error: std::fmt::Display`
+ which is required by `&Error: anyhow::kind::AdhocKind`
+ `&Error: Into<anyhow::Error>`
+ which is required by `&Error: anyhow::kind::TraitKind`
+note: the following traits must be implemented
+ --> $RUST/core/src/convert/mod.rs
+ |
+ | pub trait Into<T>: Sized {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ ::: $RUST/core/src/fmt/mod.rs
+ |
+ | pub trait Display {
+ | ^^^^^^^^^^^^^^^^^
+ = note: this error originates in the macro `anyhow` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/vendor/anyhow/tests/ui/temporary-value.rs b/vendor/anyhow/tests/ui/temporary-value.rs
new file mode 100644
index 000000000..803809b23
--- /dev/null
+++ b/vendor/anyhow/tests/ui/temporary-value.rs
@@ -0,0 +1,5 @@
+use anyhow::anyhow;
+
+fn main() {
+ let _ = anyhow!(&String::new());
+}
diff --git a/vendor/anyhow/tests/ui/temporary-value.stderr b/vendor/anyhow/tests/ui/temporary-value.stderr
new file mode 100644
index 000000000..4e4115fc3
--- /dev/null
+++ b/vendor/anyhow/tests/ui/temporary-value.stderr
@@ -0,0 +1,9 @@
+error[E0716]: temporary value dropped while borrowed
+ --> tests/ui/temporary-value.rs:4:22
+ |
+4 | let _ = anyhow!(&String::new());
+ | ---------^^^^^^^^^^^^^-
+ | | |
+ | | creates a temporary which is freed while still in use
+ | temporary value is freed at the end of this statement
+ | argument requires that borrow lasts for `'static`
diff --git a/vendor/anyhow/tests/ui/wrong-interpolation.rs b/vendor/anyhow/tests/ui/wrong-interpolation.rs
new file mode 100644
index 000000000..b870ca713
--- /dev/null
+++ b/vendor/anyhow/tests/ui/wrong-interpolation.rs
@@ -0,0 +1,5 @@
+use anyhow::{bail, Result};
+
+fn main() -> Result<()> {
+ bail!("{} not found");
+}
diff --git a/vendor/anyhow/tests/ui/wrong-interpolation.stderr b/vendor/anyhow/tests/ui/wrong-interpolation.stderr
new file mode 100644
index 000000000..55a296411
--- /dev/null
+++ b/vendor/anyhow/tests/ui/wrong-interpolation.stderr
@@ -0,0 +1,5 @@
+error: 1 positional argument in format string, but no arguments were given
+ --> tests/ui/wrong-interpolation.rs:4:12
+ |
+4 | bail!("{} not found");
+ | ^^