| 1 |
#![warn(rust_2018_idioms)] |
| 2 |
#![cfg(all(feature = "full", not(target_os = "wasi")))] |
| 3 |
#![cfg(panic = "unwind")] |
| 4 |
|
| 5 |
use futures::future; |
| 6 |
use std::error::Error; |
| 7 |
use tokio::runtime::Builder; |
| 8 |
use tokio::task::{self, block_in_place}; |
| 9 |
|
| 10 |
mod support { |
| 11 |
pub mod panic; |
| 12 |
} |
| 13 |
use support::panic::test_panic; |
| 14 |
|
| 15 |
#[test] |
| 16 |
fn block_in_place_panic_caller() -> Result<(), Box<dyn Error>> { |
| 17 |
let panic_location_file = test_panic(|| { |
| 18 |
let rt = Builder::new_current_thread().enable_all().build().unwrap(); |
| 19 |
rt.block_on(async { |
| 20 |
block_in_place(|| {}); |
| 21 |
}); |
| 22 |
}); |
| 23 |
|
| 24 |
// The panic location should be in this file |
| 25 |
assert_eq!(&panic_location_file.unwrap(), file!()); |
| 26 |
|
| 27 |
Ok(()) |
| 28 |
} |
| 29 |
|
| 30 |
#[test] |
| 31 |
fn local_set_spawn_local_panic_caller() -> Result<(), Box<dyn Error>> { |
| 32 |
let panic_location_file = test_panic(|| { |
| 33 |
let _local = task::LocalSet::new(); |
| 34 |
|
| 35 |
task::spawn_local(async {}); |
| 36 |
}); |
| 37 |
|
| 38 |
// The panic location should be in this file |
| 39 |
assert_eq!(&panic_location_file.unwrap(), file!()); |
| 40 |
|
| 41 |
Ok(()) |
| 42 |
} |
| 43 |
|
| 44 |
#[test] |
| 45 |
fn local_set_block_on_panic_caller() -> Result<(), Box<dyn Error>> { |
| 46 |
let panic_location_file = test_panic(|| { |
| 47 |
let rt = Builder::new_current_thread().enable_all().build().unwrap(); |
| 48 |
let local = task::LocalSet::new(); |
| 49 |
|
| 50 |
rt.block_on(async { |
| 51 |
local.block_on(&rt, future::pending::<()>()); |
| 52 |
}); |
| 53 |
}); |
| 54 |
|
| 55 |
// The panic location should be in this file |
| 56 |
assert_eq!(&panic_location_file.unwrap(), file!()); |
| 57 |
|
| 58 |
Ok(()) |
| 59 |
} |
| 60 |
|
| 61 |
#[test] |
| 62 |
fn spawn_panic_caller() -> Result<(), Box<dyn Error>> { |
| 63 |
let panic_location_file = test_panic(|| { |
| 64 |
tokio::spawn(future::pending::<()>()); |
| 65 |
}); |
| 66 |
|
| 67 |
// The panic location should be in this file |
| 68 |
assert_eq!(&panic_location_file.unwrap(), file!()); |
| 69 |
|
| 70 |
Ok(()) |
| 71 |
} |
| 72 |
|
| 73 |
#[test] |
| 74 |
fn local_key_sync_scope_panic_caller() -> Result<(), Box<dyn Error>> { |
| 75 |
tokio::task_local! { |
| 76 |
static NUMBER: u32; |
| 77 |
} |
| 78 |
|
| 79 |
let panic_location_file = test_panic(|| { |
| 80 |
NUMBER.sync_scope(1, || { |
| 81 |
NUMBER.with(|_| { |
| 82 |
NUMBER.sync_scope(1, || {}); |
| 83 |
}); |
| 84 |
}); |
| 85 |
}); |
| 86 |
|
| 87 |
// The panic location should be in this file |
| 88 |
assert_eq!(&panic_location_file.unwrap(), file!()); |
| 89 |
|
| 90 |
Ok(()) |
| 91 |
} |
| 92 |
|
| 93 |
#[test] |
| 94 |
fn local_key_with_panic_caller() -> Result<(), Box<dyn Error>> { |
| 95 |
tokio::task_local! { |
| 96 |
static NUMBER: u32; |
| 97 |
} |
| 98 |
|
| 99 |
let panic_location_file = test_panic(|| { |
| 100 |
NUMBER.with(|_| {}); |
| 101 |
}); |
| 102 |
|
| 103 |
// The panic location should be in this file |
| 104 |
assert_eq!(&panic_location_file.unwrap(), file!()); |
| 105 |
|
| 106 |
Ok(()) |
| 107 |
} |
| 108 |
|
| 109 |
#[test] |
| 110 |
fn local_key_get_panic_caller() -> Result<(), Box<dyn Error>> { |
| 111 |
tokio::task_local! { |
| 112 |
static NUMBER: u32; |
| 113 |
} |
| 114 |
|
| 115 |
let panic_location_file = test_panic(|| { |
| 116 |
NUMBER.get(); |
| 117 |
}); |
| 118 |
|
| 119 |
// The panic location should be in this file |
| 120 |
assert_eq!(&panic_location_file.unwrap(), file!()); |
| 121 |
|
| 122 |
Ok(()) |
| 123 |
} |