]> git.lizzy.rs Git - rust.git/commitdiff
various testing improvements
authorOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Fri, 22 Apr 2016 12:38:46 +0000 (14:38 +0200)
committerOliver 'ker' Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Fri, 22 Apr 2016 18:09:00 +0000 (20:09 +0200)
20 files changed:
src/bin/miri.rs
tests/compile-fail/bugs/discriminant_value.rs [new file with mode: 0644]
tests/compile-fail/bugs/memcmp.rs [new file with mode: 0644]
tests/compile-fail/bugs/slice_index.rs [new file with mode: 0644]
tests/compiletest.rs
tests/run-fail/inception.rs [new file with mode: 0644]
tests/run-pass/arrays.rs
tests/run-pass/bools.rs
tests/run-pass/c_enums.rs
tests/run-pass/calls.rs
tests/run-pass/closures.rs
tests/run-pass/heap.rs
tests/run-pass/ints.rs
tests/run-pass/loops.rs
tests/run-pass/pointers.rs
tests/run-pass/products.rs
tests/run-pass/specialization.rs
tests/run-pass/std.rs
tests/run-pass/sums.rs
tests/run-pass/vecs.rs

index ebfb379d313488c92657367cef88c172676981b3..a03d0a46ca93b91e1a4b01eb4b9fff92f734ec25 100644 (file)
@@ -1,4 +1,5 @@
-#![feature(rustc_private)]
+#![feature(rustc_private, custom_attribute)]
+#![allow(unused_attributes)]
 
 extern crate miri;
 extern crate rustc;
@@ -23,6 +24,7 @@ fn build_controller(&mut self, _: &Session) -> driver::CompileController<'a> {
     }
 }
 
+#[miri_run]
 fn main() {
     let args: Vec<String> = std::env::args().collect();
     rustc_driver::run_compiler(&args, &mut MiriCompilerCalls);
diff --git a/tests/compile-fail/bugs/discriminant_value.rs b/tests/compile-fail/bugs/discriminant_value.rs
new file mode 100644 (file)
index 0000000..f0a487e
--- /dev/null
@@ -0,0 +1,9 @@
+#![feature(custom_attribute)]
+#![allow(dead_code, unused_attributes)]
+
+// error-pattern:can't handle intrinsic: discriminant_value
+
+#[miri_run]
+fn main() {
+    assert_eq!(None::<i32>, None);
+}
diff --git a/tests/compile-fail/bugs/memcmp.rs b/tests/compile-fail/bugs/memcmp.rs
new file mode 100644 (file)
index 0000000..d854f21
--- /dev/null
@@ -0,0 +1,11 @@
+#![feature(custom_attribute)]
+#![allow(dead_code, unused_attributes)]
+
+// error-pattern:can't handle intrinsic: size_of_val
+
+#[miri_run]
+fn memcmp() {
+    assert_eq!("", "");
+}
+
+fn main() {}
diff --git a/tests/compile-fail/bugs/slice_index.rs b/tests/compile-fail/bugs/slice_index.rs
new file mode 100644 (file)
index 0000000..52a7624
--- /dev/null
@@ -0,0 +1,12 @@
+#![feature(custom_attribute)]
+#![allow(dead_code, unused_attributes)]
+
+// error-pattern:assertion failed
+
+#[miri_run]
+fn slice() -> u8 {
+    let arr: &[_] = &[101, 102, 103, 104, 105, 106];
+    arr[5]
+}
+
+fn main() {}
index 224d7f0611ff7077ba5dc46d8b0b6ef2051daf5a..51634fd15bffb3402c154fe5d092e1f130f2224c 100644 (file)
@@ -20,4 +20,5 @@ fn run_mode(mode: &'static str) {
 fn compile_test() {
     run_mode("compile-fail");
     run_mode("run-pass");
+    run_mode("run-fail");
 }
diff --git a/tests/run-fail/inception.rs b/tests/run-fail/inception.rs
new file mode 100644 (file)
index 0000000..25eb72a
--- /dev/null
@@ -0,0 +1,32 @@
+// error-pattern:no mir for DefId
+
+use std::env;
+use std::process::{Command, Output};
+
+fn run_miri(file: &str, sysroot: &str) -> Output {
+    let path = env::current_dir().unwrap();
+    let libpath = path.join("target").join("debug");
+    let libpath = libpath.to_str().unwrap();
+    let libpath2 = path.join("target").join("debug").join("deps");
+    let libpath2 = libpath2.to_str().unwrap();
+    Command::new("cargo")
+        .args(&[
+            "run", "--",
+            "--sysroot", sysroot,
+            "-L", libpath,
+            "-L", libpath2,
+            file
+        ])
+        .output()
+        .unwrap_or_else(|e| panic!("failed to execute process: {}", e))
+}
+
+fn main() {
+    let sysroot = env::var("RUST_SYSROOT").expect("env variable `RUST_SYSROOT` not set");
+    let test_run = run_miri("src/bin/miri.rs", &sysroot);
+
+    if test_run.status.code().unwrap_or(-1) != 0 {
+        println!("{}", String::from_utf8(test_run.stdout).unwrap());
+        panic!("{}", String::from_utf8(test_run.stderr).unwrap());
+    }
+}
index 26a4196b1b975eac33f969a3027d3268321a31ca..36b7217f5806277335485c7b3a81a0c083fed023 100644 (file)
@@ -6,6 +6,11 @@
     []
 }
 
+#[miri_run]
+fn mini_array() -> [u16; 1] {
+    [42]
+}
+
 #[miri_run]
 fn big_array() -> [u16; 5] {
     [5, 4, 3, 2, 1]
@@ -33,4 +38,14 @@ fn index() -> i32 {
     [42; 8]
 }
 
-fn main() {}
+#[miri_run]
+fn main() {
+    //assert_eq!(empty_array(), []);
+    assert_eq!(index_unsafe(), 20);
+    assert_eq!(index(), 20);
+    /*
+    assert_eq!(big_array(), [5, 4, 3, 2, 1]);
+    assert_eq!(array_array(), [[5, 4], [3, 2], [1, 0]]);
+    assert_eq!(array_repeat(), [42; 8]);
+    */
+}
index 948c09c0fdaabc835755f6b38f0f3c447c1b8902..953670fef9b275258f558d5911d448dafcde860a 100644 (file)
@@ -27,4 +27,10 @@ fn match_bool() -> i16 {
     }
 }
 
-fn main() {}
+#[miri_run]
+fn main() {
+    assert!(boolean());
+    assert_eq!(if_false(), 0);
+    assert_eq!(if_true(), 1);
+    assert_eq!(match_bool(), 1);
+}
index 442e58a22a98149869934e5d90badc60ec8600d4..fa7d195454ebe6165a207105f08df616ed0d1ab6 100644 (file)
@@ -20,4 +20,7 @@ fn unsafe_match() -> bool {
     }
 }
 
