mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 23:34:48 +00:00
Add tests
This commit is contained in:
parent
cef6aee369
commit
50107034c0
23
src/test/run-fail/mir_indexing_oob_1.rs
Normal file
23
src/test/run-fail/mir_indexing_oob_1.rs
Normal file
@ -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();
|
||||
}
|
23
src/test/run-fail/mir_indexing_oob_2.rs
Normal file
23
src/test/run-fail/mir_indexing_oob_2.rs
Normal file
@ -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();
|
||||
}
|
23
src/test/run-fail/mir_indexing_oob_3.rs
Normal file
23
src/test/run-fail/mir_indexing_oob_3.rs
Normal file
@ -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();
|
||||
}
|
37
src/test/run-fail/mir_trans_calls_converging_drops.rs
Normal file
37
src/test/run-fail/mir_trans_calls_converging_drops.rs
Normal file
@ -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");
|
||||
}
|
41
src/test/run-fail/mir_trans_calls_converging_drops_2.rs
Normal file
41
src/test/run-fail/mir_trans_calls_converging_drops_2.rs
Normal file
@ -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");
|
||||
}
|
24
src/test/run-fail/mir_trans_calls_diverging.rs
Normal file
24
src/test/run-fail/mir_trans_calls_diverging.rs
Normal file
@ -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();
|
||||
}
|
34
src/test/run-fail/mir_trans_calls_diverging_drops.rs
Normal file
34
src/test/run-fail/mir_trans_calls_diverging_drops.rs
Normal file
@ -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);
|
||||
}
|
36
src/test/run-fail/mir_trans_no_landing_pads.rs
Normal file
36
src/test/run-fail/mir_trans_no_landing_pads.rs
Normal file
@ -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);
|
||||
}
|
36
src/test/run-fail/mir_trans_no_landing_pads_diverging.rs
Normal file
36
src/test/run-fail/mir_trans_no_landing_pads_diverging.rs
Normal file
@ -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);
|
||||
}
|
28
src/test/run-pass/mir_trans_call_converging.rs
Normal file
28
src/test/run-pass/mir_trans_call_converging.rs
Normal file
@ -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);
|
||||
}
|
24
src/test/run-pass/mir_void_return.rs
Normal file
24
src/test/run-pass/mir_void_return.rs
Normal file
@ -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();
|
||||
}
|
22
src/test/run-pass/mir_void_return_2.rs
Normal file
22
src/test/run-pass/mir_void_return_2.rs
Normal file
@ -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();
|
||||
}
|
Loading…
Reference in New Issue
Block a user