From 9838a7ec5497d7d031354f77b578a7fa071129fe Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Sat, 10 Mar 2012 20:38:03 -0800 Subject: [PATCH] Tweak some test cases and add a few new ones --- .../block-must-not-have-result-do.rs | 4 +- .../block-must-not-have-result-while.rs | 2 +- src/test/compile-fail/do-while-constraints.rs | 4 +- .../compile-fail/do-while-pred-constraints.rs | 4 +- src/test/compile-fail/unreachable-code.rs | 6 +++ src/test/run-pass/loop-break-cont-1.rs | 7 ++++ src/test/run-pass/loop-break-cont.rs | 40 +++++++++++++++++++ src/test/run-pass/terminate-in-initializer.rs | 2 +- 8 files changed, 61 insertions(+), 8 deletions(-) create mode 100644 src/test/compile-fail/unreachable-code.rs create mode 100644 src/test/run-pass/loop-break-cont-1.rs create mode 100644 src/test/run-pass/loop-break-cont.rs diff --git a/src/test/compile-fail/block-must-not-have-result-do.rs b/src/test/compile-fail/block-must-not-have-result-do.rs index f842b0f02b4..da006921267 100644 --- a/src/test/compile-fail/block-must-not-have-result-do.rs +++ b/src/test/compile-fail/block-must-not-have-result-do.rs @@ -1,7 +1,7 @@ // error-pattern:mismatched types: expected `()` but found `bool` fn main() { - do { + loop { true - } while true; + } } \ No newline at end of file diff --git a/src/test/compile-fail/block-must-not-have-result-while.rs b/src/test/compile-fail/block-must-not-have-result-while.rs index da006921267..7f172998c28 100644 --- a/src/test/compile-fail/block-must-not-have-result-while.rs +++ b/src/test/compile-fail/block-must-not-have-result-while.rs @@ -1,7 +1,7 @@ // error-pattern:mismatched types: expected `()` but found `bool` fn main() { - loop { + while true { true } } \ No newline at end of file diff --git a/src/test/compile-fail/do-while-constraints.rs b/src/test/compile-fail/do-while-constraints.rs index 5464738294f..a9153338123 100644 --- a/src/test/compile-fail/do-while-constraints.rs +++ b/src/test/compile-fail/do-while-constraints.rs @@ -3,8 +3,8 @@ fn main() { let y: int = 42; let x: int; - do { + loop { log(debug, y); do { do { do { x <- y; } while true } while true } while true - } while true + } } diff --git a/src/test/compile-fail/do-while-pred-constraints.rs b/src/test/compile-fail/do-while-pred-constraints.rs index 027574c024c..03d00dd02e8 100644 --- a/src/test/compile-fail/do-while-pred-constraints.rs +++ b/src/test/compile-fail/do-while-pred-constraints.rs @@ -7,8 +7,8 @@ pure fn even(y: int) -> bool { true } fn main() { let y: int = 42; check (even(y)); - do { + loop { print_even(y); do { do { do { y += 1; } while false } while false } while false - } while true + } } diff --git a/src/test/compile-fail/unreachable-code.rs b/src/test/compile-fail/unreachable-code.rs new file mode 100644 index 00000000000..e2ecb671372 --- /dev/null +++ b/src/test/compile-fail/unreachable-code.rs @@ -0,0 +1,6 @@ +// error-pattern:unreachable statement +fn main() { + loop{} + // red herring to make sure compilation fails + log(error, 42 == 'c'); +} \ No newline at end of file diff --git a/src/test/run-pass/loop-break-cont-1.rs b/src/test/run-pass/loop-break-cont-1.rs new file mode 100644 index 00000000000..b2cd8641f22 --- /dev/null +++ b/src/test/run-pass/loop-break-cont-1.rs @@ -0,0 +1,7 @@ +fn main() { + let i = 0u; + loop { + break; + } + assert true; +} \ No newline at end of file diff --git a/src/test/run-pass/loop-break-cont.rs b/src/test/run-pass/loop-break-cont.rs new file mode 100644 index 00000000000..c40bfb7bfed --- /dev/null +++ b/src/test/run-pass/loop-break-cont.rs @@ -0,0 +1,40 @@ +// xfail-test +// runs forever for some reason -- investigating +fn main() { + let i = 0u; + loop { + log(error, "a"); + i += 1u; + if i == 10u { + break; + } + } + assert (i == 10u); + let is_even = false; + loop { + log(error, "b"); + is_even = false; + i += 1u; + if i % 2u != 0u { + cont; + } + is_even = true; + if i == 21u { + break; + } + } + assert !is_even; + loop { + log(error, "c"); + is_even = false; + if i == 22u { + break; + } + i += 1u; + if i % 2u != 0u { + cont; + } + is_even = true; + } + assert is_even; +} \ No newline at end of file diff --git a/src/test/run-pass/terminate-in-initializer.rs b/src/test/run-pass/terminate-in-initializer.rs index 11e5ca3f645..90c51e984c0 100644 --- a/src/test/run-pass/terminate-in-initializer.rs +++ b/src/test/run-pass/terminate-in-initializer.rs @@ -1,6 +1,6 @@ // xfail-win32 leaks // Issue #787 -// Don't try to clean up uninitizaed locals +// Don't try to clean up uninitialized locals use std;