Skip to content

Commit d7fb8b1

Browse files
committed
Solve bugs related to the module naming schema change.
1 parent c09d4bd commit d7fb8b1

File tree

11 files changed

+265
-55
lines changed

11 files changed

+265
-55
lines changed

source/ports/node_port/test/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ describe('metacall', () => {
6666
it('metacall_load_from_file (cob)', () => {
6767
assert.strictEqual(metacall_load_from_file('cob', [ 'say.cob' ]), undefined);
6868

69-
const script = metacall_handle('cob', 'say');
69+
const script = metacall_handle('cob', 'say.cob');
7070
assert.notStrictEqual(script, undefined);
71-
assert.strictEqual(script.name, 'say');
71+
assert.strictEqual(script.name, 'say.cob');
7272

7373
assert.strictEqual(metacall('say', 'Hello, ', 'world!'), 0);
7474
});

source/ports/py_port/metacall/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,14 @@ def generate_module(handle_name, handle):
162162
handle_name = name.split('.')[-2]
163163

164164
# Check if it is already loaded in MetaCall
165-
handle = find_handle(handle_name)
165+
handle = find_handle(name)
166166

167167
if handle != None:
168168
# Generate the module from cached handle
169169
return generate_module(handle_name, handle)
170170

171171
if metacall_load_from_file(extensions_to_tag[extension], [name]):
172-
handle = find_handle(handle_name)
172+
handle = find_handle(name)
173173
if handle != None:
174174
# Generate the module from cached handle
175175
return generate_module(handle_name, handle)

source/scripts/node/host/source/host.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const script = `#!/usr/bin/env python3
5252
import os
5353
import sys
5454
55-
sys.path.append(os.environ['PORT_LIBRARY_PATH']);
55+
sys.path.append(os.environ['PY_PORT_LIBRARY_PATH']);
5656
5757
from metacall import metacall
5858

source/tests/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ add_subdirectory(metacall_node_reentrant_test)
135135
add_subdirectory(metacall_node_port_test)
136136
add_subdirectory(metacall_node_python_port_mock_test)
137137
add_subdirectory(metacall_node_python_port_ruby_test)
138+
add_subdirectory(metacall_node_callback_test)
138139
add_subdirectory(metacall_distributable_test)
139140
add_subdirectory(metacall_cast_test)
140141
add_subdirectory(metacall_init_fini_test)
@@ -154,14 +155,14 @@ add_subdirectory(metacall_python_reentrant_test)
154155
add_subdirectory(metacall_python_varargs_test)
155156
add_subdirectory(metacall_python_port_test)
156157
add_subdirectory(metacall_python_port_https_test)
158+
add_subdirectory(metacall_python_callback_test)
157159
add_subdirectory(metacall_map_test)
158160
add_subdirectory(metacall_map_await_test)
159161
add_subdirectory(metacall_initialize_test)
160162
add_subdirectory(metacall_initialize_ex_test)
161163
add_subdirectory(metacall_reinitialize_test)
162164
add_subdirectory(metacall_fork_test)
163165
add_subdirectory(metacall_return_monad_test)
164-
add_subdirectory(metacall_callback_test)
165166
add_subdirectory(metacall_callback_complex_test)
166167
add_subdirectory(metacall_ruby_fail_test)
167168
add_subdirectory(metacall_ruby_object_class_test)
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
#
2+
# Executable name and options
3+
#
4+
5+
# Check if loaders, scripts and ports are enabled
6+
if(NOT OPTION_BUILD_LOADERS OR NOT OPTION_BUILD_LOADERS_PY OR NOT OPTION_BUILD_LOADERS_NODE
7+
OR NOT OPTION_BUILD_SCRIPTS OR NOT OPTION_BUILD_SCRIPTS_NODE
8+
OR NOT OPTION_BUILD_PORTS OR NOT OPTION_BUILD_PORTS_PY)
9+
return()
10+
endif()
11+
12+
# Target name
13+
set(target metacall-node-callback-test)
14+
message(STATUS "Test ${target}")
15+
16+
#
17+
# Compiler warnings
18+
#
19+
20+
include(Warnings)
21+
22+
#
23+
# Compiler security
24+
#
25+
26+
include(SecurityFlags)
27+
28+
#
29+
# Sources
30+
#
31+
32+
set(include_path "${CMAKE_CURRENT_SOURCE_DIR}/include/${target}")
33+
set(source_path "${CMAKE_CURRENT_SOURCE_DIR}/source")
34+
35+
set(sources
36+
${source_path}/main.cpp
37+
${source_path}/metacall_node_callback_test.cpp
38+
)
39+
40+
# Group source files
41+
set(header_group "Header Files (API)")
42+
set(source_group "Source Files")
43+
source_group_by_path(${include_path} "\\\\.h$|\\\\.hpp$"
44+
${header_group} ${headers})
45+
source_group_by_path(${source_path} "\\\\.cpp$|\\\\.c$|\\\\.h$|\\\\.hpp$"
46+
${source_group} ${sources})
47+
48+
#
49+
# Create executable
50+
#
51+
52+
# Build executable
53+
add_executable(${target}
54+
${sources}
55+
)
56+
57+
# Create namespaced alias
58+
add_executable(${META_PROJECT_NAME}::${target} ALIAS ${target})
59+
60+
#
61+
# Project options
62+
#
63+
64+
set_target_properties(${target}
65+
PROPERTIES
66+
${DEFAULT_PROJECT_OPTIONS}
67+
FOLDER "${IDE_FOLDER}"
68+
)
69+
70+
#
71+
# Include directories
72+
#
73+
74+
target_include_directories(${target}
75+
PRIVATE
76+
${DEFAULT_INCLUDE_DIRECTORIES}
77+
${PROJECT_BINARY_DIR}/source/include
78+
)
79+
80+
#
81+
# Libraries
82+
#
83+
84+
target_link_libraries(${target}
85+
PRIVATE
86+
${DEFAULT_LIBRARIES}
87+
88+
GTest
89+
90+
${META_PROJECT_NAME}::metacall_distributable
91+
)
92+
93+
#
94+
# Compile definitions
95+
#
96+
97+
target_compile_definitions(${target}
98+
PRIVATE
99+
${DEFAULT_COMPILE_DEFINITIONS}
100+
)
101+
102+
#
103+
# Compile options
104+
#
105+
106+
target_compile_options(${target}
107+
PRIVATE
108+
${DEFAULT_COMPILE_OPTIONS}
109+
)
110+
111+
#
112+
# Linker options
113+
#
114+
115+
target_link_libraries(${target}
116+
PRIVATE
117+
${DEFAULT_LINKER_OPTIONS}
118+
)
119+
120+
#
121+
# Define test
122+
#
123+
124+
add_test(NAME ${target}
125+
COMMAND $<TARGET_FILE:${target}>
126+
)
127+
128+
#
129+
# Define dependencies
130+
#
131+
132+
add_dependencies(${target}
133+
py_loader
134+
node_loader
135+
)
136+
137+
#
138+
# Define test properties
139+
#
140+
141+
set_property(TEST ${target}
142+
PROPERTY LABELS ${target}
143+
)
144+
145+
include(TestEnvironmentVariables)
146+
147+
test_environment_variables(${target}
148+
""
149+
${TESTS_ENVIRONMENT_VARIABLES}
150+
PY_PORT_LIBRARY_PATH=${CMAKE_SOURCE_DIR}/source/ports/py_port
151+
)

source/tests/metacall_callback_test/source/metacall_callback_test.cpp renamed to source/tests/metacall_node_callback_test/source/metacall_node_callback_test.cpp

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424
#include <metacall/metacall_value.h>
2525
#include <metacall/metacall_loaders.h>
2626

27-
class metacall_callback_test : public testing::Test
27+
class metacall_node_callback_test : public testing::Test
2828
{
2929
public:
3030
};
3131

32-
TEST_F(metacall_callback_test, DefaultConstructor)
32+
TEST_F(metacall_node_callback_test, DefaultConstructor)
3333
{
3434
metacall_print_info();
3535

@@ -39,43 +39,8 @@ TEST_F(metacall_callback_test, DefaultConstructor)
3939

4040
ASSERT_EQ((int) 0, (int) metacall_initialize());
4141

42-
// TODO: Python: Solve incompatibility with NodeJS on host script name after clearing it
43-
44-
/* Python */
45-
#if defined(OPTION_BUILD_LOADERS_PY)
46-
#if 0
47-
{
48-
const char * py_scripts[] =
49-
{
50-
"host.py"
51-
};
52-
53-
void * ret = NULL;
54-
55-
EXPECT_EQ((int) 0, (int) metacall_load_from_file("py", py_scripts, sizeof(py_scripts) / sizeof(py_scripts[0]), NULL));
56-
57-
ret = metacall("a");
58-
59-
EXPECT_NE((void *) NULL, (void *) ret);
60-
61-
EXPECT_EQ((double) metacall_value_to_double(ret), (double) 3.0);
62-
63-
metacall_value_destroy(ret);
64-
65-
void * handle = metacall_handle("py", "host");
66-
67-
EXPECT_NE((void *) NULL, (void *) handle);
68-
69-
EXPECT_EQ((int) 0, (int) metacall_clear(handle));
70-
}
71-
#endif
72-
#endif /* OPTION_BUILD_LOADERS_PY */
73-
74-
// TODO: NodeJS: Solve deadlock at the end of execution and with the callback
75-
7642
/* NodeJS */
7743
#if defined(OPTION_BUILD_LOADERS_NODE)
78-
#if 0
7944
{
8045
const char * node_scripts[] =
8146
{
@@ -94,13 +59,12 @@ TEST_F(metacall_callback_test, DefaultConstructor)
9459

9560
metacall_value_destroy(ret);
9661

97-
void * handle = metacall_handle("node", "host");
62+
void * handle = metacall_handle("node", "host.js");
9863

9964
EXPECT_NE((void *) NULL, (void *) handle);
10065

10166
EXPECT_EQ((int) 0, (int) metacall_clear(handle));
10267
}
103-
#endif
10468
#endif /* OPTION_BUILD_LOADERS_NODE */
10569

10670
EXPECT_EQ((int) 0, (int) metacall_destroy());

source/tests/metacall_callback_test/CMakeLists.txt renamed to source/tests/metacall_python_callback_test/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
# Check if loaders, scripts and ports are enabled
66
if(NOT OPTION_BUILD_LOADERS OR NOT OPTION_BUILD_LOADERS_PY OR NOT OPTION_BUILD_LOADERS_NODE
7-
OR NOT OPTION_BUILD_SCRIPTS OR NOT OPTION_BUILD_SCRIPTS_PY OR NOT OPTION_BUILD_SCRIPTS_NODE
8-
OR NOT OPTION_BUILD_PORTS OR NOT OPTION_BUILD_PORTS_PY OR NOT OPTION_BUILD_PORTS_NODE)
7+
OR NOT OPTION_BUILD_SCRIPTS OR NOT OPTION_BUILD_SCRIPTS_PY
8+
OR NOT OPTION_BUILD_PORTS OR NOT OPTION_BUILD_PORTS_PY)
99
return()
1010
endif()
1111

1212
# Target name
13-
set(target metacall-callback-test)
13+
set(target metacall-python-callback-test)
1414
message(STATUS "Test ${target}")
1515

1616
#
@@ -34,7 +34,7 @@ set(source_path "${CMAKE_CURRENT_SOURCE_DIR}/source")
3434

3535
set(sources
3636
${source_path}/main.cpp
37-
${source_path}/metacall_callback_test.cpp
37+
${source_path}/metacall_python_callback_test.cpp
3838
)
3939

4040
# Group source files
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* MetaCall Library by Parra Studios
3+
* A library for providing a foreign function interface calls.
4+
*
5+
* Copyright (C) 2016 - 2021 Vicente Eduardo Ferrer Garcia <[email protected]>
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*
19+
*/
20+
21+
#include <gmock/gmock.h>
22+
23+
int main(int argc, char * argv[])
24+
{
25+
::testing::InitGoogleMock(&argc, argv);
26+
27+
return RUN_ALL_TESTS();
28+
}

0 commit comments

Comments
 (0)