Skip to content

Commit afa39fa

Browse files
committed
move thread-panic tests to their own file; test getting the thread name
1 parent 9272474 commit afa39fa

File tree

5 files changed

+51
-24
lines changed

5 files changed

+51
-24
lines changed

tests/pass/concurrency/simple.rs

-19
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,6 @@ fn create_move_out() {
4545
assert_eq!(result.len(), 6);
4646
}
4747

48-
fn panic() {
49-
let result = thread::spawn(|| panic!("Hello!")).join().unwrap_err();
50-
let msg = result.downcast_ref::<&'static str>().unwrap();
51-
assert_eq!(*msg, "Hello!");
52-
}
53-
54-
fn panic_named() {
55-
thread::Builder::new()
56-
.name("childthread".to_string())
57-
.spawn(move || {
58-
panic!("Hello, world!");
59-
})
60-
.unwrap()
61-
.join()
62-
.unwrap_err();
63-
}
64-
6548
// This is not a data race!
6649
fn shared_readonly() {
6750
use std::sync::Arc;
@@ -89,6 +72,4 @@ fn main() {
8972
create_move_in();
9073
create_move_out();
9174
shared_readonly();
92-
panic();
93-
panic_named();
9475
}

tests/pass/concurrency/simple.stderr

-5
This file was deleted.

tests/pass/concurrency/thread_name.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use std::thread;
2+
3+
fn main() {
4+
// When we have not set the name...
5+
thread::spawn(|| {
6+
assert!(thread::current().name().is_none());
7+
});
8+
9+
// ... and when we have set it.
10+
thread::Builder::new()
11+
.name("childthread".to_string())
12+
.spawn(move || {
13+
assert_eq!(thread::current().name().unwrap(), "childthread");
14+
})
15+
.unwrap()
16+
.join()
17+
.unwrap();
18+
19+
// Also check main thread name.
20+
assert_eq!(thread::current().name().unwrap(), "main");
21+
}

tests/pass/panic/thread_panic.rs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//! Panicking in other threads.
2+
3+
use std::thread;
4+
5+
fn panic() {
6+
let result = thread::spawn(|| panic!("Hello!")).join().unwrap_err();
7+
let msg = result.downcast_ref::<&'static str>().unwrap();
8+
assert_eq!(*msg, "Hello!");
9+
}
10+
11+
fn panic_named() {
12+
thread::Builder::new()
13+
.name("childthread".to_string())
14+
.spawn(move || {
15+
panic!("Hello, world!");
16+
})
17+
.unwrap()
18+
.join()
19+
.unwrap_err();
20+
}
21+
22+
fn main() {
23+
panic();
24+
panic_named();
25+
}

tests/pass/panic/thread_panic.stderr

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
thread '<unnamed>' panicked at $DIR/thread_panic.rs:LL:CC:
2+
Hello!
3+
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
4+
thread 'childthread' panicked at $DIR/thread_panic.rs:LL:CC:
5+
Hello, world!

0 commit comments

Comments
 (0)