From f99cf2d62f5cdf1075e7e2bb100112100a75242e Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 7 Sep 2011 17:01:24 -0700 Subject: [PATCH] Add a number of unwinding tests Issue #236 --- src/test/run-fail/unwind-assert.rs | 6 ++++++ src/test/run-fail/unwind-check.rs | 8 ++++++++ src/test/run-fail/unwind-closure.rs | 10 ++++++++++ src/test/run-fail/unwind-initializer.rs | 7 +++++++ src/test/run-fail/unwind-iter.rs | 12 ++++++++++++ src/test/run-fail/unwind-nested.rs | 11 +++++++++++ src/test/run-fail/unwind-stacked.rs | 16 ++++++++++++++++ src/test/run-fail/unwind-uninitialized.rs | 10 ++++++++++ src/test/run-pass/unwind-box.rs | 13 +++++++++++++ src/test/run-pass/unwind-resource.rs | 20 ++++++++++++++++++++ src/test/run-pass/unwind-resource2.rs | 17 +++++++++++++++++ 11 files changed, 130 insertions(+) create mode 100644 src/test/run-fail/unwind-assert.rs create mode 100644 src/test/run-fail/unwind-check.rs create mode 100644 src/test/run-fail/unwind-closure.rs create mode 100644 src/test/run-fail/unwind-initializer.rs create mode 100644 src/test/run-fail/unwind-iter.rs create mode 100644 src/test/run-fail/unwind-nested.rs create mode 100644 src/test/run-fail/unwind-stacked.rs create mode 100644 src/test/run-fail/unwind-uninitialized.rs create mode 100644 src/test/run-pass/unwind-box.rs create mode 100644 src/test/run-pass/unwind-resource.rs create mode 100644 src/test/run-pass/unwind-resource2.rs diff --git a/src/test/run-fail/unwind-assert.rs b/src/test/run-fail/unwind-assert.rs new file mode 100644 index 00000000000..e7aeedcf505 --- /dev/null +++ b/src/test/run-fail/unwind-assert.rs @@ -0,0 +1,6 @@ +// error-pattern:fail + +fn main() { + let a = @0; + assert false; +} \ No newline at end of file diff --git a/src/test/run-fail/unwind-check.rs b/src/test/run-fail/unwind-check.rs new file mode 100644 index 00000000000..e01cc969cea --- /dev/null +++ b/src/test/run-fail/unwind-check.rs @@ -0,0 +1,8 @@ +// error-pattern:fail + +pure fn p(a: @int) -> bool { false } + +fn main() { + let a = @0; + check p(a); +} \ No newline at end of file diff --git a/src/test/run-fail/unwind-closure.rs b/src/test/run-fail/unwind-closure.rs new file mode 100644 index 00000000000..216ae054947 --- /dev/null +++ b/src/test/run-fail/unwind-closure.rs @@ -0,0 +1,10 @@ +// error-pattern:fail + +fn f(a: @int) { + fail; +} + +fn main() { + let g = bind f(@0); + g(); +} \ No newline at end of file diff --git a/src/test/run-fail/unwind-initializer.rs b/src/test/run-fail/unwind-initializer.rs new file mode 100644 index 00000000000..b3dc0d3eaeb --- /dev/null +++ b/src/test/run-fail/unwind-initializer.rs @@ -0,0 +1,7 @@ +// error-pattern:fail + +fn main() { + let a: @int = { + fail; + }; +} \ No newline at end of file diff --git a/src/test/run-fail/unwind-iter.rs b/src/test/run-fail/unwind-iter.rs new file mode 100644 index 00000000000..fa64b0ad78c --- /dev/null +++ b/src/test/run-fail/unwind-iter.rs @@ -0,0 +1,12 @@ +// error-pattern:fail + +iter x() -> int { + fail; + put 0; +} + +fn main() { + let a = @0; + for each x in x() { + } +} \ No newline at end of file diff --git a/src/test/run-fail/unwind-nested.rs b/src/test/run-fail/unwind-nested.rs new file mode 100644 index 00000000000..48e3063c6dd --- /dev/null +++ b/src/test/run-fail/unwind-nested.rs @@ -0,0 +1,11 @@ +// error-pattern:fail + +fn main() { + let a = @0; + { + let b = @0; + { + fail; + } + } +} \ No newline at end of file diff --git a/src/test/run-fail/unwind-stacked.rs b/src/test/run-fail/unwind-stacked.rs new file mode 100644 index 00000000000..bf5258cee7d --- /dev/null +++ b/src/test/run-fail/unwind-stacked.rs @@ -0,0 +1,16 @@ +// error-pattern:fail + +fn f() { + let a = @0; + fail; +} + +fn g() { + let b = @0; + f(); +} + +fn main() { + let a = @0; + g(); +} \ No newline at end of file diff --git a/src/test/run-fail/unwind-uninitialized.rs b/src/test/run-fail/unwind-uninitialized.rs new file mode 100644 index 00000000000..35269b38714 --- /dev/null +++ b/src/test/run-fail/unwind-uninitialized.rs @@ -0,0 +1,10 @@ +// error-pattern:fail + +fn f() { + fail; +} + +fn main() { + f(); + let a = @0; +} \ No newline at end of file diff --git a/src/test/run-pass/unwind-box.rs b/src/test/run-pass/unwind-box.rs new file mode 100644 index 00000000000..692a62c8272 --- /dev/null +++ b/src/test/run-pass/unwind-box.rs @@ -0,0 +1,13 @@ +use std; +import std::task; + +fn f() { + task::unsupervise(); + let a = @0; + fail; +} + +fn main() { + let g = f; + task::spawn(g); +} \ No newline at end of file diff --git a/src/test/run-pass/unwind-resource.rs b/src/test/run-pass/unwind-resource.rs new file mode 100644 index 00000000000..cd25e43dfce --- /dev/null +++ b/src/test/run-pass/unwind-resource.rs @@ -0,0 +1,20 @@ +use std; +import std::task; +import std::comm; + +resource complainer(c: comm::chan) { + comm::send(c, true); +} + +fn f(c: -comm::chan) { + task::unsupervise(); + let c <- complainer(c); + fail; +} + +fn main() { + let p = comm::port(); + let c = comm::chan(p); + task::spawn(bind f(c)); + assert comm::recv(p); +} \ No newline at end of file diff --git a/src/test/run-pass/unwind-resource2.rs b/src/test/run-pass/unwind-resource2.rs new file mode 100644 index 00000000000..d2797f5154a --- /dev/null +++ b/src/test/run-pass/unwind-resource2.rs @@ -0,0 +1,17 @@ +use std; +import std::task; +import std::comm; + +resource complainer(c: @int) { +} + +fn f() { + task::unsupervise(); + let c <- complainer(@0); + fail; +} + +fn main() { + let g = f; + task::spawn(g); +} \ No newline at end of file