about summary refs log tree commit diff
path: root/src/tools
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2024-03-03 09:00:38 +0100
committerRalf Jung <post@ralfj.de>2024-03-03 09:00:38 +0100
commit8deb65160307c0cf71b07f5d930cba7ae6344bc1 (patch)
treef12aa3f4b43978252c502172bd3a2a7481e440de /src/tools
parentbe5da3a4aaa0890d578c60abb5e5a31593655c1b (diff)
downloadrust-8deb65160307c0cf71b07f5d930cba7ae6344bc1.tar.gz
rust-8deb65160307c0cf71b07f5d930cba7ae6344bc1.zip
move thread-panic tests to their own file; test getting the thread name
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/miri/tests/pass/concurrency/simple.rs19
-rw-r--r--src/tools/miri/tests/pass/concurrency/simple.stderr5
-rw-r--r--src/tools/miri/tests/pass/concurrency/thread_name.rs21
-rw-r--r--src/tools/miri/tests/pass/panic/thread_panic.rs25
-rw-r--r--src/tools/miri/tests/pass/panic/thread_panic.stderr5
5 files changed, 51 insertions, 24 deletions
diff --git a/src/tools/miri/tests/pass/concurrency/simple.rs b/src/tools/miri/tests/pass/concurrency/simple.rs
index ec549a998ba..46033eea35d 100644
--- a/src/tools/miri/tests/pass/concurrency/simple.rs
+++ b/src/tools/miri/tests/pass/concurrency/simple.rs
@@ -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();
 }
diff --git a/src/tools/miri/tests/pass/concurrency/simple.stderr b/src/tools/miri/tests/pass/concurrency/simple.stderr
deleted file mode 100644
index 33d6b6841ad..00000000000
--- a/src/tools/miri/tests/pass/concurrency/simple.stderr
+++ /dev/null
@@ -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!
diff --git a/src/tools/miri/tests/pass/concurrency/thread_name.rs b/src/tools/miri/tests/pass/concurrency/thread_name.rs
new file mode 100644
index 00000000000..6dd5f1f5c91
--- /dev/null
+++ b/src/tools/miri/tests/pass/concurrency/thread_name.rs
@@ -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");
+}
diff --git a/src/tools/miri/tests/pass/panic/thread_panic.rs b/src/tools/miri/tests/pass/panic/thread_panic.rs
new file mode 100644
index 00000000000..9a3040b2c56
--- /dev/null
+++ b/src/tools/miri/tests/pass/panic/thread_panic.rs
@@ -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();
+}
diff --git a/src/tools/miri/tests/pass/panic/thread_panic.stderr b/src/tools/miri/tests/pass/panic/thread_panic.stderr
new file mode 100644
index 00000000000..badd409d13f
--- /dev/null
+++ b/src/tools/miri/tests/pass/panic/thread_panic.stderr
@@ -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!