Skip to content

Commit 7b4eec2

Browse files
committed
Some tests for ! annotations
1 parent a1b440b commit 7b4eec2

File tree

4 files changed

+58
-0
lines changed

4 files changed

+58
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// -*- rust -*-
2+
// xfail-stage0
3+
// Tests that a function with a ! annotation always actually fails
4+
// error-pattern: some control paths may return
5+
6+
fn bad_bang(uint i) -> ! {
7+
log 3;
8+
}
9+
10+
fn main() {
11+
bad_bang(5u);
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// -*- rust -*-
2+
// xfail-stage0
3+
// Tests that a function with a ! annotation always actually fails
4+
// error-pattern: some control paths may return
5+
6+
fn bad_bang(uint i) -> ! {
7+
ret 7u;
8+
}
9+
10+
fn main() {
11+
bad_bang(5u);
12+
}

src/test/compile-fail/bad-bang-ann.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// -*- rust -*-
2+
// xfail-stage0
3+
// Tests that a function with a ! annotation always actually fails
4+
// error-pattern: may return to the caller
5+
6+
fn bad_bang(uint i) -> ! {
7+
if (i < 0u) {
8+
}
9+
else {
10+
fail;
11+
}
12+
}
13+
14+
fn main() {
15+
bad_bang(5u);
16+
}

src/test/run-pass/ret-bang.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// -*- rust -*-
2+
fn my_err(str s) -> ! {
3+
log_err s;
4+
fail;
5+
}
6+
7+
fn okay(uint i) -> int {
8+
if (i == 3u) {
9+
my_err("I don't like three");
10+
}
11+
else {
12+
ret 42;
13+
}
14+
}
15+
16+
fn main() {
17+
okay(4u);
18+
}

0 commit comments

Comments
 (0)