Skip to content

Commit

Permalink
Allow fail messages to be caught, and introduce the Any trait
Browse files Browse the repository at this point in the history
Some code cleanup, sorting of import blocks

Removed std::unstable::UnsafeArc's use of Either

Added run-fail tests for the new FailWithCause impls

Changed future_result and try to return Result<(), ~Any>.

- Internally, there is an enum of possible fail messages passend around.
- In case of linked failure or a string message, the ~Any gets
  lazyly allocated in future_results recv method.
- For that, future result now returns a wrapper around a Port.
- Moved and renamed task::TaskResult into rt::task::UnwindResult
  and made it an internal enum.
- Introduced a replacement typedef `type TaskResult = Result<(), ~Any>`.
  • Loading branch information
Kimundi committed Oct 28, 2013
1 parent cb5b21e commit fa8e71a
Show file tree
Hide file tree
Showing 24 changed files with 912 additions and 214 deletions.
8 changes: 4 additions & 4 deletions src/libextra/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ mod tests {
let m = Mutex::new();
let m2 = m.clone();

let result: result::Result<(),()> = do task::try {
let result: result::Result<(), ~Any> = do task::try {
do m2.lock {
fail!();
}
Expand All @@ -935,7 +935,7 @@ mod tests {
let m = Mutex::new();
let m2 = m.clone();

let result: result::Result<(),()> = do task::try {
let result: result::Result<(), ~Any> = do task::try {
let (p, c) = comm::stream();
do task::spawn || { // linked
let _ = p.recv(); // wait for sibling to get in the mutex
Expand Down Expand Up @@ -963,7 +963,7 @@ mod tests {
let m2 = m.clone();
let (p, c) = comm::stream();

let result: result::Result<(),()> = do task::try {
let result: result::Result<(), ~Any> = do task::try {
let mut sibling_convos = ~[];
do 2.times {
let (p, c) = comm::stream();
Expand Down Expand Up @@ -1272,7 +1272,7 @@ mod tests {
let x = RWLock::new();
let x2 = x.clone();

let result: result::Result<(),()> = do task::try || {
let result: result::Result<(), ~Any> = do task::try || {
do lock_rwlock_in_mode(&x2, mode1) {
fail!();
}
Expand Down
3 changes: 1 addition & 2 deletions src/libextra/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -873,8 +873,7 @@ pub fn run_test(force_ignore: bool,
task.spawn(testfn_cell.take());

let task_result = result_future.recv();
let test_result = calc_result(&desc,
task_result == task::Success);
let test_result = calc_result(&desc, task_result.is_ok());
monitor_ch.send((desc.clone(), test_result));
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/librustpkg/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -640,9 +640,8 @@ fn test_install_invalid() {
pkgid.clone());
ctxt.install(pkg_src, &WhatToBuild::new(MaybeCustom, Everything));
};
// Not the best test -- doesn't test that we failed in the right way.
// Best we can do for now.
assert!(result == Err(()));
assert!(result.unwrap_err()
.to_str().contains("supplied path for package dir does not exist"));
}

#[test]
Expand Down
Loading

5 comments on commit fa8e71a

@bors
Copy link
Contributor

@bors bors commented on fa8e71a Oct 28, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from huonw
at Kimundi@fa8e71a

@bors
Copy link
Contributor

@bors bors commented on fa8e71a Oct 28, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging Kimundi/rust/fail_cause_two = fa8e71a into auto

@bors
Copy link
Contributor

@bors bors commented on fa8e71a Oct 28, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kimundi/rust/fail_cause_two = fa8e71a merged ok, testing candidate = 9ef23e9

@bors
Copy link
Contributor

@bors bors commented on fa8e71a Oct 28, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on fa8e71a Oct 28, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 9ef23e9

Please sign in to comment.