testsuite: Add various test cases

Some are xfailed, some not, some existing ones get un-xfailed.
This commit is contained in:
Tim Chevalier 2013-03-21 15:00:29 -07:00
parent b93393e907
commit e01cf3caf5
15 changed files with 383 additions and 13 deletions

View file

@ -0,0 +1,3 @@
pub trait Foo {
fn bar();
}

View file

@ -8,27 +8,19 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// xfail-test
struct Thing {
x: int
}
impl Mul<int, Thing>*/ for Thing/* { //~ ERROR Look ma, no Mul!
fn mul(c: &int) -> Thing {
impl Thing {
fn mul(&self, c: &int) -> Thing {
Thing {x: self.x * *c}
}
}
fn main() {
let u = Thing {x: 2};
let _v = u.mul(&3); // Works
let w = u * 3; // Works!!
let _v = u.mul(&3); // This is ok
let w = u * 3; //~ ERROR binary operation * cannot be applied to type `Thing`
io::println(fmt!("%i", w.x));
/*
// This doesn't work though.
let u2 = u as @Mul<int, Thing>;
let w2 = u2.mul(&4);
io::println(fmt!("%i", w2.x));
*/
}

View file

@ -9,7 +9,6 @@
// except according to those terms.
// xfail-test
struct Point {
x: float,
y: float,

View file

@ -0,0 +1,22 @@
// Copyright 2013 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.
// xfail-test
struct HasNested {
mut nest: ~[~[int]],
}
impl HasNested {
fn method_push_local(&self) {
self.nest[0].push(0);
}
}
fn main() {}

View file

@ -0,0 +1,24 @@
// Copyright 2013 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.
struct Foo {
baz: uint
}
impl Foo {
fn bar() {
Foo { baz: 0 }.bar();
}
fn bar() { //~ ERROR duplicate definition of value bar
}
}
fn main() {}

View file

@ -0,0 +1,19 @@
// Copyright 2013 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.
// xfail-test
fn main() {
for os::args().each |arg| {
match copy *arg {
s => { }
}
}
}

View file

@ -0,0 +1,15 @@
// Copyright 2013 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.
// xfail-test
trait I {}
type K = I;
impl K for int {}
fn main() {}

View file

@ -0,0 +1,12 @@
// Copyright 2013 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.
// xfail-test
fn main() { fmt!("%?", None); } //~ ERROR can't resolve type variable

View file

@ -0,0 +1,14 @@
// Copyright 2013 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.
trait B < A > { fn a() -> A { self.a} } //~ ERROR unresolved name
fn main() {}

View file

@ -0,0 +1,42 @@
// Copyright 2013 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.
extern mod std;
use core::io::WriterUtil;
enum Token {
Text(@~str),
ETag(@~[~str], @~str),
UTag(@~[~str], @~str),
Section(@~[~str], bool, @~[Token], @~str, @~str, @~str, @~str, @~str),
IncompleteSection(@~[~str], bool, @~str, bool),
Partial(@~str, @~str, @~str),
}
fn check_strs(actual: &str, expected: &str) -> bool
{
if actual != expected
{
io::stderr().write_line(fmt!("Found %s, but expected %s", actual, expected));
return false;
}
return true;
}
fn main()
{
// fail_unless!(check_strs(fmt!("%?", Text(@~"foo")), "Text(@~\"foo\")"));
// fail_unless!(check_strs(fmt!("%?", ETag(@~[~"foo"], @~"bar")), "ETag(@~[ ~\"foo\" ], @~\"bar\")"));
let t = Text(@~"foo");
let u = Section(@~[~"alpha"], true, @~[t], @~"foo", @~"foo", @~"foo", @~"foo", @~"foo");
let v = fmt!("%?", u); // this is the line that causes the seg fault
fail_unless!(v.len() > 0);
}

View file

@ -0,0 +1,30 @@
// Copyright 2013 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.
// xfail-test
// aux-build:issue_3907_1.rs
extern mod issue_3907_1;
type Foo = issue_3907_1::Foo;
struct S {
name: int
}
impl Foo for S {
fn bar() { }
}
fn main() {
let s = S {
name: 0
};
s.bar();
}

View file

@ -0,0 +1,126 @@
// Copyright 2013 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.
extern mod std;
use std::net::tcp::TcpSocketBuf;
use core::io::{ReaderUtil,WriterUtil};
enum Result {
Nil,
Int(int),
Data(~[u8]),
List(~[Result]),
Error(~str),
Status(~str)
}
priv fn parse_data(len: uint, io: @io::Reader) -> Result {
let res =
if (len > 0) {
let bytes = io.read_bytes(len as uint);
fail_unless!(bytes.len() == len);
Data(bytes)
} else {
Data(~[])
};
fail_unless!(io.read_char() == '\r');
fail_unless!(io.read_char() == '\n');
return res;
}
priv fn parse_list(len: uint, io: @io::Reader) -> Result {
let mut list: ~[Result] = ~[];
for len.times {
let v =
match io.read_char() {
'$' => parse_bulk(io),
':' => parse_int(io),
_ => fail!()
};
list.push(v);
}
return List(list);
}
priv fn chop(s: ~str) -> ~str {
s.slice(0, s.len() - 1).to_owned()
}
priv fn parse_bulk(io: @io::Reader) -> Result {
match int::from_str(chop(io.read_line())) {
None => fail!(),
Some(-1) => Nil,
Some(len) if len >= 0 => parse_data(len as uint, io),
Some(_) => fail!()
}
}
priv fn parse_multi(io: @io::Reader) -> Result {
match int::from_str(chop(io.read_line())) {
None => fail!(),
Some(-1) => Nil,
Some(0) => List(~[]),
Some(len) if len >= 0 => parse_list(len as uint, io),
Some(_) => fail!()
}
}
priv fn parse_int(io: @io::Reader) -> Result {
match int::from_str(chop(io.read_line())) {
None => fail!(),
Some(i) => Int(i)
}
}
priv fn parse_response(io: @io::Reader) -> Result {
match io.read_char() {
'$' => parse_bulk(io),
'*' => parse_multi(io),
'+' => Status(chop(io.read_line())),
'-' => Error(chop(io.read_line())),
':' => parse_int(io),
_ => fail!()
}
}
priv fn cmd_to_str(cmd: ~[~str]) -> ~str {
let mut res = ~"*";
str::push_str(&mut res, cmd.len().to_str());
str::push_str(&mut res, "\r\n");
for cmd.each |s| {
str::push_str(&mut res, str::concat(~[~"$", s.len().to_str(), ~"\r\n",
copy *s, ~"\r\n"]));
}
res
}
fn query(cmd: ~[~str], sb: TcpSocketBuf) -> Result {
let cmd = cmd_to_str(cmd);
//io::println(cmd);
sb.write_str(cmd);
let res = parse_response(@sb as @io::Reader);
//io::println(fmt!("%?", res));
res
}
fn query2(cmd: ~[~str]) -> Result {
let _cmd = cmd_to_str(cmd);
do io::with_str_reader(~"$3\r\nXXX\r\n") |sb| {
let res = parse_response(@sb as @io::Reader);
io::println(fmt!("%?", res));
res
}
}
fn main() {
}

View file

@ -0,0 +1,37 @@
// Copyright 2013 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.
// xfail-test
trait X {
fn call(&self);
}
struct Y;
struct Z<T> {
x: T
}
impl X for Y {
fn call(&self) {
}
}
impl<T: X> Drop for Z<T> {
fn finalize(&self) {
self.x.call(); // Adding this statement causes an ICE.
}
}
fn main() {
let y = Y;
let _z = Z{x: y};
}

View file

@ -0,0 +1,13 @@
// Copyright 2013 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.
fn main() {
let foo = [0, ..2*4];
}

View file

@ -0,0 +1,22 @@
// Copyright 2013 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.
// xfail-test
// See #3283
fn foo(blk: &fn(p: &'a fn() -> &'a fn())) {
let mut state = 0;
let statep = &mut state;
do blk {
|| { *statep = 1; }
}
}
fn main() {
do foo |p| { p()() }
}