Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: avoid copying test source files #49515

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,7 @@ FORMAT_CPP_FILES += $(LINT_CPP_FILES)
# C source codes.
FORMAT_CPP_FILES += $(wildcard \
benchmark/napi/*/*.c \
test/js-native-api/*.h \
test/js-native-api/*/*.c \
test/js-native-api/*/*.h \
test/node-api/*/*.c \
Expand Down
1 change: 0 additions & 1 deletion test/js-native-api/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ Makefile
*.mk
gyp-mac-tool
/*/build
test_cannot_run_js/entry_point.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <js_native_api.h>
#include "../common.h"
#include "../entry_point.h"

static napi_value Add(napi_env env, napi_callback_info info) {
size_t argc = 2;
Expand Down
1 change: 0 additions & 1 deletion test/js-native-api/2_function_arguments/binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
{
"target_name": "2_function_arguments",
"sources": [
"../entry_point.c",
"2_function_arguments.c"
]
}
Expand Down
3 changes: 2 additions & 1 deletion test/js-native-api/3_callbacks/3_callbacks.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <js_native_api.h>
#include "../common.h"
#include <string.h>
#include "../common.h"
#include "../entry_point.h"

static napi_value RunCallback(napi_env env, napi_callback_info info) {
size_t argc = 2;
Expand Down
1 change: 0 additions & 1 deletion test/js-native-api/3_callbacks/binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
{
"target_name": "3_callbacks",
"sources": [
"../entry_point.c",
"3_callbacks.c"
]
}
Expand Down
1 change: 1 addition & 0 deletions test/js-native-api/4_object_factory/4_object_factory.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <js_native_api.h>
#include "../common.h"
#include "../entry_point.h"

static napi_value CreateObject(napi_env env, napi_callback_info info) {
size_t argc = 1;
Expand Down
1 change: 0 additions & 1 deletion test/js-native-api/4_object_factory/binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
{
"target_name": "4_object_factory",
"sources": [
"../entry_point.c",
"4_object_factory.c"
]
}
Expand Down
1 change: 1 addition & 0 deletions test/js-native-api/5_function_factory/5_function_factory.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <js_native_api.h>
#include "../common.h"
#include "../entry_point.h"

static napi_value MyFunction(napi_env env, napi_callback_info info) {
napi_value str;
Expand Down
1 change: 0 additions & 1 deletion test/js-native-api/5_function_factory/binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
{
"target_name": "5_function_factory",
"sources": [
"../entry_point.c",
"5_function_factory.c"
]
}
Expand Down
1 change: 1 addition & 0 deletions test/js-native-api/6_object_wrap/6_object_wrap.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "../common.h"
#include "../entry_point.h"
#include "assert.h"
#include "myobject.h"

Expand Down
1 change: 0 additions & 1 deletion test/js-native-api/6_object_wrap/binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
{
"target_name": "6_object_wrap",
"sources": [
"../entry_point.c",
"6_object_wrap.cc"
]
}
Expand Down
3 changes: 2 additions & 1 deletion test/js-native-api/7_factory_wrap/7_factory_wrap.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <js_native_api.h>
#include "myobject.h"
#include "../common.h"
#include "../entry_point.h"
#include "myobject.h"

napi_value CreateObject(napi_env env, napi_callback_info info) {
size_t argc = 1;
Expand Down
1 change: 0 additions & 1 deletion test/js-native-api/7_factory_wrap/binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
{
"target_name": "7_factory_wrap",
"sources": [
"../entry_point.c",
"7_factory_wrap.cc",
"myobject.cc"
]
Expand Down
3 changes: 2 additions & 1 deletion test/js-native-api/8_passing_wrapped/8_passing_wrapped.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <js_native_api.h>
#include "myobject.h"
#include "../common.h"
#include "../entry_point.h"
#include "myobject.h"

extern size_t finalize_count;

Expand Down
1 change: 0 additions & 1 deletion test/js-native-api/8_passing_wrapped/binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
{
"target_name": "8_passing_wrapped",
"sources": [
"../entry_point.c",
"8_passing_wrapped.cc",
"myobject.cc"
]
Expand Down
56 changes: 56 additions & 0 deletions test/js-native-api/common-inl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#ifndef JS_NATIVE_API_COMMON_INL_H_
#define JS_NATIVE_API_COMMON_INL_H_

#include <js_native_api.h>
#include "common.h"

#include <stdio.h>

inline void add_returned_status(napi_env env,
const char* key,
napi_value object,
char* expected_message,
napi_status expected_status,
napi_status actual_status) {
char napi_message_string[100] = "";
napi_value prop_value;

if (actual_status != expected_status) {
snprintf(napi_message_string,
sizeof(napi_message_string),
"Invalid status [%d]",
actual_status);
}

NODE_API_CALL_RETURN_VOID(
env,
napi_create_string_utf8(
env,
(actual_status == expected_status ? expected_message
: napi_message_string),
NAPI_AUTO_LENGTH,
&prop_value));
NODE_API_CALL_RETURN_VOID(
env, napi_set_named_property(env, object, key, prop_value));
}

inline void add_last_status(napi_env env,
const char* key,
napi_value return_value) {
napi_value prop_value;
const napi_extended_error_info* p_last_error;
NODE_API_CALL_RETURN_VOID(env, napi_get_last_error_info(env, &p_last_error));

NODE_API_CALL_RETURN_VOID(
env,
napi_create_string_utf8(
env,
(p_last_error->error_message == NULL ? "napi_ok"
: p_last_error->error_message),
NAPI_AUTO_LENGTH,
&prop_value));
NODE_API_CALL_RETURN_VOID(
env, napi_set_named_property(env, return_value, key, prop_value));
}

#endif // JS_NATIVE_API_COMMON_INL_H_
48 changes: 0 additions & 48 deletions test/js-native-api/common.c

This file was deleted.

23 changes: 16 additions & 7 deletions test/js-native-api/common.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#ifndef JS_NATIVE_API_COMMON_H_
#define JS_NATIVE_API_COMMON_H_

#include <js_native_api.h>

// Empty value so that macros here are able to return NULL or void
Expand Down Expand Up @@ -76,11 +79,17 @@
#define DECLARE_NODE_API_PROPERTY_VALUE(name, value) \
{ (name), NULL, NULL, NULL, NULL, (value), napi_default, NULL }

void add_returned_status(napi_env env,
const char* key,
napi_value object,
char* expected_message,
napi_status expected_status,
napi_status actual_status);
static inline void add_returned_status(napi_env env,
const char* key,
napi_value object,
char* expected_message,
napi_status expected_status,
napi_status actual_status);

static inline void add_last_status(napi_env env,
const char* key,
napi_value return_value);

#include "common-inl.h"

void add_last_status(napi_env env, const char* key, napi_value return_value);
#endif // JS_NATIVE_API_COMMON_H_
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#ifndef JS_NATIVE_API_ENTRY_POINT_H_
#define JS_NATIVE_API_ENTRY_POINT_H_

#include <node_api.h>

EXTERN_C_START
napi_value Init(napi_env env, napi_value exports);
EXTERN_C_END

NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)

#endif // JS_NATIVE_API_ENTRY_POINT_H_
1 change: 0 additions & 1 deletion test/js-native-api/test_array/binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
{
"target_name": "test_array",
"sources": [
"../entry_point.c",
"test_array.c"
]
}
Expand Down
1 change: 1 addition & 0 deletions test/js-native-api/test_array/test_array.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <js_native_api.h>
#include <string.h>
#include "../common.h"
#include "../entry_point.h"

static napi_value TestGetElement(napi_env env, napi_callback_info info) {
size_t argc = 2;
Expand Down
1 change: 0 additions & 1 deletion test/js-native-api/test_bigint/binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
{
"target_name": "test_bigint",
"sources": [
"../entry_point.c",
"test_bigint.c"
]
}
Expand Down
5 changes: 3 additions & 2 deletions test/js-native-api/test_bigint/test_bigint.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include <limits.h>
#include <inttypes.h>
#include <stdio.h>
#include <js_native_api.h>
#include <limits.h>
#include <stdio.h>
#include "../common.h"
#include "../entry_point.h"

static napi_value IsLossless(napi_env env, napi_callback_info info) {
size_t argc = 2;
Expand Down
14 changes: 0 additions & 14 deletions test/js-native-api/test_cannot_run_js/binding.gyp
Original file line number Diff line number Diff line change
@@ -1,32 +1,18 @@
{
"targets": [
{
"target_name": "copy_entry_point",
"type": "none",
"copies": [
{
"destination": ".",
"files": [ "../entry_point.c" ]
}
]
},
{
"target_name": "test_cannot_run_js",
"sources": [
"entry_point.c",
"test_cannot_run_js.c"
],
"defines": [ "NAPI_EXPERIMENTAL" ],
"dependencies": [ "copy_entry_point" ],
},
{
"target_name": "test_pending_exception",
"sources": [
"entry_point.c",
"test_cannot_run_js.c"
],
"defines": [ "NAPI_VERSION=8" ],
"dependencies": [ "copy_entry_point" ],
}
]
}
1 change: 1 addition & 0 deletions test/js-native-api/test_cannot_run_js/test_cannot_run_js.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <js_native_api.h>
#include "../common.h"
#include "../entry_point.h"
#include "stdlib.h"

static void Finalize(napi_env env, void* data, void* hint) {
Expand Down
2 changes: 0 additions & 2 deletions test/js-native-api/test_constructor/binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
{
"target_name": "test_constructor",
"sources": [
"../common.c",
"../entry_point.c",
"test_constructor.c",
"test_null.c",
]
Expand Down
1 change: 1 addition & 0 deletions test/js-native-api/test_constructor/test_constructor.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <js_native_api.h>
#include "../common.h"
#include "../entry_point.h"
#include "test_null.h"

static double value_ = 1;
Expand Down
2 changes: 0 additions & 2 deletions test/js-native-api/test_conversions/binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
{
"target_name": "test_conversions",
"sources": [
"../entry_point.c",
"../common.c",
"test_conversions.c",
"test_null.c",
]
Expand Down
1 change: 1 addition & 0 deletions test/js-native-api/test_conversions/test_conversions.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <js_native_api.h>
#include "../common.h"
#include "../entry_point.h"
#include "test_null.h"

static napi_value AsBool(napi_env env, napi_callback_info info) {
Expand Down
1 change: 0 additions & 1 deletion test/js-native-api/test_dataview/binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
{
"target_name": "test_dataview",
"sources": [
"../entry_point.c",
"test_dataview.c"
]
}
Expand Down
1 change: 1 addition & 0 deletions test/js-native-api/test_dataview/test_dataview.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <js_native_api.h>
#include <string.h>
#include "../common.h"
#include "../entry_point.h"

static napi_value CreateDataView(napi_env env, napi_callback_info info) {
size_t argc = 3;
Expand Down
Loading