mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 07:14:47 -05:00
parent
89eee51f07
commit
c7ce450ee9
4 changed files with 30 additions and 30 deletions
18
BUILD.gn
18
BUILD.gn
|
@ -161,7 +161,7 @@ static_library("libdeno") {
|
||||||
configs += [ ":deno_config" ]
|
configs += [ ":deno_config" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
# Only functionality needed for mock_runtime_test and snapshot_creator
|
# Only functionality needed for libdeno_test and snapshot_creator
|
||||||
# In particular no flatbuffers, no assets, no rust, no msg handlers.
|
# In particular no flatbuffers, no assets, no rust, no msg handlers.
|
||||||
# Because snapshots are slow, it's important that snapshot_creator's
|
# Because snapshots are slow, it's important that snapshot_creator's
|
||||||
# dependencies are minimal.
|
# dependencies are minimal.
|
||||||
|
@ -184,17 +184,17 @@ v8_source_set("deno_base_test") {
|
||||||
sources = [
|
sources = [
|
||||||
"src/file_util_test.cc",
|
"src/file_util_test.cc",
|
||||||
"src/from_snapshot.cc",
|
"src/from_snapshot.cc",
|
||||||
"src/mock_runtime_test.cc",
|
"src/libdeno_test.cc",
|
||||||
]
|
]
|
||||||
inputs = [
|
inputs = [
|
||||||
"$target_gen_dir/snapshot_mock_runtime.bin",
|
"$target_gen_dir/snapshot_libdeno_test.bin",
|
||||||
]
|
]
|
||||||
deps = [
|
deps = [
|
||||||
":create_snapshot_mock_runtime",
|
":create_snapshot_libdeno_test",
|
||||||
":deno_base",
|
":deno_base",
|
||||||
"//testing/gtest:gtest",
|
"//testing/gtest:gtest",
|
||||||
]
|
]
|
||||||
defines = [ "DENO_MOCK_RUNTIME" ]
|
defines = [ "LIBDENO_TEST" ]
|
||||||
configs = [ ":deno_config" ]
|
configs = [ ":deno_config" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -353,7 +353,7 @@ rust_flatbuffer("msg_rs") {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
# Generates $target_gen_dir/snapshot_deno.cc
|
# Generates $target_gen_dir/snapshot_deno.bin
|
||||||
create_snapshot("deno") {
|
create_snapshot("deno") {
|
||||||
js = "$target_gen_dir/bundle/main.js"
|
js = "$target_gen_dir/bundle/main.js"
|
||||||
source_map = "$target_gen_dir/bundle/main.js.map"
|
source_map = "$target_gen_dir/bundle/main.js.map"
|
||||||
|
@ -362,8 +362,8 @@ create_snapshot("deno") {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
# Generates $target_gen_dir/snapshot_mock_runtime.cc
|
# Generates $target_gen_dir/snapshot_libdeno_test.bin
|
||||||
create_snapshot("mock_runtime") {
|
create_snapshot("libdeno_test") {
|
||||||
testonly = true
|
testonly = true
|
||||||
js = "js/mock_runtime.js"
|
js = "js/libdeno_test.js"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
// A simple runtime that doesn't involve typescript or protobufs to test
|
// A simple runtime that doesn't involve typescript or protobufs to test
|
||||||
// libdeno. Invoked by mock_runtime_test.cc
|
// libdeno. Invoked by libdeno_test.cc
|
||||||
|
|
||||||
const global = this;
|
const global = this;
|
||||||
|
|
||||||
function assert(cond) {
|
function assert(cond) {
|
||||||
if (!cond) throw Error("mock_runtime.js assert failed");
|
if (!cond) throw Error("libdeno_test.js assert failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
global.CanCallFunction = () => {
|
global.CanCallFunction = () => {
|
|
@ -12,9 +12,9 @@
|
||||||
|
|
||||||
extern const char deno_snapshot_start asm("deno_snapshot_start");
|
extern const char deno_snapshot_start asm("deno_snapshot_start");
|
||||||
extern const char deno_snapshot_end asm("deno_snapshot_end");
|
extern const char deno_snapshot_end asm("deno_snapshot_end");
|
||||||
#ifdef DENO_MOCK_RUNTIME
|
#ifdef LIBDENO_TEST
|
||||||
asm(".data\n"
|
asm(".data\n"
|
||||||
"deno_snapshot_start: .incbin \"gen/snapshot_mock_runtime.bin\"\n"
|
"deno_snapshot_start: .incbin \"gen/snapshot_libdeno_test.bin\"\n"
|
||||||
"deno_snapshot_end:\n"
|
"deno_snapshot_end:\n"
|
||||||
".globl deno_snapshot_start;\n"
|
".globl deno_snapshot_start;\n"
|
||||||
".globl deno_snapshot_end;");
|
".globl deno_snapshot_end;");
|
||||||
|
@ -24,7 +24,7 @@ asm(".data\n"
|
||||||
"deno_snapshot_end:\n"
|
"deno_snapshot_end:\n"
|
||||||
".globl deno_snapshot_start;\n"
|
".globl deno_snapshot_start;\n"
|
||||||
".globl deno_snapshot_end;");
|
".globl deno_snapshot_end;");
|
||||||
#endif // DENO_MOCK_RUNTIME
|
#endif // LIBDENO_TEST
|
||||||
|
|
||||||
namespace deno {
|
namespace deno {
|
||||||
|
|
||||||
|
|
|
@ -3,20 +3,20 @@
|
||||||
|
|
||||||
#include "deno.h"
|
#include "deno.h"
|
||||||
|
|
||||||
TEST(MockRuntimeTest, InitializesCorrectly) {
|
TEST(LibDenoTest, InitializesCorrectly) {
|
||||||
Deno* d = deno_new(nullptr, nullptr);
|
Deno* d = deno_new(nullptr, nullptr);
|
||||||
EXPECT_TRUE(deno_execute(d, "a.js", "1 + 2"));
|
EXPECT_TRUE(deno_execute(d, "a.js", "1 + 2"));
|
||||||
deno_delete(d);
|
deno_delete(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(MockRuntimeTest, CanCallFunction) {
|
TEST(LibDenoTest, CanCallFunction) {
|
||||||
Deno* d = deno_new(nullptr, nullptr);
|
Deno* d = deno_new(nullptr, nullptr);
|
||||||
EXPECT_TRUE(deno_execute(d, "a.js",
|
EXPECT_TRUE(deno_execute(d, "a.js",
|
||||||
"if (CanCallFunction() != 'foo') throw Error();"));
|
"if (CanCallFunction() != 'foo') throw Error();"));
|
||||||
deno_delete(d);
|
deno_delete(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(MockRuntimeTest, ErrorsCorrectly) {
|
TEST(LibDenoTest, ErrorsCorrectly) {
|
||||||
Deno* d = deno_new(nullptr, nullptr);
|
Deno* d = deno_new(nullptr, nullptr);
|
||||||
EXPECT_FALSE(deno_execute(d, "a.js", "throw Error()"));
|
EXPECT_FALSE(deno_execute(d, "a.js", "throw Error()"));
|
||||||
deno_delete(d);
|
deno_delete(d);
|
||||||
|
@ -45,14 +45,14 @@ deno_buf StrBufNullAllocPtr(const char* str) {
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(MockRuntimeTest, SendSuccess) {
|
TEST(LibDenoTest, SendSuccess) {
|
||||||
Deno* d = deno_new(nullptr, nullptr);
|
Deno* d = deno_new(nullptr, nullptr);
|
||||||
EXPECT_TRUE(deno_execute(d, "a.js", "SendSuccess()"));
|
EXPECT_TRUE(deno_execute(d, "a.js", "SendSuccess()"));
|
||||||
EXPECT_TRUE(deno_send(d, strbuf("abc")));
|
EXPECT_TRUE(deno_send(d, strbuf("abc")));
|
||||||
deno_delete(d);
|
deno_delete(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(MockRuntimeTest, SendWrongByteLength) {
|
TEST(LibDenoTest, SendWrongByteLength) {
|
||||||
Deno* d = deno_new(nullptr, nullptr);
|
Deno* d = deno_new(nullptr, nullptr);
|
||||||
EXPECT_TRUE(deno_execute(d, "a.js", "SendWrongByteLength()"));
|
EXPECT_TRUE(deno_execute(d, "a.js", "SendWrongByteLength()"));
|
||||||
// deno_send the wrong sized message, it should throw.
|
// deno_send the wrong sized message, it should throw.
|
||||||
|
@ -63,14 +63,14 @@ TEST(MockRuntimeTest, SendWrongByteLength) {
|
||||||
deno_delete(d);
|
deno_delete(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(MockRuntimeTest, SendNoCallback) {
|
TEST(LibDenoTest, SendNoCallback) {
|
||||||
Deno* d = deno_new(nullptr, nullptr);
|
Deno* d = deno_new(nullptr, nullptr);
|
||||||
// We didn't call deno.recv() in JS, should fail.
|
// We didn't call deno.recv() in JS, should fail.
|
||||||
EXPECT_FALSE(deno_send(d, strbuf("abc")));
|
EXPECT_FALSE(deno_send(d, strbuf("abc")));
|
||||||
deno_delete(d);
|
deno_delete(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(MockRuntimeTest, RecvReturnEmpty) {
|
TEST(LibDenoTest, RecvReturnEmpty) {
|
||||||
static int count = 0;
|
static int count = 0;
|
||||||
Deno* d = deno_new(nullptr, [](auto _, auto buf) {
|
Deno* d = deno_new(nullptr, [](auto _, auto buf) {
|
||||||
count++;
|
count++;
|
||||||
|
@ -84,7 +84,7 @@ TEST(MockRuntimeTest, RecvReturnEmpty) {
|
||||||
deno_delete(d);
|
deno_delete(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(MockRuntimeTest, RecvReturnBar) {
|
TEST(LibDenoTest, RecvReturnBar) {
|
||||||
static int count = 0;
|
static int count = 0;
|
||||||
Deno* d = deno_new(nullptr, [](auto deno, auto buf) {
|
Deno* d = deno_new(nullptr, [](auto deno, auto buf) {
|
||||||
count++;
|
count++;
|
||||||
|
@ -99,13 +99,13 @@ TEST(MockRuntimeTest, RecvReturnBar) {
|
||||||
deno_delete(d);
|
deno_delete(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(MockRuntimeTest, DoubleRecvFails) {
|
TEST(LibDenoTest, DoubleRecvFails) {
|
||||||
Deno* d = deno_new(nullptr, nullptr);
|
Deno* d = deno_new(nullptr, nullptr);
|
||||||
EXPECT_FALSE(deno_execute(d, "a.js", "DoubleRecvFails()"));
|
EXPECT_FALSE(deno_execute(d, "a.js", "DoubleRecvFails()"));
|
||||||
deno_delete(d);
|
deno_delete(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(MockRuntimeTest, SendRecvSlice) {
|
TEST(LibDenoTest, SendRecvSlice) {
|
||||||
static int count = 0;
|
static int count = 0;
|
||||||
Deno* d = deno_new(nullptr, [](auto deno, auto buf) {
|
Deno* d = deno_new(nullptr, [](auto deno, auto buf) {
|
||||||
static const size_t alloc_len = 1024;
|
static const size_t alloc_len = 1024;
|
||||||
|
@ -137,7 +137,7 @@ TEST(MockRuntimeTest, SendRecvSlice) {
|
||||||
deno_delete(d);
|
deno_delete(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(MockRuntimeTest, JSSendArrayBufferViewTypes) {
|
TEST(LibDenoTest, JSSendArrayBufferViewTypes) {
|
||||||
static int count = 0;
|
static int count = 0;
|
||||||
Deno* d = deno_new(nullptr, [](auto _, auto buf) {
|
Deno* d = deno_new(nullptr, [](auto _, auto buf) {
|
||||||
count++;
|
count++;
|
||||||
|
@ -152,7 +152,7 @@ TEST(MockRuntimeTest, JSSendArrayBufferViewTypes) {
|
||||||
deno_delete(d);
|
deno_delete(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(MockRuntimeTest, JSSendNeutersBuffer) {
|
TEST(LibDenoTest, JSSendNeutersBuffer) {
|
||||||
static int count = 0;
|
static int count = 0;
|
||||||
Deno* d = deno_new(nullptr, [](auto _, auto buf) {
|
Deno* d = deno_new(nullptr, [](auto _, auto buf) {
|
||||||
count++;
|
count++;
|
||||||
|
@ -164,19 +164,19 @@ TEST(MockRuntimeTest, JSSendNeutersBuffer) {
|
||||||
deno_delete(d);
|
deno_delete(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(MockRuntimeTest, TypedArraySnapshots) {
|
TEST(LibDenoTest, TypedArraySnapshots) {
|
||||||
Deno* d = deno_new(nullptr, nullptr);
|
Deno* d = deno_new(nullptr, nullptr);
|
||||||
EXPECT_TRUE(deno_execute(d, "a.js", "TypedArraySnapshots()"));
|
EXPECT_TRUE(deno_execute(d, "a.js", "TypedArraySnapshots()"));
|
||||||
deno_delete(d);
|
deno_delete(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(MockRuntimeTest, SnapshotBug) {
|
TEST(LibDenoTest, SnapshotBug) {
|
||||||
Deno* d = deno_new(nullptr, nullptr);
|
Deno* d = deno_new(nullptr, nullptr);
|
||||||
EXPECT_TRUE(deno_execute(d, "a.js", "SnapshotBug()"));
|
EXPECT_TRUE(deno_execute(d, "a.js", "SnapshotBug()"));
|
||||||
deno_delete(d);
|
deno_delete(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(MockRuntimeTest, ErrorHandling) {
|
TEST(LibDenoTest, ErrorHandling) {
|
||||||
static int count = 0;
|
static int count = 0;
|
||||||
Deno* d = deno_new(nullptr, [](auto deno, auto buf) {
|
Deno* d = deno_new(nullptr, [](auto deno, auto buf) {
|
||||||
count++;
|
count++;
|
||||||
|
@ -188,7 +188,7 @@ TEST(MockRuntimeTest, ErrorHandling) {
|
||||||
deno_delete(d);
|
deno_delete(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(MockRuntimeTest, SendNullAllocPtr) {
|
TEST(LibDenoTest, SendNullAllocPtr) {
|
||||||
static int count = 0;
|
static int count = 0;
|
||||||
Deno* d = deno_new(nullptr, [](auto _, auto buf) { count++; });
|
Deno* d = deno_new(nullptr, [](auto _, auto buf) { count++; });
|
||||||
EXPECT_TRUE(deno_execute(d, "a.js", "SendNullAllocPtr()"));
|
EXPECT_TRUE(deno_execute(d, "a.js", "SendNullAllocPtr()"));
|
Loading…
Reference in a new issue