-fn main() {}
+#[miri_run]
+fn main() {
+    assert!(unsafe_match());
+}
index 62ea521d956e5d507cdca54b79cb02cec0d7c650..68b358145627544220011468ca28d1c82decbcc1 100644 (file)
@@ -39,4 +39,11 @@ fn test_size_of() -> usize {
     ::std::mem::size_of::<Option<i32>>()
 }
 
-fn main() {}
+#[miri_run]
+fn main() {
+    assert_eq!(call(), 2);
+    assert_eq!(factorial_recursive(), 3628800);
+    //assert_eq!(call_generic(), (42, true));
+    assert_eq!(cross_crate_fn_call(), 1);
+    //assert_eq!(test_size_of(), 8);
+}
index 3612cfcb4c4763bf0df2170b385b370e74736ef1..ca35992225eccaf31a8f13964d776458808ff544 100644 (file)
@@ -37,4 +37,7 @@ fn inner<T: Copy>(t: T) -> (i32, T, T) {
 //     y
 // }
 
-fn main() {}
+#[miri_run]
+fn main() {
+    assert_eq!(simple(), 12);
+}
index 3cc01e5829bb9835b7376a6b236fe0c0eb5c27e2..f5aad1601c77d5ec329683e12773bcb1baa19ea6 100644 (file)
@@ -11,4 +11,8 @@ fn make_box_syntax() -> Box<(i16, i16)> {
     box (1, 2)
 }
 
-fn main() {}
+#[miri_run]
+fn main() {
+    assert_eq!(*make_box(), (1, 2));
+    assert_eq!(*make_box_syntax(), (1, 2));
+}
index cc113eaed59239564976ad02e417aada391d174c..76091be3581ec10cef7b64a9aed26bc31a519cd7 100644 (file)
@@ -53,4 +53,13 @@ fn match_int_range() -> i64 {
     }
 }
 
-fn main() {}
+#[miri_run]
+fn main() {
+    assert_eq!(ret(), 1);
+    assert_eq!(neg(), -1);
+    assert_eq!(add(), 3);
+    assert_eq!(indirect_add(), 3);
+    assert_eq!(arith(), 5*5);
+    assert_eq!(match_int(), 20);
+    assert_eq!(match_int_range(), 4);
+}
index 081e7bb228b4ab1cfd8847abe314d1880c01d9e9..57a2f7c4357bee61697258ecc9b2a77dc0a060c8 100644 (file)
@@ -34,4 +34,9 @@ fn for_loop() -> usize {
     sum
 }
 
