Skip to content

Commit e01cf3c

Browse files
committed
testsuite: Add various test cases
Some are xfailed, some not, some existing ones get un-xfailed.
1 parent b93393e commit e01cf3c

15 files changed

+383
-13
lines changed

src/test/auxiliary/issue_3907_1.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub trait Foo {
2+
fn bar();
3+
}

src/test/compile-fail/issue-3820.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,19 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// xfail-test
1211
struct Thing {
1312
x: int
1413
}
1514

16-
impl Mul<int, Thing>*/ for Thing/* { //~ ERROR Look ma, no Mul!
17-
fn mul(c: &int) -> Thing {
15+
impl Thing {
16+
fn mul(&self, c: &int) -> Thing {
1817
Thing {x: self.x * *c}
1918
}
2019
}
2120

2221
fn main() {
2322
let u = Thing {x: 2};
24-
let _v = u.mul(&3); // Works
25-
let w = u * 3; // Works!!
23+
let _v = u.mul(&3); // This is ok
24+
let w = u * 3; //~ ERROR binary operation * cannot be applied to type `Thing`
2625
io::println(fmt!("%i", w.x));
27-
28-
/*
29-
// This doesn't work though.
30-
let u2 = u as @Mul<int, Thing>;
31-
let w2 = u2.mul(&4);
32-
io::println(fmt!("%i", w2.x));
33-
*/
3426
}

src/test/compile-fail/issue-3973.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// except according to those terms.
1010

