1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

chore: move test_ffi and test_nap to tests/ [WIP] (#22394)

Moving some additional NAPI and. FFI tests out of the tree root.
This commit is contained in:
Matt Mastracci 2024-02-12 13:46:50 -07:00 committed by Divy Srivastava
parent fe18597e34
commit de664f9a9d
71 changed files with 66 additions and 24 deletions

View file

@ -45,7 +45,7 @@
"cli/tsc/*typescript.js", "cli/tsc/*typescript.js",
"gh-pages", "gh-pages",
"target", "target",
"test_ffi/tests/test.js", "tests/ffi/tests/test.js",
"test_util/std", "test_util/std",
"test_util/wpt", "test_util/wpt",
"third_party", "third_party",

6
.gitignore vendored
View file

@ -12,9 +12,9 @@ gclient_config.py_entries
/std/hash/_wasm/target /std/hash/_wasm/target
/tools/wpt/manifest.json /tools/wpt/manifest.json
/third_party/ /third_party/
/test_napi/node_modules /tests/napi/node_modules
/test_napi/build /tests/napi/build
/test_napi/third_party_tests/node_modules /tests/napi/third_party_tests/node_modules
# MacOS generated files # MacOS generated files
.DS_Store .DS_Store

View file

@ -28,10 +28,10 @@ members = [
"ext/websocket", "ext/websocket",
"ext/webstorage", "ext/webstorage",
"runtime", "runtime",
"test_ffi",
"test_napi",
"test_util", "test_util",
"tests", "tests",
"tests/ffi",
"tests/napi",
] ]
exclude = ["test_util/std/hash/_wasm"] exclude = ["test_util/std/hash/_wasm"]

View file

@ -1,6 +1,6 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { loadTestLibrary } from "../../../test_napi/common.js"; import { loadTestLibrary } from "../../../tests/napi/common.js";
const lib = loadTestLibrary(); const lib = loadTestLibrary();

View file

@ -2,7 +2,7 @@ import { bench, run } from "mitata";
import { createRequire } from "module"; import { createRequire } from "module";
const require = createRequire(import.meta.url); const require = createRequire(import.meta.url);
const lib = require("../../../test_napi.node"); const lib = require("../../../tests/napi.node");
bench("warmup", () => {}); bench("warmup", () => {});
bench("napi_get_undefined", () => lib.test_get_undefined(0)); bench("napi_get_undefined", () => lib.test_get_undefined(0));

View file

