diff options
| author | David Tolnay <dtolnay@gmail.com> | 2024-02-25 20:53:48 -0800 |
|---|---|---|
| committer | David Tolnay <dtolnay@gmail.com> | 2024-02-25 20:55:12 -0800 |
| commit | 793b45f53a671710a7b01e05ae82f4125aa95d73 (patch) | |
| tree | 7f9fe31d0ccdf887d8eb7bace9f30a152e1de35c | |
| parent | 0250ef2571185b05701ed9d74fc904c17508a397 (diff) | |
| download | rust-793b45f53a671710a7b01e05ae82f4125aa95d73.tar.gz rust-793b45f53a671710a7b01e05ae82f4125aa95d73.zip | |
Add Waker::will_wake tests
Currently fails:
---- task::test_waker_will_wake_clone stdout ----
thread 'task::test_waker_will_wake_clone' panicked at library/alloc/tests/task.rs:17:5:
assertion failed: waker.will_wake(&clone)
| -rw-r--r-- | library/alloc/tests/lib.rs | 2 | ||||
| -rw-r--r-- | library/alloc/tests/task.rs | 34 |
2 files changed, 36 insertions, 0 deletions
diff --git a/library/alloc/tests/lib.rs b/library/alloc/tests/lib.rs index c4e89a58a05..ed928994ad6 100644 --- a/library/alloc/tests/lib.rs +++ b/library/alloc/tests/lib.rs @@ -41,6 +41,7 @@ #![feature(thin_box)] #![feature(strict_provenance)] #![feature(drain_keep_rest)] +#![feature(local_waker)] #![allow(internal_features)] #![deny(fuzzy_provenance_casts)] #![deny(unsafe_op_in_unsafe_fn)] @@ -62,6 +63,7 @@ mod rc; mod slice; mod str; mod string; +mod task; mod thin_box; mod vec; mod vec_deque; diff --git a/library/alloc/tests/task.rs b/library/alloc/tests/task.rs new file mode 100644 index 00000000000..0f8d9218980 --- /dev/null +++ b/library/alloc/tests/task.rs @@ -0,0 +1,34 @@ +use alloc::rc::Rc; +use alloc::sync::Arc; +use alloc::task::{LocalWake, Wake}; +use core::task::{LocalWaker, Waker}; + +#[test] +fn test_waker_will_wake_clone() { + struct NoopWaker; + + impl Wake for NoopWaker { + fn wake(self: Arc<Self>) {} + } + + let waker = Waker::from(Arc::new(NoopWaker)); + let clone = waker.clone(); + + assert!(waker.will_wake(&clone)); + assert!(clone.will_wake(&waker)); +} + +#[test] +fn test_local_waker_will_wake_clone() { + struct NoopWaker; + + impl LocalWake for NoopWaker { + fn wake(self: Rc<Self>) {} + } + + let waker = LocalWaker::from(Rc::new(NoopWaker)); + let clone = waker.clone(); + + assert!(waker.will_wake(&clone)); + assert!(clone.will_wake(&waker)); +} |