1111
// xfail-test
12-
1312
struct Point {
1413
x: float,
1514
y: float,

src/test/compile-fail/issue-3991.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// xfail-test
12+
struct HasNested {
13+
mut nest: ~[~[int]],
14+
}
15+
16+
impl HasNested {
17+
fn method_push_local(&self) {
18+
self.nest[0].push(0);
19+
}
20+
}
21+
22+
fn main() {}

src/test/compile-fail/issue-4265.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
struct Foo {
12+
baz: uint
13+
}
14+
15+
impl Foo {
16+
fn bar() {
17+
Foo { baz: 0 }.bar();
18+
}
19+
20+
fn bar() { //~ ERROR duplicate definition of value bar
21+
}
22+
}
23+
24+
fn main() {}

src/test/compile-fail/issue-4542.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// xfail-test
12+
13+
fn main() {
14+
for os::args().each |arg| {
15+
match copy *arg {
16+
s => { }
17+
}
18+
}
19+
}

src/test/compile-fail/issue-5035.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// xfail-test
12+
trait I {}
13+
type K = I;
14+
impl K for int {}
15+
fn main() {}

src/test/compile-fail/issue-5062.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// xfail-test
12+
fn main() { fmt!("%?", None); } //~ ERROR can't resolve type variable

src/test/compile-fail/issue-5099.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
12+
trait B < A > { fn a() -> A { self.a} } //~ ERROR unresolved name
13+
14+
fn main() {}

src/test/run-pass/issue-3556.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
extern mod std;
12+
use core::io::WriterUtil;
13+
14+
enum Token {
15+
Text(@~str),
16+
ETag(@~[~str], @~str),
17+
UTag(@~[~str], @~str),
18+
Section(@~[~str], bool, @~[Token], @~str, @~str, @~str, @~str, @~str),
19+
IncompleteSection(@~[~str], bool, @~str, bool),
20+
Partial(@~str, @~str, @~str),
21+
}
22+
23+
fn check_strs(actual: &str, expected: &str) -> bool
24+
{
25+
if actual != expected
26+
{
27+
io::stderr().write_line(fmt!("Found %s, but expected %s", actual, expected));
28+
return false;
29+
}
30+
return true;
31+
}
32+
33+
fn main()
34+
{
35+
// fail_unless!(check_strs(fmt!("%?", Text(@~"foo")), "Text(@~\"foo\")"));
36+
// fail_unless!(check_strs(fmt!("%?", ETag(@~[~"foo"], @~"bar")), "ETag(@~[ ~\"foo\" ], @~\"bar\")"));
37+
38+
let t = Text(@~"foo");
39+
let u = Section(@~[~"alpha"], true, @~[t], @~"foo", @~"foo", @~"foo", @~"foo", @~"foo");
40+
let v = fmt!("%?", u); // this is the line that causes the seg fault
41+
fail_unless!(v.len() > 0);
42+
}

src/test/run-pass/issue-3907-2.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// xfail-test
12+
// aux-build:issue_3907_1.rs
13+
extern mod issue_3907_1;
14+
15+
type Foo = issue_3907_1::Foo;
16+
17+
struct S {
18+
name: int
19+
}
20+
21+
impl Foo for S {
22+
fn bar() { }
23+
}
24+
25+
fn main() {
26+
let s = S {
27+
name: 0
28+
};
29+
s.bar();
30+
}

src/test/run-pass/issue-4241.rs

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
extern mod std;
12+
13+
use std::net::tcp::TcpSocketBuf;
14+
15+
use core::io::{ReaderUtil,WriterUtil};
16+
17+
enum Result {
18+
Nil,
19+
Int(int),
20+
Data(~[u8]),
21+
List(~[Result]),
22+
Error(~str),
23+
Status(~str)
24+
}
25+
26+
priv fn parse_data(len: uint, io: @io::Reader) -> Result {
27+
let res =
28+
if (len > 0) {
29+
let bytes = io.read_bytes(len as uint);
30+
fail_unless!(bytes.len() == len);
31+
Data(bytes)
32+
} else {
33+
Data(~[])
34+
};
35+
fail_unless!(io.read_char() == '\r');
36+
fail_unless!(io.read_char() == '\n');
37+
return res;
38+
}
39+
40+
priv fn parse_list(len: uint, io: @io::Reader) -> Result {
41+
let mut list: ~[Result] = ~[];
42+
for len.times {
43+
let v =
44+
match io.read_char() {
45+
'$' => parse_bulk(io),
46+
':' => parse_int(io),
47+
_ => fail!()
48+
};
49+
list.push(v);
50+
}
51+
return List(list);
52+
}
53+
54+
priv fn chop(s: ~str) -> ~str {
55+
s.slice(0, s.len() - 1).to_owned()
56+
}
57+
58+
priv fn parse_bulk(io: @io::Reader) -> Result {
59+
match int::from_str(chop(io.read_line())) {
60+
None => fail!(),
61+
Some(-1) => Nil,
62+
Some(len) if len >= 0 => parse_data(len as uint, io),
63+
Some(_) => fail!()
64+
}
65+
}
66+
67+
priv fn parse_multi(io: @io::Reader) -> Result {
68+
match int::from_str(chop(io.read_line())) {
69+
None => fail!(),
70+
Some(-1) => Nil,
71+
Some(0) => List(~[]),
72+
Some(len) if len >= 0 => parse_list(len as uint, io),
73+
Some(_) => fail!()
74+
}
75+
}
76+
77+
priv fn parse_int(io: @io::Reader) -> Result {
78+
match int::from_str(chop(io.read_line())) {
79+
None => fail!(),
80+
Some(i) => Int(i)
81+
}
82+
}
83+
84+
priv fn parse_response(io: @io::Reader) -> Result {
85+
match io.read_char() {
86+
'$' => parse_bulk(io),
87+
'*' => parse_multi(io),
88+
'+' => Status(chop(io.read_line())),
89+
'-' => Error(chop(io.read_line())),
90+
':' => parse_int(io),
91+
_ => fail!()
92+
}
93+
}
94+
95+
priv fn cmd_to_str(cmd: ~[~str]) -> ~str {
96+
let mut res = ~"*";
97+
str::push_str(&mut res, cmd.len().to_str());
98+
str::push_str(&mut res, "\r\n");
99+
for cmd.each |s| {
100+
str::push_str(&mut res, str::concat(~[~"$", s.len().to_str(), ~"\r\n",
101+
copy *s, ~"\r\n"]));
102+
}
103+
res
104+
}
105+
106+
fn query(cmd: ~[~str], sb: TcpSocketBuf) -> Result {
107+
let cmd = cmd_to_str(cmd);
108+
//io::println(cmd);
109+
sb.write_str(cmd);
110+
let res = parse_response(@sb as @io::Reader);
111+
//io::println(fmt!("%?", res));
112+
res
113+
}
114+
115+
fn query2(cmd: ~[~str]) -> Result {
116+
let _cmd = cmd_to_str(cmd);
117+
do io::with_str_reader(~"$3\r\nXXX\r\n") |sb| {
118+
let res = parse_response(@sb as @io::Reader);
119+
io::println(fmt!("%?", res));
120+
res
121+
}
122+
}
123+
124+
125+
fn main() {
126+
}

src/test/run-pass/issue-4252.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// xfail-test
12+
13+
trait X {
14+
fn call(&self);
15+
}
16+
17+
struct Y;
18+
19+
struct Z<T> {
20+
x: T
21+
}
22+
23+
impl X for Y {
24+
fn call(&self) {
25+
}
26+
}
27+
28+
impl<T: X> Drop for Z<T> {
29+
fn finalize(&self) {
30+
self.x.call(); // Adding this statement causes an ICE.
31+
}
32+
}
33+
34+
fn main() {
35+
let y = Y;
36+
let _z = Z{x: y};
37+
}

0 commit comments

Comments
 (0)