forked from JuliaLang/julia
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ec6f886
commit 2ca8142
Showing
5 changed files
with
132 additions
and
1 deletion.
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
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
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
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
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,72 @@ | ||
# This file is a part of Julia. License is MIT: http://julialang.org/license | ||
|
||
|
||
@test map(typeof, map(@catch(i->[1,2,3][i]), 1:6)) == | ||
[Int, Int, Int, BoundsError, BoundsError, BoundsError] | ||
|
||
@test typeof(@catch(open)("/no/file/with/this/name")) == SystemError | ||
|
||
|
||
let | ||
|
||
function f(c, n) | ||
c[1] += 1 | ||
if c[1] <= n | ||
error("foo") | ||
end | ||
return 7 | ||
end | ||
|
||
# Success on first attempt... | ||
c = [0] | ||
@test retry(f)(c,0) == 7 | ||
@test c[1] == 1 | ||
|
||
# Success on second attempt... | ||
c = [0] | ||
@test retry(f)(c,1) == 7 | ||
@test c[1] == 2 | ||
|
||
# Success on third attempt... | ||
c = [0] | ||
@test retry(f)(c,2) == 7 | ||
@test c[1] == 3 | ||
|
||
# 3 failed attempts, so exception is raised... | ||
c = [0] | ||
ex = @catch(retry(f))(c,3) | ||
@test ex.msg == "foo" | ||
@test c[1] == 3 | ||
|
||
c = [0] | ||
ex = @catch(retry(f, ErrorException))(c,3) | ||
@test typeof(ex) == ErrorException | ||
@test ex.msg == "foo" | ||
@test c[1] == 3 | ||
|
||
c = [0] | ||
ex = @catch(retry(f, e->e.msg == "foo"))(c,3) | ||
@test typeof(ex) == ErrorException | ||
@test ex.msg == "foo" | ||
@test c[1] == 3 | ||
|
||
# No retry if condition does not match... | ||
c = [0] | ||
ex = @catch(retry(f, e->e.msg == "bar"))(c,3) | ||
@test typeof(ex) == ErrorException | ||
@test ex.msg == "foo" | ||
@test c[1] == 1 | ||
|
||
c = [0] | ||
ex = @catch(retry(f, e->e.http_status_code == "503"))(c,3) | ||
@test typeof(ex) == ErrorException | ||
@test ex.msg == "foo" | ||
@test c[1] == 1 | ||
|
||
c = [0] | ||
ex = @catch(retry(f, SystemError))(c,3) | ||
@test typeof(ex) == ErrorException | ||
@test ex.msg == "foo" | ||
@test c[1] == 1 | ||
|
||
end |