From bec60f9e03330014245e7c74d2ce3c83065494a6 Mon Sep 17 00:00:00 2001 From: Michael Dawson Date: Tue, 30 May 2017 17:47:05 -0400 Subject: [PATCH] test: consolidate n-api test addons It takes time to build each of the addons used to test n-api. Consolidate a few of the smaller ones to save build time. --- .../test.js => test_general/testGlobals.js} | 2 +- .../testInstanceOf.js} | 2 +- test/addons-napi/test_general/test_general.c | 29 +++++++++++++++++++ test/addons-napi/test_globals/binding.gyp | 8 ----- test/addons-napi/test_globals/test_globals.c | 26 ----------------- test/addons-napi/test_instanceof/binding.gyp | 8 ----- .../test_instanceof/test_instanceof.c | 28 ------------------ 7 files changed, 31 insertions(+), 72 deletions(-) rename test/addons-napi/{test_globals/test.js => test_general/testGlobals.js} (96%) rename test/addons-napi/{test_instanceof/test.js => test_general/testInstanceOf.js} (97%) delete mode 100644 test/addons-napi/test_globals/binding.gyp delete mode 100644 test/addons-napi/test_globals/test_globals.c delete mode 100644 test/addons-napi/test_instanceof/binding.gyp delete mode 100644 test/addons-napi/test_instanceof/test_instanceof.c diff --git a/test/addons-napi/test_globals/test.js b/test/addons-napi/test_general/testGlobals.js similarity index 96% rename from test/addons-napi/test_globals/test.js rename to test/addons-napi/test_general/testGlobals.js index a6e5f722cb9379..38cf3f3edbccbc 100644 --- a/test/addons-napi/test_globals/test.js +++ b/test/addons-napi/test_general/testGlobals.js @@ -2,7 +2,7 @@ const common = require('../../common'); const assert = require('assert'); -const test_globals = require(`./build/${common.buildType}/test_globals`); +const test_globals = require(`./build/${common.buildType}/test_general`); assert.strictEqual(test_globals.getUndefined(), undefined); assert.strictEqual(test_globals.getNull(), null); diff --git a/test/addons-napi/test_instanceof/test.js b/test/addons-napi/test_general/testInstanceOf.js similarity index 97% rename from test/addons-napi/test_instanceof/test.js rename to test/addons-napi/test_general/testInstanceOf.js index 418149d1909e6f..3279979719dc37 100644 --- a/test/addons-napi/test_instanceof/test.js +++ b/test/addons-napi/test_general/testInstanceOf.js @@ -6,7 +6,7 @@ const assert = require('assert'); // addon is referenced through the eval expression in testFile // eslint-disable-next-line no-unused-vars -const addon = require(`./build/${common.buildType}/test_instanceof`); +const addon = require(`./build/${common.buildType}/test_general`); const path = require('path'); // The following assert functions are referenced by v8's unit tests diff --git a/test/addons-napi/test_general/test_general.c b/test/addons-napi/test_general/test_general.c index 585a3bf2b3ff0d..5d974081a4d8c9 100644 --- a/test/addons-napi/test_general/test_general.c +++ b/test/addons-napi/test_general/test_general.c @@ -33,11 +33,40 @@ napi_value testGetVersion(napi_env env, napi_callback_info info) { return result; } +napi_value doInstanceOf(napi_env env, napi_callback_info info) { + size_t argc = 2; + napi_value args[2]; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL)); + + bool instanceof; + NAPI_CALL(env, napi_instanceof(env, args[0], args[1], &instanceof)); + + napi_value result; + NAPI_CALL(env, napi_get_boolean(env, instanceof, &result)); + + return result; +} + +napi_value getNull(napi_env env, napi_callback_info info) { + napi_value result; + NAPI_CALL(env, napi_get_null(env, &result)); + return result; +} + +napi_value getUndefined(napi_env env, napi_callback_info info) { + napi_value result; + NAPI_CALL(env, napi_get_undefined(env, &result)); + return result; +} + void Init(napi_env env, napi_value exports, napi_value module, void* priv) { napi_property_descriptor descriptors[] = { DECLARE_NAPI_PROPERTY("testStrictEquals", testStrictEquals), DECLARE_NAPI_PROPERTY("testGetPrototype", testGetPrototype), DECLARE_NAPI_PROPERTY("testGetVersion", testGetVersion), + DECLARE_NAPI_PROPERTY("doInstanceOf", doInstanceOf), + DECLARE_NAPI_PROPERTY("getUndefined", getUndefined), + DECLARE_NAPI_PROPERTY("getNull", getNull), }; NAPI_CALL_RETURN_VOID(env, napi_define_properties( diff --git a/test/addons-napi/test_globals/binding.gyp b/test/addons-napi/test_globals/binding.gyp deleted file mode 100644 index 0160dc72e18017..00000000000000 --- a/test/addons-napi/test_globals/binding.gyp +++ /dev/null @@ -1,8 +0,0 @@ -{ - "targets": [ - { - "target_name": "test_globals", - "sources": [ "test_globals.c" ] - } - ] -} diff --git a/test/addons-napi/test_globals/test_globals.c b/test/addons-napi/test_globals/test_globals.c deleted file mode 100644 index 709e42a2e0e6c8..00000000000000 --- a/test/addons-napi/test_globals/test_globals.c +++ /dev/null @@ -1,26 +0,0 @@ -#include -#include "../common.h" - -napi_value getNull(napi_env env, napi_callback_info info) { - napi_value result; - NAPI_CALL(env, napi_get_null(env, &result)); - return result; -} - -napi_value getUndefined(napi_env env, napi_callback_info info) { - napi_value result; - NAPI_CALL(env, napi_get_undefined(env, &result)); - return result; -} - -void Init(napi_env env, napi_value exports, napi_value module, void* priv) { - napi_property_descriptor descriptors[] = { - DECLARE_NAPI_PROPERTY("getUndefined", getUndefined), - DECLARE_NAPI_PROPERTY("getNull", getNull), - }; - - NAPI_CALL_RETURN_VOID(env, napi_define_properties( - env, exports, sizeof(descriptors) / sizeof(*descriptors), descriptors)); -} - -NAPI_MODULE(addon, Init) diff --git a/test/addons-napi/test_instanceof/binding.gyp b/test/addons-napi/test_instanceof/binding.gyp deleted file mode 100644 index 7fca7e0736d410..00000000000000 --- a/test/addons-napi/test_instanceof/binding.gyp +++ /dev/null @@ -1,8 +0,0 @@ -{ - "targets": [ - { - "target_name": "test_instanceof", - "sources": [ "test_instanceof.c" ] - } - ] -} diff --git a/test/addons-napi/test_instanceof/test_instanceof.c b/test/addons-napi/test_instanceof/test_instanceof.c deleted file mode 100644 index 76a6542830959d..00000000000000 --- a/test/addons-napi/test_instanceof/test_instanceof.c +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include -#include "../common.h" - -napi_value doInstanceOf(napi_env env, napi_callback_info info) { - size_t argc = 2; - napi_value args[2]; - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL)); - - bool instanceof; - NAPI_CALL(env, napi_instanceof(env, args[0], args[1], &instanceof)); - - napi_value result; - NAPI_CALL(env, napi_get_boolean(env, instanceof, &result)); - - return result; -} - -void Init(napi_env env, napi_value exports, napi_value module, void* priv) { - napi_property_descriptor descriptors[] = { - DECLARE_NAPI_PROPERTY("doInstanceOf", doInstanceOf), - }; - - NAPI_CALL_RETURN_VOID(env, napi_define_properties( - env, exports, sizeof(descriptors) / sizeof(*descriptors), descriptors)); -} - -NAPI_MODULE(addon, Init)