-fn main() {}
+#[miri_run]
+fn main() {
+    assert_eq!(factorial_loop(), 3628800);
+    assert_eq!(index_for_loop(), 60);
+    assert_eq!(for_loop(), 60);
+}
index b66aabb2505c42dcf66e33caac197a7e5bc1c320..9f28b982b4eeef6160d2df4c8ab53a98a2d69874 100644 (file)
@@ -58,4 +58,14 @@ fn dangling_pointer() -> *const i32 {
     &*b as *const i32
 }
 
-fn main() {}
+#[miri_run]
+fn main() {
+    assert_eq!(one_line_ref(), 1);
+    assert_eq!(basic_ref(), 1);
+    assert_eq!(basic_ref_mut(), 3);
+    assert_eq!(basic_ref_mut_var(), 3);
+    assert_eq!(tuple_ref_mut(), (10, 22));
+    assert_eq!(match_ref_mut(), 42);
+    // FIXME: improve this test... how?
+    assert!(dangling_pointer() != std::ptr::null());
+}
index 1d65006ae6f67ae92d77fdc309ca8fadf2b85728..68a1b429438e095423b48720bd11b9020f8cded9 100644 (file)
@@ -16,6 +16,7 @@ fn tuple_5() -> (i16, i16, i16, i16, i16) {
     (1, 2, 3, 4, 5)
 }
 
+#[derive(Debug, PartialEq)]
 struct Pair { x: i8, y: i8 }
 
 #[miri_run]
@@ -30,4 +31,11 @@ fn field_access() -> (i8, i8) {
     (p.x, p.y)
 }
 
-fn main() {}
+#[miri_run]
+fn main() {
+    assert_eq!(tuple(), (1,));
+    assert_eq!(tuple_2(), (1, 2));
+    assert_eq!(tuple_5(), (1, 2, 3, 4, 5));
+    assert_eq!(pair(), Pair { x: 10, y: 20} );
+    assert_eq!(field_access(), (15, 20));
+}
index b8b101fe8421786f04253ea6d2ac84888dcebc2c..b82038f400308c7312f0603a858b742015044426 100644 (file)
@@ -18,4 +18,6 @@ fn specialization() -> (bool, bool) {
     (i32::is_unit(), <()>::is_unit())
 }
 
-fn main() {}
+fn main() {
+    assert_eq!(specialization(), (false, true));
+}
index d9c0e3ca1fe4881e030b10f6bb2787bdf8c4f055..1d4dc8befef8c6e73455f872514e29a948015330 100644 (file)
@@ -44,4 +44,10 @@ fn true_assert() {
     assert_eq!(1, 1);
 }
 
-fn main() {}
+#[miri_run]
+fn main() {
+    //let x = rc_reference_cycle().0;
+    //assert!(x.borrow().is_some());
+    assert_eq!(*arc(), 42);
+    assert_eq!(rc_cell().get(), 84);
+}
index 7f92f0d5ffffebb0b8281312dab1063b6a14a005..b8635b4dcd648c1929b1d1c0493cd1e6454d8f0a 100644 (file)
@@ -1,6 +1,7 @@
 #![feature(custom_attribute)]
 #![allow(dead_code, unused_attributes)]
 
+#[derive(Debug, PartialEq)]
 enum Unit { Unit }
 
 #[miri_run]
@@ -8,6 +9,7 @@ fn return_unit() -> Unit {
     Unit::Unit
 }
 
+#[derive(Debug, PartialEq)]
 enum MyBool { False, True }
 
 #[miri_run]
@@ -53,4 +55,14 @@ fn two_nones() -> (Option<i16>, Option<i16>) {
     (None, None)
 }
 
-fn main() {}
+#[miri_run]
+fn main() {
+    //assert_eq!(two_nones(), (None, None));
+    assert_eq!(match_opt_some(), 13);
+    assert_eq!(match_opt_none(), 42);
+    //assert_eq!(return_some(), Some(42));
+    //assert_eq!(return_none(), None);
+    //assert_eq!(return_false(), MyBool::False);
+    //assert_eq!(return_true(), MyBool::True);
+    //assert_eq!(return_unit(), Unit::Unit);
+}
index 325762289c5bdebfc736495be1c53b8ff2ff5392..2a4cc6128843bc1fc3546f597562e61d0914dd83 100644 (file)
@@ -36,4 +36,9 @@ fn vec_reallocate() -> Vec<u8> {
     v
 }
 
-fn main() {}
+#[miri_run]
+fn main() {
+    assert_eq!(vec_reallocate().len(), 5);
+    assert_eq!(vec_into_iter(), 30);
+    assert_eq!(make_vec().capacity(), 4);
+}