From: Oliver Schneider Date: Fri, 22 Apr 2016 12:38:46 +0000 (+0200) Subject: various testing improvements X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=ef5fc75c35d6bc66503814907a5e045c744a9456;p=rust.git various testing improvements --- diff --git a/src/bin/miri.rs b/src/bin/miri.rs index ebfb379d313..a03d0a46ca9 100644 --- a/src/bin/miri.rs +++ b/src/bin/miri.rs @@ -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 = 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 index 00000000000..f0a487e20df --- /dev/null +++ b/tests/compile-fail/bugs/discriminant_value.rs @@ -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::, None); +} diff --git a/tests/compile-fail/bugs/memcmp.rs b/tests/compile-fail/bugs/memcmp.rs new file mode 100644 index 00000000000..d854f21ca31 --- /dev/null +++ b/tests/compile-fail/bugs/memcmp.rs @@ -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 index 00000000000..52a76247ca4 --- /dev/null +++ b/tests/compile-fail/bugs/slice_index.rs @@ -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() {} diff --git a/tests/compiletest.rs b/tests/compiletest.rs index 224d7f0611f..51634fd15bf 100644 --- a/tests/compiletest.rs +++ b/tests/compiletest.rs @@ -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 index 00000000000..25eb72aa04c --- /dev/null +++ b/tests/run-fail/inception.rs @@ -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()); + } +} diff --git a/tests/run-pass/arrays.rs b/tests/run-pass/arrays.rs index 26a4196b1b9..36b7217f580 100644 --- a/tests/run-pass/arrays.rs +++ b/tests/run-pass/arrays.rs @@ -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]); + */ +} diff --git a/tests/run-pass/bools.rs b/tests/run-pass/bools.rs index 948c09c0fda..953670fef9b 100644 --- a/tests/run-pass/bools.rs +++ b/tests/run-pass/bools.rs @@ -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); +} diff --git a/tests/run-pass/c_enums.rs b/tests/run-pass/c_enums.rs index 442e58a22a9..fa7d195454e 100644 --- a/tests/run-pass/c_enums.rs +++ b/tests/run-pass/c_enums.rs @@ -20,4 +20,7 @@ fn unsafe_match() -> bool { } } -fn main() {} +#[miri_run] +fn main() { + assert!(unsafe_match()); +} diff --git a/tests/run-pass/calls.rs b/tests/run-pass/calls.rs index 62ea521d956..68b35814562 100644 --- a/tests/run-pass/calls.rs +++ b/tests/run-pass/calls.rs @@ -39,4 +39,11 @@ fn test_size_of() -> usize { ::std::mem::size_of::>() } -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); +} diff --git a/tests/run-pass/closures.rs b/tests/run-pass/closures.rs index 3612cfcb4c4..ca35992225e 100644 --- a/tests/run-pass/closures.rs +++ b/tests/run-pass/closures.rs @@ -37,4 +37,7 @@ fn inner(t: T) -> (i32, T, T) { // y // } -fn main() {} +#[miri_run] +fn main() { + assert_eq!(simple(), 12); +} diff --git a/tests/run-pass/heap.rs b/tests/run-pass/heap.rs index 3cc01e5829b..f5aad1601c7 100644 --- a/tests/run-pass/heap.rs +++ b/tests/run-pass/heap.rs @@ -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)); +} diff --git a/tests/run-pass/ints.rs b/tests/run-pass/ints.rs index cc113eaed59..76091be3581 100644 --- a/tests/run-pass/ints.rs +++ b/tests/run-pass/ints.rs @@ -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); +} diff --git a/tests/run-pass/loops.rs b/tests/run-pass/loops.rs index 081e7bb228b..57a2f7c4357 100644 --- a/tests/run-pass/loops.rs +++ b/tests/run-pass/loops.rs @@ -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); +} diff --git a/tests/run-pass/pointers.rs b/tests/run-pass/pointers.rs index b66aabb2505..9f28b982b4e 100644 --- a/tests/run-pass/pointers.rs +++ b/tests/run-pass/pointers.rs @@ -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()); +} diff --git a/tests/run-pass/products.rs b/tests/run-pass/products.rs index 1d65006ae6f..68a1b429438 100644 --- a/tests/run-pass/products.rs +++ b/tests/run-pass/products.rs @@ -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)); +} diff --git a/tests/run-pass/specialization.rs b/tests/run-pass/specialization.rs index b8b101fe842..b82038f4003 100644 --- a/tests/run-pass/specialization.rs +++ b/tests/run-pass/specialization.rs @@ -18,4 +18,6 @@ fn specialization() -> (bool, bool) { (i32::is_unit(), <()>::is_unit()) } -fn main() {} +fn main() { + assert_eq!(specialization(), (false, true)); +} diff --git a/tests/run-pass/std.rs b/tests/run-pass/std.rs index d9c0e3ca1fe..1d4dc8befef 100644 --- a/tests/run-pass/std.rs +++ b/tests/run-pass/std.rs @@ -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); +} diff --git a/tests/run-pass/sums.rs b/tests/run-pass/sums.rs index 7f92f0d5fff..b8635b4dcd6 100644 --- a/tests/run-pass/sums.rs +++ b/tests/run-pass/sums.rs @@ -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, Option) { (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); +} diff --git a/tests/run-pass/vecs.rs b/tests/run-pass/vecs.rs index 325762289c5..2a4cc612884 100644 --- a/tests/run-pass/vecs.rs +++ b/tests/run-pass/vecs.rs @@ -36,4 +36,9 @@ fn vec_reallocate() -> Vec { 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); +}