Skip to content

Commit 88b617f

Browse files
committed
add test for core_plugin
add support for installing plugins
1 parent c9259ae commit 88b617f

File tree

6 files changed

+375
-4
lines changed

6 files changed

+375
-4
lines changed

source/cli/plugins/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,9 @@ endif()
55

66
# Extension sub-projects
77
add_subdirectory(core_plugin)
8+
9+
#Install plugin directory
10+
install(DIRECTORY ${PROJECT_OUTPUT_DIR}/plugins
11+
DESTINATION ${INSTALL_LIB}
12+
PATTERN "test[-_]*" EXCLUDE
13+
)

source/cli/plugins/core_plugin/source/core_plugin.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,23 @@ void *load(size_t argc, void *args[], void *data)
1414
{
1515
(void)argc;
1616
(void)data;
17+
1718
char *tag = metacall_value_to_string(args[0]);
19+
if (tag == NULL)
20+
{
21+
return metacall_value_create_int(1);
22+
}
23+
1824
size_t size = metacall_value_count(args[1]);
1925

2026
char **scripts = (char **)malloc(sizeof(char *) * size);
2127
void **script_val = metacall_value_to_array(args[1]);
22-
for (int i = 0; i < size; ++i)
28+
if (scripts == NULL || script_val == NULL)
29+
{
30+
return metacall_value_create_int(1);
31+
}
32+
33+
for (size_t i = 0; i < size; ++i)
2334
{
2435
scripts[i] = metacall_value_to_string(script_val[i]);
2536
}
@@ -105,12 +116,11 @@ void *await(size_t argc, void *args[], void *data)
105116

106117
await_cond.wait(lock);
107118

119+
return fdata.v;
108120
/* Unused */
109121
metacall_value_destroy(future);
110122

111123
metacall_allocator_destroy(allocator);
112-
113-
return fdata.v;
114124
}
115125

116126
void *call(size_t argc, void *args[], void *data)
@@ -162,6 +172,7 @@ void *clear(size_t argc, void *args[], void *data)
162172

163173
if (handle == NULL)
164174
{
175+
log_write("metacall", LOG_LEVEL_DEBUG, "handle %s not found in loader (%s)", script, tag);
165176
return metacall_value_create_int(1);
166177
}
167178

@@ -240,7 +251,7 @@ int core_plugin(void *loader, void *context)
240251
}
241252