@ -50,11 +50,11 @@ Update the generated symbol lists using the script:
deno run --allow-write tools/napi/generate_symbols_lists.js deno run --allow-write tools/napi/generate_symbols_lists.js
``` ```
Add a test in [`/test_napi`](../../test_napi/). You can also refer to Node.js Add a test in [`/tests/napi`](../../tests/napi/). You can also refer to Node.js
test suite for Node-API. test suite for Node-API.
```js ```js
// test_napi/boolean_test.js // tests/napi/boolean_test.js
import { assertEquals, loadTestLibrary } from "./common.js"; import { assertEquals, loadTestLibrary } from "./common.js";
const lib = loadTestLibrary(); const lib = loadTestLibrary();
Deno.test("napi get boolean", function () { Deno.test("napi get boolean", function () {
@ -64,7 +64,7 @@ Deno.test("napi get boolean", function () {
``` ```
```rust ```rust
// test_napi/src/boolean.rs // tests/napi/src/boolean.rs
use napi_sys::Status::napi_ok; use napi_sys::Status::napi_ok;
use napi_sys::ValueType::napi_boolean; use napi_sys::ValueType::napi_boolean;
@ -96,7 +96,7 @@ pub fn init(env: napi_env, exports: napi_value) {
``` ```
```diff ```diff
// test_napi/src/lib.rs // tests/napi/src/lib.rs
+ mod boolean; + mod boolean;
@ -114,4 +114,4 @@ unsafe extern "C" fn napi_register_module_v1(
} }
``` ```
Run the test using `cargo test -p test_napi`. Run the test using `cargo test -p tests/napi`.

View file

@ -21,5 +21,5 @@ MacOS.
To run benchmarks: To run benchmarks:
```bash ```bash
target/release/deno bench --allow-ffi --allow-read --unstable-ffi ./test_ffi/tests/bench.js target/release/deno bench --allow-ffi --allow-read --unstable-ffi ./tests/ffi/tests/bench.js
``` ```

View file

@ -87,8 +87,16 @@ pub fn third_party_path() -> PathRef {
root_path().join("third_party") root_path().join("third_party")
} }
pub fn ffi_tests_path() -> PathRef {
root_path().join("tests").join("ffi")
}
pub fn napi_tests_path() -> PathRef { pub fn napi_tests_path() -> PathRef {
root_path().join("test_napi") root_path().join("tests").join("napi")
}
pub fn deno_config_path() -> PathRef {
root_path().join("tests").join("config").join("deno.json")
} }
/// Test server registry url. /// Test server registry url.

View file

@ -1,5 +1,6 @@
{ {
"imports": { "imports": {
"@test_util/": "../../test_util/" "@test_util/": "../../test_util/",
"@std/": "../../test_util/std/"
} }
} }

View file

@ -3,6 +3,8 @@
use pretty_assertions::assert_eq; use pretty_assertions::assert_eq;
use std::process::Command; use std::process::Command;
use test_util::deno_cmd; use test_util::deno_cmd;
use test_util::deno_config_path;
use test_util::ffi_tests_path;
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
const BUILD_VARIANT: &str = "debug"; const BUILD_VARIANT: &str = "debug";
@ -26,7 +28,11 @@ fn basic() {
build(); build();
let output = deno_cmd() let output = deno_cmd()
.current_dir(ffi_tests_path())
.arg("run") .arg("run")
.arg("--config")
.arg(deno_config_path())
.arg("--no-lock")
.arg("--allow-ffi") .arg("--allow-ffi")
.arg("--allow-read") .arg("--allow-read")
.arg("--unstable-ffi") .arg("--unstable-ffi")
@ -134,7 +140,11 @@ fn symbol_types() {
build(); build();
let output = deno_cmd() let output = deno_cmd()
.current_dir(ffi_tests_path())
.arg("check") .arg("check")
.arg("--config")
.arg(deno_config_path())
.arg("--no-lock")
.arg("--unstable-ffi") .arg("--unstable-ffi")
.arg("--quiet") .arg("--quiet")
.arg("tests/ffi_types.ts") .arg("tests/ffi_types.ts")
@ -157,7 +167,11 @@ fn thread_safe_callback() {
build(); build();
let output = deno_cmd() let output = deno_cmd()
.current_dir(ffi_tests_path())
.arg("run") .arg("run")
.arg("--config")
.arg(deno_config_path())
.arg("--no-lock")
.arg("--allow-ffi") .arg("--allow-ffi")
.arg("--allow-read") .arg("--allow-read")
.arg("--unstable-ffi") .arg("--unstable-ffi")
@ -191,7 +205,11 @@ fn event_loop_integration() {
build(); build();
let output = deno_cmd() let output = deno_cmd()
.current_dir(ffi_tests_path())
.arg("run") .arg("run")
.arg("--config")
.arg(deno_config_path())
.arg("--no-lock")
.arg("--allow-ffi") .arg("--allow-ffi")
.arg("--allow-read") .arg("--allow-read")
.arg("--unstable-ffi") .arg("--unstable-ffi")
@ -243,7 +261,11 @@ fn ffi_callback_errors_test() {
build(); build();
let output = deno_cmd() let output = deno_cmd()
.current_dir(ffi_tests_path())
.arg("run") .arg("run")
.arg("--config")
.arg(deno_config_path())
.arg("--no-lock")
.arg("--allow-ffi") .arg("--allow-ffi")
.arg("--allow-read") .arg("--allow-read")
.arg("--unstable-ffi") .arg("--unstable-ffi")

View file

@ -10,7 +10,7 @@ import {
assertInstanceOf, assertInstanceOf,
assertEquals, assertEquals,
assertFalse, assertFalse,
} from "../../test_util/std/assert/mod.ts"; } from "@std/assert/mod.ts";
const targetDir = Deno.execPath().replace(/[^\/\\]+$/, ""); const targetDir = Deno.execPath().replace(/[^\/\\]+$/, "");
const [libPrefix, libSuffix] = { const [libPrefix, libSuffix] = {

View file

@ -120,7 +120,7 @@ fn js_unit_test(test: String) {
.current_dir(util::root_path()) .current_dir(util::root_path())
.arg("test") .arg("test")
.arg("--config") .arg("--config")
.arg("tests/config/deno.json") .arg(util::deno_config_path())
.arg("--no-lock") .arg("--no-lock")
.arg("--unstable") .arg("--unstable")
.arg("--location=http://127.0.0.1:4545/") .arg("--location=http://127.0.0.1:4545/")

View file

@ -1,6 +1,7 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
use test_util as util; use test_util as util;
use util::deno_config_path;
use util::env_vars_for_npm_tests; use util::env_vars_for_npm_tests;
#[test] #[test]
@ -9,7 +10,7 @@ fn node_compat_tests() {
.current_dir(util::root_path()) .current_dir(util::root_path())
.arg("test") .arg("test")
.arg("--config") .arg("--config")
.arg("tests/config/deno.json") .arg(deno_config_path())
.arg("--no-lock") .arg("--no-lock")
.arg("--unstable") .arg("--unstable")
.arg("-A") .arg("-A")

View file

@ -4,6 +4,7 @@ use std::io::BufReader;
use std::time::Duration; use std::time::Duration;
use std::time::Instant; use std::time::Instant;
use test_util as util; use test_util as util;
use util::deno_config_path;
use util::env_vars_for_npm_tests; use util::env_vars_for_npm_tests;
util::unit_test_factory!( util::unit_test_factory!(
@ -97,7 +98,7 @@ fn node_unit_test(test: String) {
.current_dir(util::root_path()) .current_dir(util::root_path())
.arg("test") .arg("test")
.arg("--config") .arg("--config")
.arg("tests/config/deno.json") .arg(deno_config_path())
.arg("--no-lock") .arg("--no-lock")
.arg("--unstable") .arg("--unstable")
// TODO(kt3k): This option is required to pass tls_test.ts, // TODO(kt3k): This option is required to pass tls_test.ts,

View file

@ -12,6 +12,9 @@ if (import.meta.main) {
const { stdout, stderr, code } = await new Deno.Command(Deno.execPath(), { const { stdout, stderr, code } = await new Deno.Command(Deno.execPath(), {
args: [ args: [
"run", "run",
"--config",
Deno.realPathSync("../config/deno.json"),
"--no-lock",
"--allow-read", "--allow-read",
"--allow-run", "--allow-run",
"--allow-ffi", "--allow-ffi",
@ -20,8 +23,8 @@ if (import.meta.main) {
], ],
}).output(); }).output();
assertEquals(code, 0);
assertEquals(new TextDecoder().decode(stderr), ""); assertEquals(new TextDecoder().decode(stderr), "");
assertEquals(code, 0);
const stdoutText = new TextDecoder().decode(stdout); const stdoutText = new TextDecoder().decode(stdout);
const stdoutLines = stdoutText.split("\n"); const stdoutLines = stdoutText.split("\n");

View file

@ -5,8 +5,8 @@ export {
assertEquals, assertEquals,
assertRejects, assertRejects,
assertThrows, assertThrows,
} from "../test_util/std/assert/mod.ts"; } from "@std/assert/mod.ts";
export { fromFileUrl } from "../test_util/std/path/mod.ts"; export { fromFileUrl } from "@std/path/mod.ts";
import process from "node:process"; import process from "node:process";
const targetDir = Deno.execPath().replace(/[^\/\\]+$/, ""); const targetDir = Deno.execPath().replace(/[^\/\\]+$/, "");

View file

@ -2,8 +2,10 @@
use std::process::Command; use std::process::Command;
use test_util::deno_cmd; use test_util::deno_cmd;
use test_util::deno_config_path;
use test_util::env_vars_for_npm_tests; use test_util::env_vars_for_npm_tests;
use test_util::http_server; use test_util::http_server;
use test_util::napi_tests_path;
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
const BUILD_VARIANT: &str = "debug"; const BUILD_VARIANT: &str = "debug";
@ -57,13 +59,17 @@ fn napi_tests() {
let _http_guard = http_server(); let _http_guard = http_server();
let output = deno_cmd() let output = deno_cmd()
.current_dir(test_util::napi_tests_path()) .current_dir(napi_tests_path())
.env("RUST_BACKTRACE", "1") .env("RUST_BACKTRACE", "1")
.arg("test") .arg("test")
.arg("--allow-read") .arg("--allow-read")
.arg("--allow-env") .arg("--allow-env")
.arg("--allow-ffi") .arg("--allow-ffi")
.arg("--allow-run") .arg("--allow-run")
.arg("--config")
.arg(deno_config_path())
.arg("--no-lock")
.arg(".")
.envs(env_vars_for_npm_tests()) .envs(env_vars_for_npm_tests())
.spawn() .spawn()
.unwrap() .unwrap()