summaryrefslogtreecommitdiff
path: root/test_ffi/tests
diff options
context:
space:
mode:
Diffstat (limited to 'test_ffi/tests')
-rw-r--r--test_ffi/tests/integration_tests.rs2
-rw-r--r--test_ffi/tests/test.js35
2 files changed, 32 insertions, 5 deletions
diff --git a/test_ffi/tests/integration_tests.rs b/test_ffi/tests/integration_tests.rs
index 99a17f0a9..13c4e1485 100644
--- a/test_ffi/tests/integration_tests.rs
+++ b/test_ffi/tests/integration_tests.rs
@@ -24,6 +24,7 @@ fn basic() {
.arg("--allow-ffi")
.arg("--allow-read")
.arg("--unstable")
+ .arg("--quiet")
.arg("tests/test.js")
.env("NO_COLOR", "1")
.output()
@@ -37,7 +38,6 @@ fn basic() {
println!("{:?}", output.status);
assert!(output.status.success());
let expected = "\
- dlopen doesn't panic\n\
something\n\
[1, 2, 3, 4, 5, 6, 7, 8]\n\
[1, 2, 3, 4, 5, 6, 7, 8] [9, 10]\n\
diff --git a/test_ffi/tests/test.js b/test_ffi/tests/test.js
index 16e4d76b6..db7603521 100644
--- a/test_ffi/tests/test.js
+++ b/test_ffi/tests/test.js
@@ -1,6 +1,8 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
// deno-lint-ignore-file
+import { assertThrows } from "../../test_util/std/testing/asserts.ts";
+
const targetDir = Deno.execPath().replace(/[^\/\\]+$/, "");
const [libPrefix, libSuffix] = {
darwin: ["lib", "dylib"],
@@ -12,11 +14,22 @@ const libPath = `${targetDir}/${libPrefix}test_ffi.${libSuffix}`;
const resourcesPre = Deno.resources();
// dlopen shouldn't panic
-try {
+assertThrows(() => {
Deno.dlopen("cli/src/main.rs", {});
-} catch (_) {
- console.log("dlopen doesn't panic");
-}
+});
+
+assertThrows(
+ () => {
+ Deno.dlopen(libPath, {
+ non_existent_symbol: {
+ parameters: [],
+ result: "void",
+ },
+ });
+ },
+ Error,
+ "Failed to register symbol non_existent_symbol",
+);
const dylib = Deno.dlopen(libPath, {
"print_something": { parameters: [], result: "void" },
@@ -75,6 +88,20 @@ console.log(Boolean(dylib.symbols.is_null_ptr(ptr)));
console.log(Boolean(dylib.symbols.is_null_ptr(null)));
console.log(Boolean(dylib.symbols.is_null_ptr(Deno.UnsafePointer.of(into))));
console.log(dylib.symbols.add_u32(123, 456));
+assertThrows(
+ () => {
+ dylib.symbols.add_u32(-1, 100);
+ },
+ TypeError,
+ "Expected FFI argument to be an unsigned integer, but got Number(-1)",
+);
+assertThrows(
+ () => {
+ dylib.symbols.add_u32(null, 100);
+ },
+ TypeError,
+ "Expected FFI argument to be an unsigned integer, but got Null",
+);
console.log(dylib.symbols.add_i32(123, 456));
console.log(dylib.symbols.add_u64(123, 456));
console.log(dylib.symbols.add_i64(123, 456));