From 224d03dbdc642a60a3326c7bb9b9206082d4cda4 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 8 Nov 2018 08:58:03 +0100 Subject: [PATCH] organize std tests a bit better --- tests/run-pass/rc.rs | 35 +++++++++++++++++++++++++++++++++-- tests/run-pass/refcell.rs | 6 +++++- tests/run-pass/std.rs | 34 ---------------------------------- 3 files changed, 38 insertions(+), 37 deletions(-) delete mode 100644 tests/run-pass/std.rs diff --git a/tests/run-pass/rc.rs b/tests/run-pass/rc.rs index 0bf70750311..bc89d752e0b 100644 --- a/tests/run-pass/rc.rs +++ b/tests/run-pass/rc.rs @@ -1,13 +1,33 @@ -use std::cell::RefCell; +use std::cell::{Cell, RefCell}; use std::rc::Rc; +use std::sync::Arc; fn rc_refcell() { let r = Rc::new(RefCell::new(42)); + let r2 = r.clone(); *r.borrow_mut() += 10; - let x = *r.borrow(); + let x = *r2.borrow(); assert_eq!(x, 52); } +fn rc_cell() { + let r = Rc::new(Cell::new(42)); + let r2 = r.clone(); + let x = r.get(); + r2.set(x + x); + assert_eq!(r.get(), 84); +} + +fn rc_refcell2() { + let r = Rc::new(RefCell::new(42)); + let r2 = r.clone(); + *r.borrow_mut() += 10; + let x = r2.borrow(); + let r3 = r.clone(); + let y = r3.borrow(); + assert_eq!((*x + *y)/2, 52); +} + fn rc_raw() { let r = Rc::new(0); let r2 = Rc::into_raw(r.clone()); @@ -17,6 +37,14 @@ fn rc_raw() { assert!(Rc::try_unwrap(r2).is_ok()); } +fn arc() { + fn test() -> Arc { + let a = Arc::new(42); + a + } + assert_eq!(*test(), 42); +} + // Make sure this Rc doesn't fall apart when touched fn check_unique_rc(mut r: Rc) { let r2 = r.clone(); @@ -34,6 +62,9 @@ fn rc_from() { fn main() { rc_refcell(); + rc_refcell2(); + rc_cell(); rc_raw(); rc_from(); + arc(); } diff --git a/tests/run-pass/refcell.rs b/tests/run-pass/refcell.rs index 93cef1572a3..52dcdbd36d0 100644 --- a/tests/run-pass/refcell.rs +++ b/tests/run-pass/refcell.rs @@ -1,6 +1,6 @@ use std::cell::RefCell; -fn main() { +fn lots_of_funny_borrows() { let c = RefCell::new(42); { let s1 = c.borrow(); @@ -31,3 +31,7 @@ fn main() { let _y: i32 = *s2; } } + +fn main() { + lots_of_funny_borrows(); +} diff --git a/tests/run-pass/std.rs b/tests/run-pass/std.rs deleted file mode 100644 index 7ff967b29f3..00000000000 --- a/tests/run-pass/std.rs +++ /dev/null @@ -1,34 +0,0 @@ -use std::cell::{Cell, RefCell}; -use std::rc::Rc; -use std::sync::Arc; - -fn rc_cell() -> Rc> { - let r = Rc::new(Cell::new(42)); - let x = r.get(); - r.set(x + x); - r -} - -fn rc_refcell() -> i32 { - let r = Rc::new(RefCell::new(42)); - *r.borrow_mut() += 10; - let x = r.borrow(); - let y = r.borrow(); - (*x + *y)/2 -} - -fn arc() -> Arc { - let a = Arc::new(42); - a -} - -fn true_assert() { - assert_eq!(1, 1); -} - -fn main() { - assert_eq!(*arc(), 42); - assert_eq!(rc_cell().get(), 84); - assert_eq!(rc_refcell(), 52); - true_assert(); -}