From 50107034c08413898392ddf08d13ce1b29b1efac Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Mon, 21 Dec 2015 18:58:18 +0200 Subject: [PATCH] Add tests --- src/test/run-fail/mir_indexing_oob_1.rs | 23 +++++++++++ src/test/run-fail/mir_indexing_oob_2.rs | 23 +++++++++++ src/test/run-fail/mir_indexing_oob_3.rs | 23 +++++++++++ .../mir_trans_calls_converging_drops.rs | 37 +++++++++++++++++ .../mir_trans_calls_converging_drops_2.rs | 41 +++++++++++++++++++ .../run-fail/mir_trans_calls_diverging.rs | 24 +++++++++++ .../mir_trans_calls_diverging_drops.rs | 34 +++++++++++++++ .../run-fail/mir_trans_no_landing_pads.rs | 36 ++++++++++++++++ .../mir_trans_no_landing_pads_diverging.rs | 36 ++++++++++++++++ .../run-pass/mir_trans_call_converging.rs | 28 +++++++++++++ src/test/run-pass/mir_void_return.rs | 24 +++++++++++ src/test/run-pass/mir_void_return_2.rs | 22 ++++++++++ 12 files changed, 351 insertions(+) create mode 100644 src/test/run-fail/mir_indexing_oob_1.rs create mode 100644 src/test/run-fail/mir_indexing_oob_2.rs create mode 100644 src/test/run-fail/mir_indexing_oob_3.rs create mode 100644 src/test/run-fail/mir_trans_calls_converging_drops.rs create mode 100644 src/test/run-fail/mir_trans_calls_converging_drops_2.rs create mode 100644 src/test/run-fail/mir_trans_calls_diverging.rs create mode 100644 src/test/run-fail/mir_trans_calls_diverging_drops.rs create mode 100644 src/test/run-fail/mir_trans_no_landing_pads.rs create mode 100644 src/test/run-fail/mir_trans_no_landing_pads_diverging.rs create mode 100644 src/test/run-pass/mir_trans_call_converging.rs create mode 100644 src/test/run-pass/mir_void_return.rs create mode 100644 src/test/run-pass/mir_void_return_2.rs diff --git a/src/test/run-fail/mir_indexing_oob_1.rs b/src/test/run-fail/mir_indexing_oob_1.rs new file mode 100644 index 00000000000..e0d20a20577 --- /dev/null +++ b/src/test/run-fail/mir_indexing_oob_1.rs @@ -0,0 +1,23 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// error-pattern:index out of bounds: the len is 5 but the index is 10 +#![feature(rustc_attrs)] + +const C: [u32; 5] = [0; 5]; + +#[rustc_mir] +fn test() -> u32 { + C[10] +} + +fn main() { + test(); +} diff --git a/src/test/run-fail/mir_indexing_oob_2.rs b/src/test/run-fail/mir_indexing_oob_2.rs new file mode 100644 index 00000000000..6c65be5769f --- /dev/null +++ b/src/test/run-fail/mir_indexing_oob_2.rs @@ -0,0 +1,23 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// error-pattern:index out of bounds: the len is 5 but the index is 10 +#![feature(rustc_attrs)] + +const C: &'static [u8; 5] = b"hello"; + +#[rustc_mir] +fn test() -> u8 { + C[10] +} + +fn main() { + test(); +} diff --git a/src/test/run-fail/mir_indexing_oob_3.rs b/src/test/run-fail/mir_indexing_oob_3.rs new file mode 100644 index 00000000000..5f3fc9376b0 --- /dev/null +++ b/src/test/run-fail/mir_indexing_oob_3.rs @@ -0,0 +1,23 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// error-pattern:index out of bounds: the len is 5 but the index is 10 +#![feature(rustc_attrs)] + +const C: &'static [u8; 5] = b"hello"; + +#[rustc_mir] +fn mir() -> u8 { + C[10] +} + +fn main() { + mir(); +} diff --git a/src/test/run-fail/mir_trans_calls_converging_drops.rs b/src/test/run-fail/mir_trans_calls_converging_drops.rs new file mode 100644 index 00000000000..754f616cfd5 --- /dev/null +++ b/src/test/run-fail/mir_trans_calls_converging_drops.rs @@ -0,0 +1,37 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. +#![feature(rustc_attrs)] +// error-pattern:converging_fn called +// error-pattern:0 dropped +// error-pattern:exit + +use std::io::{self, Write}; + +struct Droppable(u8); +impl Drop for Droppable { + fn drop(&mut self) { + write!(io::stderr(), "{} dropped\n", self.0); + } +} + +fn converging_fn() { + write!(io::stderr(), "converging_fn called\n"); +} + +#[rustc_mir] +fn mir(d: Droppable) { + converging_fn(); +} + +fn main() { + let d = Droppable(0); + mir(d); + panic!("exit"); +} diff --git a/src/test/run-fail/mir_trans_calls_converging_drops_2.rs b/src/test/run-fail/mir_trans_calls_converging_drops_2.rs new file mode 100644 index 00000000000..5e870be3bc6 --- /dev/null +++ b/src/test/run-fail/mir_trans_calls_converging_drops_2.rs @@ -0,0 +1,41 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. +#![feature(rustc_attrs)] +// error-pattern:complex called +// error-pattern:dropped +// error-pattern:exit + +use std::io::{self, Write}; + +struct Droppable; +impl Drop for Droppable { + fn drop(&mut self) { + write!(io::stderr(), "dropped\n"); + } +} + +// return value of this function is copied into the return slot +fn complex() -> u64 { + write!(io::stderr(), "complex called\n"); + 42 +} + + +#[rustc_mir] +fn mir() -> u64 { + let x = Droppable; + return complex(); + drop(x); +} + +pub fn main() { + assert_eq!(mir(), 42); + panic!("exit"); +} diff --git a/src/test/run-fail/mir_trans_calls_diverging.rs b/src/test/run-fail/mir_trans_calls_diverging.rs new file mode 100644 index 00000000000..fcd8ab26a0a --- /dev/null +++ b/src/test/run-fail/mir_trans_calls_diverging.rs @@ -0,0 +1,24 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. +#![feature(rustc_attrs)] +// error-pattern:diverging_fn called + +fn diverging_fn() -> ! { + panic!("diverging_fn called") +} + +#[rustc_mir] +fn mir() { + diverging_fn(); +} + +fn main() { + mir(); +} diff --git a/src/test/run-fail/mir_trans_calls_diverging_drops.rs b/src/test/run-fail/mir_trans_calls_diverging_drops.rs new file mode 100644 index 00000000000..ffa1ff08277 --- /dev/null +++ b/src/test/run-fail/mir_trans_calls_diverging_drops.rs @@ -0,0 +1,34 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. +#![feature(rustc_attrs)] +// error-pattern:diverging_fn called +// error-pattern:0 dropped +use std::io::{self, Write}; + +struct Droppable(u8); +impl Drop for Droppable { + fn drop(&mut self) { + write!(io::stderr(), "{} dropped", self.0); + } +} + +fn diverging_fn() -> ! { + panic!("diverging_fn called") +} + +#[rustc_mir] +fn mir(d: Droppable) { + diverging_fn(); +} + +fn main() { + let d = Droppable(0); + mir(d); +} diff --git a/src/test/run-fail/mir_trans_no_landing_pads.rs b/src/test/run-fail/mir_trans_no_landing_pads.rs new file mode 100644 index 00000000000..bc913fdab1c --- /dev/null +++ b/src/test/run-fail/mir_trans_no_landing_pads.rs @@ -0,0 +1,36 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. +#![feature(rustc_attrs)] +// compile-flags: -Z no-landing-pads +// error-pattern:converging_fn called +use std::io::{self, Write}; + +struct Droppable; +impl Drop for Droppable { + fn drop(&mut self) { + ::std::process::exit(1) + } +} + +fn converging_fn() { + panic!("converging_fn called") +} + +#[rustc_mir] +fn mir(d: Droppable) { + let x = Droppable; + converging_fn(); + drop(x); + drop(d); +} + +fn main() { + mir(Droppable); +} diff --git a/src/test/run-fail/mir_trans_no_landing_pads_diverging.rs b/src/test/run-fail/mir_trans_no_landing_pads_diverging.rs new file mode 100644 index 00000000000..d97eb8c89e3 --- /dev/null +++ b/src/test/run-fail/mir_trans_no_landing_pads_diverging.rs @@ -0,0 +1,36 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. +#![feature(rustc_attrs)] +// compile-flags: -Z no-landing-pads +// error-pattern:diverging_fn called +use std::io::{self, Write}; + +struct Droppable; +impl Drop for Droppable { + fn drop(&mut self) { + ::std::process::exit(1) + } +} + +fn diverging_fn() -> ! { + panic!("diverging_fn called") +} + +#[rustc_mir] +fn mir(d: Droppable) { + let x = Droppable; + diverging_fn(); + drop(x); + drop(d); +} + +fn main() { + mir(Droppable); +} diff --git a/src/test/run-pass/mir_trans_call_converging.rs b/src/test/run-pass/mir_trans_call_converging.rs new file mode 100644 index 00000000000..d8acfec25c4 --- /dev/null +++ b/src/test/run-pass/mir_trans_call_converging.rs @@ -0,0 +1,28 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. +#![feature(rustc_attrs)] + +fn converging_fn() -> u64 { + 43 +} + +#[rustc_mir] +fn mir() -> u64 { + let x; + loop { + x = converging_fn(); + break; + } + x +} + +fn main() { + assert_eq!(mir(), 43); +} diff --git a/src/test/run-pass/mir_void_return.rs b/src/test/run-pass/mir_void_return.rs new file mode 100644 index 00000000000..8b07449b8fa --- /dev/null +++ b/src/test/run-pass/mir_void_return.rs @@ -0,0 +1,24 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(rustc_attrs)] + +#[rustc_mir] +fn mir() -> (){ + let x = 1; + let mut y = 0; + while y < x { + y += 1 + } +} + +pub fn main() { + mir(); +} diff --git a/src/test/run-pass/mir_void_return_2.rs b/src/test/run-pass/mir_void_return_2.rs new file mode 100644 index 00000000000..a3ad3432409 --- /dev/null +++ b/src/test/run-pass/mir_void_return_2.rs @@ -0,0 +1,22 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(rustc_attrs)] + +fn nil() {} + +#[rustc_mir] +fn mir(){ + nil() +} + +pub fn main() { + mir(); +}