From d9ed0fba49d6ac3f804d41d0dc3fdff4f0d87671 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 12 Oct 2019 16:14:07 -0700 Subject: [PATCH] Add test for optional backtrace --- tests/test_option.rs | 108 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 85 insertions(+), 23 deletions(-) diff --git a/tests/test_option.rs b/tests/test_option.rs index 936f3e6..945e850 100644 --- a/tests/test_option.rs +++ b/tests/test_option.rs @@ -4,36 +4,98 @@ use std::backtrace::Backtrace; use thiserror::Error; -#[derive(Error, Debug)] -#[error("...")] -pub struct OptSourceNoBacktraceStruct { - #[source] - source: Option, -} +pub mod structs { + use super::*; -#[derive(Error, Debug)] -#[error("...")] -pub struct OptSourceAlwaysBacktraceStruct { - #[source] - source: Option, - backtrace: Backtrace, -} - -#[derive(Error, Debug)] -pub enum OptSourceNoBacktraceEnum { + #[derive(Error, Debug)] #[error("...")] - Test { + pub struct OptSourceNoBacktrace { #[source] source: Option, - }, -} + } -#[derive(Error, Debug)] -pub enum OptSourceAlwaysBacktraceEnum { + #[derive(Error, Debug)] #[error("...")] - Test { + pub struct OptSourceAlwaysBacktrace { #[source] source: Option, backtrace: Backtrace, - }, + } + + #[derive(Error, Debug)] + #[error("...")] + pub struct NoSourceOptBacktrace { + #[backtrace] + backtrace: Option, + } + + #[derive(Error, Debug)] + #[error("...")] + pub struct AlwaysSourceOptBacktrace { + source: anyhow::Error, + #[backtrace] + backtrace: Option, + } + + #[derive(Error, Debug)] + #[error("...")] + pub struct OptSourceOptBacktrace { + #[source] + source: Option, + #[backtrace] + backtrace: Option, + } +} + +pub mod enums { + use super::*; + + #[derive(Error, Debug)] + pub enum OptSourceNoBacktrace { + #[error("...")] + Test { + #[source] + source: Option, + }, + } + + #[derive(Error, Debug)] + pub enum OptSourceAlwaysBacktrace { + #[error("...")] + Test { + #[source] + source: Option, + backtrace: Backtrace, + }, + } + + #[derive(Error, Debug)] + pub enum NoSourceOptBacktrace { + #[error("...")] + Test { + #[backtrace] + backtrace: Option, + }, + } + + #[derive(Error, Debug)] + pub enum AlwaysSourceOptBacktrace { + #[error("...")] + Test { + source: anyhow::Error, + #[backtrace] + backtrace: Option, + }, + } + + #[derive(Error, Debug)] + pub enum OptSourceOptBacktrace { + #[error("...")] + Test { + #[source] + source: Option, + #[backtrace] + backtrace: Option, + }, + } }