Add tests

This commit is contained in:
Simonas Kazlauskas 2015-12-21 18:58:18 +02:00
parent cef6aee369
commit 50107034c0
12 changed files with 351 additions and 0 deletions

View 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();
}

View 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();
}

View 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();
}

View 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");
}

View 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");
}

View 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();
}

View 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);
}

View 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);
}

View 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);
}

View 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);
}

View 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();
}

View 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();
}