242253
{
243-
enum metacall_value_id arg_types[] = { METACALL_STRING, METACALL_STRING };
254+
enum metacall_value_id arg_types[] = { METACALL_STRING, METACALL_ARRAY };
244255
if (metacall_register_loaderv(loader, context, "load", load, METACALL_INT, sizeof(arg_types) / sizeof(arg_types[0]), arg_types) != 0)
245256
{
246257
log_write("metacall", LOG_LEVEL_DEBUG, "Failed to register function: load");

source/tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,4 @@ add_subdirectory(metacall_library_path_without_env_vars_test)
228228
add_subdirectory(metacall_ext_test)
229229
add_subdirectory(metacall_plugin_extension_test)
230230
add_subdirectory(metacall_plugin_extension_local_test)
231+
add_subdirectory(metacall_core_plugin_test)
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
# Check if this loader is enabled
2+
if(NOT OPTION_BUILD_LOADERS OR NOT OPTION_BUILD_LOADERS_EXT OR NOT OPTION_BUILD_LOADERS_NODE OR NOT OPTION_BUILD_LOADERS_PY OR NOT OPTION_BUILD_SCRIPTS_EXT OR NOT OPTION_BUILD_SCRIPTS_NODE OR NOT OPTION_BUILD_SCRIPTS_PY)
3+
return()
4+
endif()
5+
6+
#
7+
# Executable name and options
8+
#
9+
10+
# Target name
11+
set(target metacall-core-plugin-test)
12+
message(STATUS "Test ${target}")
13+
14+
#
15+
# Compiler warnings
16+
#
17+
18+
include(Warnings)
19+
20+
#
21+
# Compiler security
22+
#
23+
24+
include(SecurityFlags)
25+
26+
#
27+
# Sources
28+
#
29+
30+
set(include_path "${CMAKE_CURRENT_SOURCE_DIR}/include/${target}")
31+
set(source_path "${CMAKE_CURRENT_SOURCE_DIR}/source")
32+
33+
set(sources
34+
${source_path}/main.cpp
35+
${source_path}/metacall_core_plugin_test.cpp
36+
)
37+
38+
# Group source files
39+
set(header_group "Header Files (API)")
40+
set(source_group "Source Files")
41+
source_group_by_path(${include_path} "\\\\.h$|\\\\.hpp$"
42+
${header_group} ${headers})
43+
source_group_by_path(${source_path} "\\\\.cpp$|\\\\.c$|\\\\.h$|\\\\.hpp$"
44+
${source_group} ${sources})
45+
46+
#
47+
# Create executable
48+
#
49+
50+
# Build executable
51+
add_executable(${target}
52+
${sources}
53+
)
54+
55+
# Create namespaced alias
56+
add_executable(${META_PROJECT_NAME}::${target} ALIAS ${target})
57+
58+
#
59+
# Project options
60+
#
61+
62+
set_target_properties(${target}
63+
PROPERTIES
64+
${DEFAULT_PROJECT_OPTIONS}
65+
FOLDER "${IDE_FOLDER}"
66+
)
67+
68+
#
69+
# Include directories
70+
#
71+
72+
target_include_directories(${target}
73+
PRIVATE
74+
${DEFAULT_INCLUDE_DIRECTORIES}
75+
${PROJECT_BINARY_DIR}/source/include
76+
)
77+
78+
#
79+
# Libraries
80+
#
81+
82+
target_link_libraries(${target}
83+
PRIVATE
84+
${DEFAULT_LIBRARIES}
85+
86+
GTest
87+
88+
${META_PROJECT_NAME}::metacall
89+
)
90+
91+
#
92+
# Compile definitions
93+
#
94+
95+
target_compile_definitions(${target}
96+
PRIVATE
97+
${DEFAULT_COMPILE_DEFINITIONS}
98+
)
99+
100+
#
101+
# Compile options
102+
#
103+
104+
target_compile_options(${target}
105+
PRIVATE
106+
${DEFAULT_COMPILE_OPTIONS}
107+
)
108+
109+
#
110+
#Define Macros
111+
#
112+
113+
add_compile_definitions(CORE_PLUGIN_PATH="${PROJECT_OUTPUT_DIR}/plugins/core_plugin/metacall-core_plugin.json")
114+
115+
#
116+
# Linker options
117+
#
118+
119+
target_link_libraries(${target}
120+
PRIVATE
121+
${DEFAULT_LINKER_OPTIONS}
122+
)
123+
124+
#
125+
# Define test
126+
#
127+
128+
add_test(NAME ${target}
129+
COMMAND $<TARGET_FILE:${target}>
130+
)
131+
132+
#
133+
# Define dependencies
134+
#
135+
136+
add_dependencies(${target}
137+
ext_loader
138+
node_loader
139+
py_loader
140+
core_plugin
141+
)
142+
143+
#
144+
# Define test properties
145+
#
146+
147+
set_property(TEST ${target}
148+
PROPERTY LABELS ${target}
149+
)
150+
151+
include(TestEnvironmentVariables)
152+
153+
test_environment_variables(${target}
154+
""
155+
${TESTS_ENVIRONMENT_VARIABLES}
156+
)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Loader Library by Parra Studios
3+
* A plugin for loading ruby code at run-time into a process.
4+
*
5+
* Copyright (C) 2016 - 2022 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 <gtest/gtest.h>
22+
23+
int main(int argc, char *argv[])
24+
{
25+
::testing::InitGoogleTest(&argc, argv);
26+
27+
return RUN_ALL_TESTS();
28+
}

0 commit comments

Comments
 (0)