Skip to content

Commit 567afc7

Browse files
legendecasruyadorno
authored andcommitted
test: avoid copying test source files
Converting the helper functions to be inlined and making the helper file header only. PR-URL: #49515 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Gabriel Schulhof <gabrielschulhof@gmail.com>
1 parent c23c60f commit 567afc7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+156
-148
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,6 +1423,7 @@ FORMAT_CPP_FILES += $(LINT_CPP_FILES)
14231423
# C source codes.
14241424
FORMAT_CPP_FILES += $(wildcard \
14251425
benchmark/napi/*/*.c \
1426+
test/js-native-api/*.h \
14261427
test/js-native-api/*/*.c \
14271428
test/js-native-api/*/*.h \
14281429
test/node-api/*/*.c \

test/js-native-api/2_function_arguments/2_function_arguments.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <js_native_api.h>
22
#include "../common.h"
3+
#include "../entry_point.h"
34

45
static napi_value Add(napi_env env, napi_callback_info info) {
56
size_t argc = 2;

test/js-native-api/2_function_arguments/binding.gyp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
{
44
"target_name": "2_function_arguments",
55
"sources": [
6-
"../entry_point.c",
76
"2_function_arguments.c"
87
]
98
}

test/js-native-api/3_callbacks/3_callbacks.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <js_native_api.h>
2-
#include "../common.h"
32
#include <string.h>
3+
#include "../common.h"
4+
#include "../entry_point.h"
45

56
static napi_value RunCallback(napi_env env, napi_callback_info info) {
67
size_t argc = 2;

test/js-native-api/3_callbacks/binding.gyp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
{
44
"target_name": "3_callbacks",
55
"sources": [
6-
"../entry_point.c",
76
"3_callbacks.c"
87
]
98
}

test/js-native-api/4_object_factory/4_object_factory.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <js_native_api.h>
22
#include "../common.h"
3+
#include "../entry_point.h"
34

45
static napi_value CreateObject(napi_env env, napi_callback_info info) {
56
size_t argc = 1;

test/js-native-api/4_object_factory/binding.gyp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
{
44
"target_name": "4_object_factory",
55
"sources": [
6-
"../entry_point.c",
76
"4_object_factory.c"
87
]
98
}

test/js-native-api/5_function_factory/5_function_factory.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <js_native_api.h>
22
#include "../common.h"
3+
#include "../entry_point.h"
34

45
static napi_value MyFunction(napi_env env, napi_callback_info info) {
56
napi_value str;

test/js-native-api/5_function_factory/binding.gyp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
{
44
"target_name": "5_function_factory",
55
"sources": [
6-
"../entry_point.c",
76
"5_function_factory.c"
87
]
98
}

test/js-native-api/6_object_wrap/6_object_wrap.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "../common.h"
2+
#include "../entry_point.h"
23
#include "assert.h"
34
#include "myobject.h"
45

test/js-native-api/6_object_wrap/binding.gyp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
{
44
"target_name": "6_object_wrap",
55
"sources": [
6-
"../entry_point.c",
76
"6_object_wrap.cc"
87
]
98
}

test/js-native-api/7_factory_wrap/7_factory_wrap.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <js_native_api.h>
2-
#include "myobject.h"
32
#include "../common.h"
3+
#include "../entry_point.h"
4+
#include "myobject.h"
45

56
napi_value CreateObject(napi_env env, napi_callback_info info) {
67
size_t argc = 1;

test/js-native-api/7_factory_wrap/binding.gyp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
{
44
"target_name": "7_factory_wrap",
55
"sources": [
6-
"../entry_point.c",
76
"7_factory_wrap.cc",
87
"myobject.cc"
98
]

test/js-native-api/8_passing_wrapped/8_passing_wrapped.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <js_native_api.h>
2-
#include "myobject.h"
32
#include "../common.h"
3+
#include "../entry_point.h"
4+
#include "myobject.h"
45

56
extern size_t finalize_count;
67

test/js-native-api/8_passing_wrapped/binding.gyp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
{
44
"target_name": "8_passing_wrapped",
55
"sources": [
6-
"../entry_point.c",
76
"8_passing_wrapped.cc",
87
"myobject.cc"
98
]

test/js-native-api/common-inl.h

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#ifndef JS_NATIVE_API_COMMON_INL_H_
2+
#define JS_NATIVE_API_COMMON_INL_H_
3+
4+
#include <js_native_api.h>
5+
#include "common.h"
6+
7+
#include <stdio.h>
8+
9+
inline void add_returned_status(napi_env env,
10+
const char* key,
11+
napi_value object,
12+
char* expected_message,
13+
napi_status expected_status,
14+
napi_status actual_status) {
15+
char napi_message_string[100] = "";
16+
napi_value prop_value;
17+
18+
if (actual_status != expected_status) {
19+
snprintf(napi_message_string,
20+
sizeof(napi_message_string),
21+
"Invalid status [%d]",
22+
actual_status);
23+
}
24+
25+
NODE_API_CALL_RETURN_VOID(
26+
env,
27+
napi_create_string_utf8(
28+
env,
29+
(actual_status == expected_status ? expected_message
30+
: napi_message_string),
31+
NAPI_AUTO_LENGTH,
32+
&prop_value));
33+
NODE_API_CALL_RETURN_VOID(
34+
env, napi_set_named_property(env, object, key, prop_value));
35+
}
36+
37+
inline void add_last_status(napi_env env,
38+
const char* key,
39+
napi_value return_value) {
40+
napi_value prop_value;
41+
const napi_extended_error_info* p_last_error;
42+
NODE_API_CALL_RETURN_VOID(env, napi_get_last_error_info(env, &p_last_error));
43+
44+
NODE_API_CALL_RETURN_VOID(
45+
env,
46+
napi_create_string_utf8(
47+
env,
48+
(p_last_error->error_message == NULL ? "napi_ok"
49+
: p_last_error->error_message),
50+
NAPI_AUTO_LENGTH,
51+
&prop_value));
52+
NODE_API_CALL_RETURN_VOID(
53+
env, napi_set_named_property(env, return_value, key, prop_value));
54+
}
55+
56+
#endif // JS_NATIVE_API_COMMON_INL_H_

test/js-native-api/common.c

Lines changed: 0 additions & 48 deletions
This file was deleted.

test/js-native-api/common.h

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#ifndef JS_NATIVE_API_COMMON_H_
2+
#define JS_NATIVE_API_COMMON_H_
3+
14
#include <js_native_api.h>
25

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

79-
void add_returned_status(napi_env env,
80-
const char* key,
81-
napi_value object,
82-
char* expected_message,
83-
napi_status expected_status,
84-
napi_status actual_status);
82+
static inline void add_returned_status(napi_env env,
83+
const char* key,
84+
napi_value object,
85+
char* expected_message,
86+
napi_status expected_status,
87+
napi_status actual_status);
88+
89+
static inline void add_last_status(napi_env env,
90+
const char* key,
91+
napi_value return_value);
92+
93+
#include "common-inl.h"
8594

86-
void add_last_status(napi_env env, const char* key, napi_value return_value);
95+
#endif // JS_NATIVE_API_COMMON_H_
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
#ifndef JS_NATIVE_API_ENTRY_POINT_H_
2+
#define JS_NATIVE_API_ENTRY_POINT_H_
3+
14
#include <node_api.h>
25

36
EXTERN_C_START
47
napi_value Init(napi_env env, napi_value exports);
58
EXTERN_C_END
69

710
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)
11+
12+
#endif // JS_NATIVE_API_ENTRY_POINT_H_

test/js-native-api/test_array/binding.gyp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
{
44
"target_name": "test_array",
55
"sources": [
6-
"../entry_point.c",
76
"test_array.c"
87
]
98
}

test/js-native-api/test_array/test_array.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <js_native_api.h>
22
#include <string.h>
33
#include "../common.h"
4+
#include "../entry_point.h"
45

56
static napi_value TestGetElement(napi_env env, napi_callback_info info) {
67
size_t argc = 2;

test/js-native-api/test_bigint/binding.gyp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
{
44
"target_name": "test_bigint",
55
"sources": [
6-
"../entry_point.c",
76
"test_bigint.c"
87
]
98
}

test/js-native-api/test_bigint/test_bigint.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
#include <limits.h>
21
#include <inttypes.h>
3-
#include <stdio.h>
42
#include <js_native_api.h>
3+
#include <limits.h>
4+
#include <stdio.h>
55
#include "../common.h"
6+
#include "../entry_point.h"
67

78
static napi_value IsLossless(napi_env env, napi_callback_info info) {
89
size_t argc = 2;
Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,18 @@
11
{
22
"targets": [
3-
{
4-
"target_name": "copy_entry_point",
5-
"type": "none",
6-
"copies": [
7-
{
8-
"destination": ".",
9-
"files": [ "../entry_point.c" ]
10-
}
11-
]
12-
},
133
{
144
"target_name": "test_cannot_run_js",
155
"sources": [
16-
"entry_point.c",
176
"test_cannot_run_js.c"
187
],
198
"defines": [ "NAPI_EXPERIMENTAL" ],
20-
"dependencies": [ "copy_entry_point" ],
219
},
2210
{
2311
"target_name": "test_pending_exception",
2412
"sources": [
25-
"entry_point.c",
2613
"test_cannot_run_js.c"
2714
],
2815
"defines": [ "NAPI_VERSION=8" ],
29-
"dependencies": [ "copy_entry_point" ],
3016
}
3117
]
3218
}

test/js-native-api/test_cannot_run_js/test_cannot_run_js.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <js_native_api.h>
22
#include "../common.h"
3+
#include "../entry_point.h"
34
#include "stdlib.h"
45

56
static void Finalize(napi_env env, void* data, void* hint) {

test/js-native-api/test_constructor/binding.gyp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
{
44
"target_name": "test_constructor",
55
"sources": [
6-
"../common.c",
7-
"../entry_point.c",
86
"test_constructor.c",
97
"test_null.c",
108
]

test/js-native-api/test_constructor/test_constructor.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <js_native_api.h>
22
#include "../common.h"
3+
#include "../entry_point.h"
34
#include "test_null.h"
45

56
static double value_ = 1;

test/js-native-api/test_conversions/binding.gyp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
{
44
"target_name": "test_conversions",
55
"sources": [
6-
"../entry_point.c",
7-
"../common.c",
86
"test_conversions.c",
97
"test_null.c",
108
]

test/js-native-api/test_conversions/test_conversions.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <js_native_api.h>
22
#include "../common.h"
3+
#include "../entry_point.h"
34
#include "test_null.h"
45

56
static napi_value AsBool(napi_env env, napi_callback_info info) {

test/js-native-api/test_dataview/binding.gyp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
{
44
"target_name": "test_dataview",
55
"sources": [
6-
"../entry_point.c",
76
"test_dataview.c"
87
]
98
}

test/js-native-api/test_dataview/test_dataview.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <js_native_api.h>
22
#include <string.h>
33
#include "../common.h"
4+
#include "../entry_point.h"
45

56
static napi_value CreateDataView(napi_env env, napi_callback_info info) {
67
size_t argc = 3;

0 commit comments

Comments
 (0)