-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into merge-in-rustler-sys
- Loading branch information
Showing
9 changed files
with
64 additions
and
12 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
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
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,30 @@ | ||
use rustler::{Decoder, Encoder, Env, Term}; | ||
|
||
#[rustler::nif] | ||
pub fn panic_in_nif() -> i32 { | ||
panic!("panic!") | ||
} | ||
|
||
struct Panicking; | ||
|
||
impl Encoder for Panicking { | ||
fn encode<'a>(&self, _env: Env<'a>) -> Term<'a> { | ||
panic!("panic in encode!") | ||
} | ||
} | ||
|
||
impl<'a> Decoder<'a> for Panicking { | ||
fn decode(_term: Term<'a>) -> rustler::NifResult<Self> { | ||
panic!("panic in decode!") | ||
} | ||
} | ||
|
||
#[rustler::nif] | ||
pub fn panic_in_encode() -> Panicking { | ||
Panicking | ||
} | ||
|
||
#[rustler::nif] | ||
pub fn panic_in_decode(_p: Panicking) -> i32 { | ||
0 | ||
} |
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,12 @@ | ||
defmodule PanicTest do | ||
use ExUnit.Case | ||
|
||
test "panics in NIFs are caught" do | ||
assert_raise ErlangError, &RustlerTest.panic_in_nif/0 | ||
assert_raise ErlangError, &RustlerTest.panic_in_encode/0 | ||
|
||
assert_raise ErlangError, fn -> | ||
RustlerTest.panic_in_decode(:anything) | ||
end | ||
end | ||
end |