-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for cross-crate condition handling. Close #5446.
- Loading branch information
Showing
8 changed files
with
215 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright 2012 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. | ||
|
||
#[crate_type="lib"]; | ||
|
||
condition! { | ||
pub oops: int -> int; | ||
} | ||
|
||
pub fn trouble() -> int { | ||
oops::cond.raise(1) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright 2012 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. | ||
|
||
#[crate_type="lib"]; | ||
|
||
condition! { | ||
pub oops: int -> int; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright 2012 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. | ||
|
||
#[crate_type="lib"]; | ||
|
||
condition! { | ||
pub oops: int -> int; | ||
} | ||
|
||
pub fn guard(k: extern fn() -> int, x: int) -> int { | ||
do oops::cond.trap(|i| i*x).inside { | ||
k() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright 2012 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. | ||
|
||
#[crate_type="lib"]; | ||
|
||
#[deriving(Eq)] | ||
pub enum Color { | ||
Red, Green, Blue | ||
} | ||
|
||
condition! { | ||
pub oops: (int,float,~str) -> ::Color; | ||
} | ||
|
||
pub trait Thunk<T> { | ||
fn call(self) -> T; | ||
} | ||
|
||
pub fn callback<T,TH:Thunk<T>>(t:TH) -> T { | ||
t.call() | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2012 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-fast | ||
// aux-build:xc_conditions.rs | ||
|
||
extern mod xc_conditions; | ||
use xc_conditions::oops; | ||
use xc_conditions::trouble; | ||
|
||
// Tests of cross-crate conditions; the condition is | ||
// defined in lib, and we test various combinations | ||
// of `trap` and `raise` in the client or the lib where | ||
// the condition was defined. Also in test #4 we use | ||
// more complex features (generics, traits) in | ||
// combination with the condition. | ||
// | ||
// trap raise | ||
// ------------ | ||
// xc_conditions : client lib | ||
// xc_conditions_2: client client | ||
// xc_conditions_3: lib client | ||
// xc_conditions_4: client client (with traits) | ||
// | ||
// the trap=lib, raise=lib case isn't tested since | ||
// there's no cross-crate-ness to test in that case. | ||
|
||
pub fn main() { | ||
do oops::cond.trap(|_i| 12345).inside { | ||
let x = trouble(); | ||
assert_eq!(x,12345); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright 2012 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-fast | ||
// aux-build:xc_conditions_2.rs | ||
|
||
extern mod xc_conditions_2; | ||
use xcc = xc_conditions_2; | ||
|
||
pub fn main() { | ||
do xcc::oops::cond.trap(|_| 1).inside { | ||
xcc::oops::cond.raise(1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright 2012 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-fast | ||
// aux-build:xc_conditions_3.rs | ||
|
||
extern mod xc_conditions_3; | ||
use xcc = xc_conditions_3; | ||
|
||
pub fn main() { | ||
assert_eq!(xcc::guard(a, 1), 40); | ||
} | ||
|
||
pub fn a() -> int { | ||
assert_eq!(xcc::oops::cond.raise(7), 7); | ||
xcc::guard(b, 2) | ||
} | ||
|
||
pub fn b() -> int { | ||
assert_eq!(xcc::oops::cond.raise(8), 16); | ||
xcc::guard(c, 3) | ||
} | ||
|
||
pub fn c() -> int { | ||
assert_eq!(xcc::oops::cond.raise(9), 18); | ||
xcc::guard(d, 4) | ||
} | ||
|
||
pub fn d() -> int { | ||
xcc::oops::cond.raise(10) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2012 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-fast | ||
// aux-build:xc_conditions_4.rs | ||
|
||
extern mod xc_conditions_4; | ||
use xcc = xc_conditions_4; | ||
|
||
struct SThunk { | ||
x: int | ||
} | ||
|
||
impl xcc::Thunk<xcc::Color> for SThunk { | ||
fn call(self) -> xcc::Color { | ||
xcc::oops::cond.raise((self.x, 1.23, ~"oh no")) | ||
} | ||
} | ||
|
||
pub fn main() { | ||
do xcc::oops::cond.trap(|_| xcc::Red).inside { | ||
let t = SThunk { x : 10 }; | ||
assert_eq!(xcc::callback(t), xcc::Red) | ||
} | ||
} |
07f48a5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
saw approval from thestinger
at graydon@07f48a5
07f48a5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merging graydon/rust/2013-08-01-testcases-for-fixed-bugs = 07f48a5 into auto
07f48a5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
graydon/rust/2013-08-01-testcases-for-fixed-bugs = 07f48a5 merged ok, testing candidate = 1571a763
07f48a5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some tests failed:
failure: http://buildbot.rust-lang.org/builders/auto-linux-32-opt/builds/726
exception: http://buildbot.rust-lang.org/builders/auto-mac-32-opt/builds/708
exception: http://buildbot.rust-lang.org/builders/auto-mac-64-opt/builds/711
exception: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt/builds/712
exception: http://buildbot.rust-lang.org/builders/auto-mac-64-opt-vg/builds/705
exception: http://buildbot.rust-lang.org/builders/auto-mac-all-opt/builds/708
exception: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt/builds/728
exception: http://buildbot.rust-lang.org/builders/auto-linux-64-opt/builds/726
exception: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt/builds/730
exception: http://buildbot.rust-lang.org/builders/auto-linux-64-opt-vg/builds/735
exception: http://buildbot.rust-lang.org/builders/auto-linux-all-opt/builds/728
exception: http://buildbot.rust-lang.org/builders/auto-win-32-opt/builds/711
exception: http://buildbot.rust-lang.org/builders/auto-win-32-nopt/builds/725
exception: http://buildbot.rust-lang.org/builders/auto-bsd-64-opt/builds/499