about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlexis Bourget <alexis.bourget@gmail.com>2020-09-08 00:10:35 +0200
committerAlexis Bourget <alexis.bourget@gmail.com>2020-09-21 21:50:19 +0200
commitf69c5aa428efdbc01685c3d06e63fedd3120e8e5 (patch)
tree8dfb6e05e419e4ee744c262321984952225c590d
parent8aae1eee94f481bd955cff473deae1f03c313451 (diff)
downloadrust-f69c5aa428efdbc01685c3d06e63fedd3120e8e5.tar.gz
rust-f69c5aa428efdbc01685c3d06e63fedd3120e8e5.zip
Move more tests using Cell to unit tests
-rw-r--r--library/core/tests/option.rs31
-rw-r--r--src/test/ui/option-unwrap.rs32
2 files changed, 31 insertions, 32 deletions
diff --git a/library/core/tests/option.rs b/library/core/tests/option.rs
index 9e86e07dd91..bd9a5a6a2cd 100644
--- a/library/core/tests/option.rs
+++ b/library/core/tests/option.rs
@@ -372,3 +372,34 @@ fn option_const() {
     const IS_NONE: bool = OPTION.is_none();
     assert!(!IS_NONE);
 }
+
+#[test]
+fn test_unwrap_drop() {
+    use std::cell::Cell;
+
+    struct Dtor<'a> {
+        x: &'a Cell<isize>,
+    }
+
+    impl<'a> std::ops::Drop for Dtor<'a> {
+        fn drop(&mut self) {
+            self.x.set(self.x.get() - 1);
+        }
+    }
+
+    fn unwrap<T>(o: Option<T>) -> T {
+        match o {
+            Some(v) => v,
+            None => panic!(),
+        }
+    }
+
+    let x = &Cell::new(1);
+
+    {
+        let b = Some(Dtor { x });
+        let _c = unwrap(b);
+    }
+
+    assert_eq!(x.get(), 0);
+}
diff --git a/src/test/ui/option-unwrap.rs b/src/test/ui/option-unwrap.rs
deleted file mode 100644
index 173f803ee24..00000000000
--- a/src/test/ui/option-unwrap.rs
+++ /dev/null
@@ -1,32 +0,0 @@
-// run-pass
-
-#![allow(non_camel_case_types)]
-use std::cell::Cell;
-
-struct dtor<'a> {
-    x: &'a Cell<isize>,
-}
-
-impl<'a> Drop for dtor<'a> {
-    fn drop(&mut self) {
-        self.x.set(self.x.get() - 1);
-    }
-}
-
-fn unwrap<T>(o: Option<T>) -> T {
-    match o {
-      Some(v) => v,
-      None => panic!()
-    }
-}
-
-pub fn main() {
-    let x = &Cell::new(1);
-
-    {
-        let b = Some(dtor { x:x });
-        let _c = unwrap(b);
-    }
-
-    assert_eq!(x.get(), 0);
-}