Skip to content

Commit

Permalink
Add mock_runtime_test for deno_last_exception.
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Jul 24, 2018
1 parent 7baf8a0 commit b87e6d5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
3 changes: 1 addition & 2 deletions js/mock_runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ global.SendSuccess = () => {
});
};

global.SendByteLength = () => {
global.SendWrongByteLength = () => {
deno.recv(msg => {
assert(msg instanceof ArrayBuffer);
assert(msg.byteLength === 3);
});
};
Expand Down
9 changes: 6 additions & 3 deletions src/mock_runtime_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,14 @@ TEST(MockRuntimeTest, SendSuccess) {
deno_delete(d);
}

TEST(MockRuntimeTest, SendByteLength) {
TEST(MockRuntimeTest, SendWrongByteLength) {
Deno* d = deno_new(nullptr, nullptr);
EXPECT_TRUE(deno_execute(d, "a.js", "SendByteLength()"));
// We pub the wrong sized message, it should throw.
EXPECT_TRUE(deno_execute(d, "a.js", "SendWrongByteLength()"));
// deno_send the wrong sized message, it should throw.
EXPECT_FALSE(deno_send(d, strbuf("abcd")));
std::string exception = deno_last_exception(d);
EXPECT_GT(exception.length(), 1);
EXPECT_NE(exception.find("assert"), std::string::npos);
deno_delete(d);
}

Expand Down

0 comments on commit b87e6d5

Please sign in to comment.