| 1 |
#![cfg_attr(not(feature = "enabled"), allow(dead_code))] |
| 2 |
|
| 3 |
failspot::failspot_name! { |
| 4 |
pub enum FailSpotName { |
| 5 |
One, |
| 6 |
Two, |
| 7 |
Three, |
| 8 |
Four, |
| 9 |
} |
| 10 |
} |
| 11 |
|
| 12 |
mod inner { |
| 13 |
failspot::failspot_name! { |
| 14 |
pub enum FailSpotName2 { |
| 15 |
Four, |
| 16 |
Five, |
| 17 |
Six, |
| 18 |
Seven, |
| 19 |
} |
| 20 |
} |
| 21 |
} |
| 22 |
|
| 23 |
fn stop_process_or_fail() -> Result<(), Box<dyn std::error::Error>> { |
| 24 |
failspot::failspot!(One bail(std::io::Error::other("fail"))); |
| 25 |
failspot::failspot!(<inner::FailSpotName2>::Four bail(std::io::Error::other("fail"))); |
| 26 |
Ok(()) |
| 27 |
} |
| 28 |
|
| 29 |
fn fill_missing_auxv_or_panic() { |
| 30 |
failspot::failspot!(Two panic!()); |
| 31 |
failspot::failspot!(<inner::FailSpotName2>::Five panic!()); |
| 32 |
} |
| 33 |
|
| 34 |
fn get_thread_name_or_none() -> Option<String> { |
| 35 |
if failspot::failspot!(Three) { |
| 36 |
return None; |
| 37 |
} |
| 38 |
if failspot::failspot!(<inner::FailSpotName2>::Six) { |
| 39 |
return None; |
| 40 |
} |
| 41 |
Some("mythread".to_string()) |
| 42 |
} |
| 43 |
|
| 44 |
fn common() -> Result<Option<String>, Box<dyn std::error::Error>> { |
| 45 |
stop_process_or_fail()?; |
| 46 |
fill_missing_auxv_or_panic(); |
| 47 |
let name = get_thread_name_or_none(); |
| 48 |
|
| 49 |
let name = failspot::failspot!(if Four { |
| 50 |
name.map(|_| "deleted".to_string()) |
| 51 |
} else { |
| 52 |
name |
| 53 |
}); |
| 54 |
|
| 55 |
let name = name.map(|name| { |
| 56 |
failspot::failspot!(if <inner::FailSpotName2>::Seven { |
| 57 |
"deleted".to_string() |
| 58 |
} else { |
| 59 |
name |
| 60 |
}) |
| 61 |
}); |
| 62 |
|
| 63 |
Ok(name) |
| 64 |
} |
| 65 |
|
| 66 |
#[cfg(feature = "enabled")] |
| 67 |
#[test] |
| 68 |
fn no_fails() -> Result<(), Box<dyn std::error::Error>> { |
| 69 |
let _client = FailSpotName::testing_client(); |
| 70 |
let _client2 = inner::FailSpotName2::testing_client(); |
| 71 |
let thread_name = common()?; |
| 72 |
assert_eq!(thread_name.as_deref(), Some("mythread")); |
| 73 |
Ok(()) |
| 74 |
} |
| 75 |
|
| 76 |
#[cfg(feature = "enabled")] |
| 77 |
#[test] |
| 78 |
#[should_panic] |
| 79 |
fn panic_fail() { |
| 80 |
let mut client = FailSpotName::testing_client(); |
| 81 |
let _client2 = inner::FailSpotName2::testing_client(); |
| 82 |
client.set_enabled(FailSpotName::Two, true); |
| 83 |
let _ = common(); |
| 84 |
} |
| 85 |
|
| 86 |
#[cfg(feature = "enabled")] |
| 87 |
#[test] |
| 88 |
#[should_panic] |
| 89 |
fn panic_fail2() { |
| 90 |
let mut _client = FailSpotName::testing_client(); |
| 91 |
let mut client2 = inner::FailSpotName2::testing_client(); |
| 92 |
client2.set_enabled(inner::FailSpotName2::Five, true); |
| 93 |
let _ = common(); |
| 94 |
} |
| 95 |
|
| 96 |
#[cfg(feature = "enabled")] |
| 97 |
#[test] |
| 98 |
fn test_error() { |
| 99 |
let mut client = FailSpotName::testing_client(); |
| 100 |
let mut _client2 = inner::FailSpotName2::testing_client(); |
| 101 |
client.set_enabled(FailSpotName::One, true); |
| 102 |
common().unwrap_err(); |
| 103 |
} |
| 104 |
|
| 105 |
#[cfg(feature = "enabled")] |
| 106 |
#[test] |
| 107 |
fn test_error2() { |
| 108 |
let mut _client = FailSpotName::testing_client(); |
| 109 |
let mut client2 = inner::FailSpotName2::testing_client(); |
| 110 |
client2.set_enabled(inner::FailSpotName2::Four, true); |
| 111 |
common().unwrap_err(); |
| 112 |
} |
| 113 |
|
| 114 |
#[cfg(feature = "enabled")] |
| 115 |
#[test] |
| 116 |
fn expression_fail() { |
| 117 |
let mut client = FailSpotName::testing_client(); |
| 118 |
let mut _client2 = inner::FailSpotName2::testing_client(); |
| 119 |
client.set_enabled(FailSpotName::Three, true); |
| 120 |
let thread_name = common().unwrap(); |
| 121 |
assert!(thread_name.is_none()); |
| 122 |
} |
| 123 |
|
| 124 |
#[cfg(feature = "enabled")] |
| 125 |
#[test] |
| 126 |
fn expression_fail2() { |
| 127 |
let mut _client = FailSpotName::testing_client(); |
| 128 |
let mut client2 = inner::FailSpotName2::testing_client(); |
| 129 |
client2.set_enabled(inner::FailSpotName2::Six, true); |
| 130 |
let thread_name = common().unwrap(); |
| 131 |
assert!(thread_name.is_none()); |
| 132 |
} |
| 133 |
|
| 134 |
#[cfg(feature = "enabled")] |
| 135 |
#[test] |
| 136 |
fn if_statement_fail() { |
| 137 |
let mut client = FailSpotName::testing_client(); |
| 138 |
let mut _client2 = inner::FailSpotName2::testing_client(); |
| 139 |
client.set_enabled(FailSpotName::Four, true); |
| 140 |
let thread_name = common().unwrap(); |
| 141 |
assert!(thread_name.as_deref() == Some("deleted")); |
| 142 |
} |
| 143 |
|
| 144 |
#[cfg(feature = "enabled")] |
| 145 |
#[test] |
| 146 |
fn if_statement_fail2() { |
| 147 |
let mut _client = FailSpotName::testing_client(); |
| 148 |
let mut client2 = inner::FailSpotName2::testing_client(); |
| 149 |
client2.set_enabled(inner::FailSpotName2::Seven, true); |
| 150 |
let thread_name = common().unwrap(); |
| 151 |
assert!(thread_name.as_deref() == Some("deleted")); |
| 152 |
} |