move thread-panic tests to their own file; test getting the thread name
This commit is contained in:
parent
be5da3a4aa
commit
8deb651603
@ -45,23 +45,6 @@ fn create_move_out() {
|
||||
assert_eq!(result.len(), 6);
|
||||
}
|
||||
|
||||
fn panic() {
|
||||
let result = thread::spawn(|| panic!("Hello!")).join().unwrap_err();
|
||||
let msg = result.downcast_ref::<&'static str>().unwrap();
|
||||
assert_eq!(*msg, "Hello!");
|
||||
}
|
||||
|
||||
fn panic_named() {
|
||||
thread::Builder::new()
|
||||
.name("childthread".to_string())
|
||||
.spawn(move || {
|
||||
panic!("Hello, world!");
|
||||
})
|
||||
.unwrap()
|
||||
.join()
|
||||
.unwrap_err();
|
||||
}
|
||||
|
||||
// This is not a data race!
|
||||
fn shared_readonly() {
|
||||
use std::sync::Arc;
|
||||
@ -89,6 +72,4 @@ fn main() {
|
||||
create_move_in();
|
||||
create_move_out();
|
||||
shared_readonly();
|
||||
panic();
|
||||
panic_named();
|
||||
}
|
||||
|
@ -1,5 +0,0 @@
|
||||
thread '<unnamed>' panicked at $DIR/simple.rs:LL:CC:
|
||||
Hello!
|
||||
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
|
||||
thread 'childthread' panicked at $DIR/simple.rs:LL:CC:
|
||||
Hello, world!
|
21
src/tools/miri/tests/pass/concurrency/thread_name.rs
Normal file
21
src/tools/miri/tests/pass/concurrency/thread_name.rs
Normal file
@ -0,0 +1,21 @@
|
||||
use std::thread;
|
||||
|
||||
fn main() {
|
||||
// When we have not set the name...
|
||||
thread::spawn(|| {
|
||||
assert!(thread::current().name().is_none());
|
||||
});
|
||||
|
||||
// ... and when we have set it.
|
||||
thread::Builder::new()
|
||||
.name("childthread".to_string())
|
||||
.spawn(move || {
|
||||
assert_eq!(thread::current().name().unwrap(), "childthread");
|
||||
})
|
||||
.unwrap()
|
||||
.join()
|
||||
.unwrap();
|
||||
|
||||
// Also check main thread name.
|
||||
assert_eq!(thread::current().name().unwrap(), "main");
|
||||
}
|
25
src/tools/miri/tests/pass/panic/thread_panic.rs
Normal file
25
src/tools/miri/tests/pass/panic/thread_panic.rs
Normal file
@ -0,0 +1,25 @@
|
||||
//! Panicking in other threads.
|
||||
|
||||
use std::thread;
|
||||
|
||||
fn panic() {
|
||||
let result = thread::spawn(|| panic!("Hello!")).join().unwrap_err();
|
||||
let msg = result.downcast_ref::<&'static str>().unwrap();
|
||||
assert_eq!(*msg, "Hello!");
|
||||
}
|
||||
|
||||
fn panic_named() {
|
||||
thread::Builder::new()
|
||||
.name("childthread".to_string())
|
||||
.spawn(move || {
|
||||
panic!("Hello, world!");
|
||||
})
|
||||
.unwrap()
|
||||
.join()
|
||||
.unwrap_err();
|
||||
}
|
||||
|
||||
fn main() {
|
||||
panic();
|
||||
panic_named();
|
||||
}
|
5
src/tools/miri/tests/pass/panic/thread_panic.stderr
Normal file
5
src/tools/miri/tests/pass/panic/thread_panic.stderr
Normal file
@ -0,0 +1,5 @@
|
||||
thread '<unnamed>' panicked at $DIR/thread_panic.rs:LL:CC:
|
||||
Hello!
|
||||
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
|
||||
thread 'childthread' panicked at $DIR/thread_panic.rs:LL:CC:
|
||||
Hello, world!
|
Loading…
x
Reference in New Issue
Block a user