Skip to content

Commit

Permalink
Corrected misspelling in scripts, we need error handling to catch thi…
Browse files Browse the repository at this point in the history
…s easily...
  • Loading branch information
viferga committed Apr 22, 2021
1 parent 4baa356 commit d4bc051
Show file tree
Hide file tree
Showing 6 changed files with 269 additions and 8 deletions.
8 changes: 4 additions & 4 deletions source/loaders/ts_loader/bootstrap/lib/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ const inspect = (handle, equal = assert.notDeepStrictEqual) => {

// Test load from memory
inspect(load_from_memory('memory_module', `
export function mem_sum(left: number, rigth: number): number {
return left + rigth;
export function mem_sum(left: number, right: number): number {
return left + right;
}
export async function mem_sum_async(left: number, rigth: number): number {
return left + rigth;
export async function mem_sum_async(left: number, right: number): number {
return left + right;
}
`, {}));

Expand Down
8 changes: 4 additions & 4 deletions source/scripts/typescript/typedfunc/source/typedfunc.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use strict';

export function typed_sum(left: number, rigth: number): number {
return left + rigth;
export function typed_sum(left: number, right: number): number {
return left + right;
}

export async function typed_sum_async(left: number, rigth: number): Promise<number> {
return left + rigth;
export async function typed_sum_async(left: number, right: number): Promise<number> {
return left + right;
}

export function build_name(first: string, last = 'Smith') {
Expand Down
1 change: 1 addition & 0 deletions source/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ add_subdirectory(metacall_file_test)
add_subdirectory(metacall_file_fail_test)
add_subdirectory(metacall_typescript_test)
add_subdirectory(metacall_typescript_node_test)
add_subdirectory(metacall_typescript_call_map_test)
#add_subdirectory(metacall_typescript_tsx_test) # TODO: Download react dependencies locally instead of globally
add_subdirectory(metacall_lua_test)
add_subdirectory(metacall_rpc_test)
Expand Down
149 changes: 149 additions & 0 deletions source/tests/metacall_typescript_call_map_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
# Check if this loader is enabled
if(NOT OPTION_BUILD_LOADERS OR NOT OPTION_BUILD_LOADERS_NODE OR NOT OPTION_BUILD_LOADERS_TS
OR NOT OPTION_BUILD_SCRIPTS OR NOT OPTION_BUILD_SCRIPTS_NODE OR NOT OPTION_BUILD_SCRIPTS_TS)
return()
endif()

#
# Executable name and options
#

# Target name
set(target metacall-typescript-call-map-test)
message(STATUS "Test ${target}")

#
# Compiler warnings
#

include(Warnings)

#
# Compiler security
#

include(SecurityFlags)

#
# Sources
#

set(include_path "${CMAKE_CURRENT_SOURCE_DIR}/include/${target}")
set(source_path "${CMAKE_CURRENT_SOURCE_DIR}/source")

set(sources
${source_path}/main.cpp
${source_path}/metacall_typescript_call_map_test.cpp
)

# Group source files
set(header_group "Header Files (API)")
set(source_group "Source Files")
source_group_by_path(${include_path} "\\\\.h$|\\\\.hpp$"
${header_group} ${headers})
source_group_by_path(${source_path} "\\\\.cpp$|\\\\.c$|\\\\.h$|\\\\.hpp$"
${source_group} ${sources})

#
# Create executable
#

# Build executable
add_executable(${target}
${sources}
)

# Create namespaced alias
add_executable(${META_PROJECT_NAME}::${target} ALIAS ${target})

#
# Project options
#

set_target_properties(${target}
PROPERTIES
${DEFAULT_PROJECT_OPTIONS}
FOLDER "${IDE_FOLDER}"
)

#
# Include directories
#

target_include_directories(${target}
PRIVATE
${DEFAULT_INCLUDE_DIRECTORIES}
${PROJECT_BINARY_DIR}/source/include
)

#
# Libraries
#

target_link_libraries(${target}
PRIVATE
${DEFAULT_LIBRARIES}

GTest

${META_PROJECT_NAME}::metacall
)

#
# Compile definitions
#

target_compile_definitions(${target}
PRIVATE
${DEFAULT_COMPILE_DEFINITIONS}
)

#
# Compile options
#

target_compile_options(${target}
PRIVATE
${DEFAULT_COMPILE_OPTIONS}
)

#
# Linker options
#

target_link_libraries(${target}
PRIVATE
${DEFAULT_LINKER_OPTIONS}
)

#
# Define test
#

add_test(NAME ${target}
COMMAND $<TARGET_FILE:${target}>
)

#
# Define dependencies
#

add_dependencies(${target}
node_loader
ts_loader
)

#
# Define test properties
#

set_property(TEST ${target}
PROPERTY LABELS ${target}
)

include(TestEnvironmentVariables)

test_environment_variables(${target}
""
${TESTS_ENVIRONMENT_VARIABLES}
)
28 changes: 28 additions & 0 deletions source/tests/metacall_typescript_call_map_test/source/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* MetaCall Library by Parra Studios
* A library for providing a foreign function interface calls.
*
* Copyright (C) 2016 - 2021 Vicente Eduardo Ferrer Garcia <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#include <gtest/gtest.h>

int main(int argc, char *argv[])
{
::testing::InitGoogleTest(&argc, argv);

return RUN_ALL_TESTS();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* MetaCall Library by Parra Studios
* A library for providing a foreign function interface calls.
*
* Copyright (C) 2016 - 2021 Vicente Eduardo Ferrer Garcia <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#include <gtest/gtest.h>

#include <metacall/metacall.h>
#include <metacall/metacall_loaders.h>
#include <metacall/metacall_value.h>

class metacall_typescript_call_map_test : public testing::Test
{
public:
};

TEST_F(metacall_typescript_call_map_test, DefaultConstructor)
{
metacall_print_info();

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

struct metacall_allocator_std_type std_ctx = { &std::malloc, &std::realloc, &std::free };

void *allocator = metacall_allocator_create(METACALL_ALLOCATOR_STD, (void *)&std_ctx);

/* TypeScript */
#if defined(OPTION_BUILD_LOADERS_TS)
{
const char *ts_scripts[] = {
"typedfunc.ts"
};

/* Load scripts */
EXPECT_EQ((int)0, (int)metacall_load_from_file("ts", ts_scripts, sizeof(ts_scripts) / sizeof(ts_scripts[0]), NULL));

/* Test typed sum */
static const char args_map[] = "{\"left\":10,\"right\":2}";

void *ret = metacallfms(metacall_function("typed_sum"), args_map, sizeof(args_map), allocator);

EXPECT_NE((void *)NULL, (void *)ret);

EXPECT_EQ((double)metacall_value_to_double(ret), (double)12.0);

metacall_value_destroy(ret);
}
#endif /* OPTION_BUILD_LOADERS_TS */

/* Print inspect information */
{
size_t size = 0;

char *inspect_str = metacall_inspect(&size, allocator);

EXPECT_NE((char *)NULL, (char *)inspect_str);

EXPECT_GT((size_t)size, (size_t)0);

std::cout << inspect_str << std::endl;

metacall_allocator_free(allocator, inspect_str);
}

metacall_allocator_destroy(allocator);

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

0 comments on commit d4bc051

Please sign in to comment.