-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for decorating functions with rescue clauses on Elixir 1.5
Fixes #11
- Loading branch information
Arjan Scherpenisse
committed
Jul 4, 2017
1 parent
e53641d
commit ffee591
Showing
2 changed files
with
57 additions
and
10 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
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,35 @@ | ||
# two arguments | ||
defmodule DecoratorTest.Fixture.ExceptionDecorator do | ||
use Decorator.Define, [test: 0] | ||
|
||
def test(body, _context) do | ||
{:ok, body} | ||
end | ||
|
||
end | ||
|
||
defmodule DecoratorTest.Fixture.ExceptionTestModule do | ||
use DecoratorTest.Fixture.ExceptionDecorator | ||
|
||
@decorate test() | ||
def result(a) do | ||
if a == :throw do | ||
raise RuntimeError, "text" | ||
end | ||
a | ||
rescue | ||
_ in RuntimeError -> | ||
:error | ||
end | ||
end | ||
|
||
defmodule DecoratorTest.Exception do | ||
use ExUnit.Case | ||
|
||
alias DecoratorTest.Fixture.ExceptionTestModule | ||
|
||
test "Functions which have a 'rescue' clause" do | ||
assert {:ok, 3} = ExceptionTestModule.result(3) | ||
assert {:ok, :error} = ExceptionTestModule.result(:throw) | ||
end | ||
end |