]> git.lizzy.rs Git - rust.git/commitdiff
Add tests
authorSimonas Kazlauskas <git@kazlauskas.me>
Mon, 21 Dec 2015 16:58:18 +0000 (18:58 +0200)
committerSimonas Kazlauskas <git@kazlauskas.me>
Wed, 6 Jan 2016 11:57:52 +0000 (13:57 +0200)
12 files changed:
src/test/run-fail/mir_indexing_oob_1.rs [new file with mode: 0644]
src/test/run-fail/mir_indexing_oob_2.rs [new file with mode: 0644]
src/test/run-fail/mir_indexing_oob_3.rs [new file with mode: 0644]
src/test/run-fail/mir_trans_calls_converging_drops.rs [new file with mode: 0644]
src/test/run-fail/mir_trans_calls_converging_drops_2.rs [new file with mode: 0644]
src/test/run-fail/mir_trans_calls_diverging.rs [new file with mode: 0644]
src/test/run-fail/mir_trans_calls_diverging_drops.rs [new file with mode: 0644]
src/test/run-fail/mir_trans_no_landing_pads.rs [new file with mode: 0644]
src/test/run-fail/mir_trans_no_landing_pads_diverging.rs [new file with mode: 0644]
src/test/run-pass/mir_trans_call_converging.rs [new file with mode: 0644]
src/test/run-pass/mir_void_return.rs [new file with mode: 0644]
src/test/run-pass/mir_void_return_2.rs [new file with mode: 0644]

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 (file)
index 0000000..e0d20a2
--- /dev/null
@@ -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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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 (file)
index 0000000..6c65be5
--- /dev/null
@@ -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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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 (file)
index 0000000..5f3fc93
--- /dev/null
@@ -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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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 (file)
index 0000000..754f616
--- /dev/null
@@ -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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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 (file)
index 0000000..5e870be
--- /dev/null
@@ -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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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 (file)
index 0000000..fcd8ab2
--- /dev/null
@@ -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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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 (file)
index 0000000..ffa1ff0
--- /dev/null
@@ -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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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 (file)
index 0000000..bc913fd
--- /dev/null
@@ -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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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 (file)
index 0000000..d97eb8c
--- /dev/null
@@ -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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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 (file)
index 0000000..d8acfec
--- /dev/null
@@ -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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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 (file)
index 0000000..8b07449
--- /dev/null
@@ -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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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 (file)
index 0000000..a3ad343
--- /dev/null
@@ -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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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();
+}