From e5b8ac1006eb587bd2ef1149f36bc140c40da74e Mon Sep 17 00:00:00 2001 From: Akos Kiss Date: Fri, 21 Apr 2017 12:06:22 +0200 Subject: [PATCH] Split unit tests into separate directories The unit tests should follow the component structure, so this patch moves all `jerry-core` unit tests under `tests/unit-core` and the `jerry-libm` unit tests under `tests/unit-libm`. JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu --- CMakeLists.txt | 5 ++- tests/{unit => unit-core}/CMakeLists.txt | 6 +-- tests/{unit => unit-core}/test-api.c | 0 tests/{unit => unit-core}/test-common.h | 0 tests/{unit => unit-core}/test-date-helpers.c | 0 tests/{unit => unit-core}/test-heap.c | 0 .../test-lit-char-helpers.c | 0 .../test-literal-storage.c | 0 tests/{unit => unit-core}/test-longjmp.c | 0 .../test-number-to-integer.c | 0 .../test-number-to-string.c | 0 tests/{unit => unit-core}/test-poolman.c | 0 .../test-string-to-number.c | 0 tests/{unit => unit-core}/test-strings.c | 0 tests/{unit => unit-core}/test-user-context.c | 0 tests/unit-libm/CMakeLists.txt | 41 +++++++++++++++++++ tests/{unit => unit-libm}/test-libm.c | 5 ++- tests/{unit => unit-libm}/test-libm.inc.h | 7 ++-- tools/gen-test-libm.sh | 2 +- tools/unit-tests/gen-test-libm.c | 9 ++-- 20 files changed, 60 insertions(+), 15 deletions(-) rename tests/{unit => unit-core}/CMakeLists.txt (93%) rename tests/{unit => unit-core}/test-api.c (100%) rename tests/{unit => unit-core}/test-common.h (100%) rename tests/{unit => unit-core}/test-date-helpers.c (100%) rename tests/{unit => unit-core}/test-heap.c (100%) rename tests/{unit => unit-core}/test-lit-char-helpers.c (100%) rename tests/{unit => unit-core}/test-literal-storage.c (100%) rename tests/{unit => unit-core}/test-longjmp.c (100%) rename tests/{unit => unit-core}/test-number-to-integer.c (100%) rename tests/{unit => unit-core}/test-number-to-string.c (100%) rename tests/{unit => unit-core}/test-poolman.c (100%) rename tests/{unit => unit-core}/test-string-to-number.c (100%) rename tests/{unit => unit-core}/test-strings.c (100%) rename tests/{unit => unit-core}/test-user-context.c (100%) create mode 100644 tests/unit-libm/CMakeLists.txt rename tests/{unit => unit-libm}/test-libm.c (96%) rename tests/{unit => unit-libm}/test-libm.inc.h (99%) diff --git a/CMakeLists.txt b/CMakeLists.txt index ace26af1d9..5b8a4eee6a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -239,5 +239,8 @@ endif() # Unittests if(UNITTESTS) - add_subdirectory(tests/unit) + add_subdirectory(tests/unit-core) + if(JERRY_LIBM) + add_subdirectory(tests/unit-libm) + endif() endif() diff --git a/tests/unit/CMakeLists.txt b/tests/unit-core/CMakeLists.txt similarity index 93% rename from tests/unit/CMakeLists.txt rename to tests/unit-core/CMakeLists.txt index 5da7ae0515..5a42e7dcd5 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit-core/CMakeLists.txt @@ -13,7 +13,7 @@ # limitations under the License. cmake_minimum_required (VERSION 2.8.12) -project (Unittest C) +project (unit-core C) if (NOT IS_ABSOLUTE ${FEATURE_PROFILE}) set(FEATURE_PROFILE "${CMAKE_SOURCE_DIR}/jerry-core/profiles/${FEATURE_PROFILE}.profile") @@ -27,7 +27,7 @@ endif() file(GLOB SOURCE_UNIT_TEST_MAIN_MODULES *.c) # Unit tests declaration -add_custom_target(unittests) +add_custom_target(unittests-core) foreach(SOURCE_UNIT_TEST_MAIN ${SOURCE_UNIT_TEST_MAIN_MODULES}) get_filename_component(TARGET_NAME ${SOURCE_UNIT_TEST_MAIN} NAME_WE) @@ -41,5 +41,5 @@ foreach(SOURCE_UNIT_TEST_MAIN ${SOURCE_UNIT_TEST_MAIN_MODULES}) target_link_libraries(${TARGET_NAME} jerry-core) - add_dependencies(unittests ${TARGET_NAME}) + add_dependencies(unittests-core ${TARGET_NAME}) endforeach() diff --git a/tests/unit/test-api.c b/tests/unit-core/test-api.c similarity index 100% rename from tests/unit/test-api.c rename to tests/unit-core/test-api.c diff --git a/tests/unit/test-common.h b/tests/unit-core/test-common.h similarity index 100% rename from tests/unit/test-common.h rename to tests/unit-core/test-common.h diff --git a/tests/unit/test-date-helpers.c b/tests/unit-core/test-date-helpers.c similarity index 100% rename from tests/unit/test-date-helpers.c rename to tests/unit-core/test-date-helpers.c diff --git a/tests/unit/test-heap.c b/tests/unit-core/test-heap.c similarity index 100% rename from tests/unit/test-heap.c rename to tests/unit-core/test-heap.c diff --git a/tests/unit/test-lit-char-helpers.c b/tests/unit-core/test-lit-char-helpers.c similarity index 100% rename from tests/unit/test-lit-char-helpers.c rename to tests/unit-core/test-lit-char-helpers.c diff --git a/tests/unit/test-literal-storage.c b/tests/unit-core/test-literal-storage.c similarity index 100% rename from tests/unit/test-literal-storage.c rename to tests/unit-core/test-literal-storage.c diff --git a/tests/unit/test-longjmp.c b/tests/unit-core/test-longjmp.c similarity index 100% rename from tests/unit/test-longjmp.c rename to tests/unit-core/test-longjmp.c diff --git a/tests/unit/test-number-to-integer.c b/tests/unit-core/test-number-to-integer.c similarity index 100% rename from tests/unit/test-number-to-integer.c rename to tests/unit-core/test-number-to-integer.c diff --git a/tests/unit/test-number-to-string.c b/tests/unit-core/test-number-to-string.c similarity index 100% rename from tests/unit/test-number-to-string.c rename to tests/unit-core/test-number-to-string.c diff --git a/tests/unit/test-poolman.c b/tests/unit-core/test-poolman.c similarity index 100% rename from tests/unit/test-poolman.c rename to tests/unit-core/test-poolman.c diff --git a/tests/unit/test-string-to-number.c b/tests/unit-core/test-string-to-number.c similarity index 100% rename from tests/unit/test-string-to-number.c rename to tests/unit-core/test-string-to-number.c diff --git a/tests/unit/test-strings.c b/tests/unit-core/test-strings.c similarity index 100% rename from tests/unit/test-strings.c rename to tests/unit-core/test-strings.c diff --git a/tests/unit/test-user-context.c b/tests/unit-core/test-user-context.c similarity index 100% rename from tests/unit/test-user-context.c rename to tests/unit-core/test-user-context.c diff --git a/tests/unit-libm/CMakeLists.txt b/tests/unit-libm/CMakeLists.txt new file mode 100644 index 0000000000..06d92077d7 --- /dev/null +++ b/tests/unit-libm/CMakeLists.txt @@ -0,0 +1,41 @@ +# Copyright JS Foundation and other contributors, http://js.foundation +# +# 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. + +cmake_minimum_required (VERSION 2.8.12) +project (unit-libm C) + +# Unit tests main modules +file(GLOB SOURCE_UNIT_TEST_MAIN_MODULES *.c) + +# Unit tests declaration +add_custom_target(unittests-libm) + +foreach(SOURCE_UNIT_TEST_MAIN ${SOURCE_UNIT_TEST_MAIN_MODULES}) + get_filename_component(TARGET_NAME ${SOURCE_UNIT_TEST_MAIN} NAME_WE) + set(TARGET_NAME unit-${TARGET_NAME}) + + add_executable(${TARGET_NAME} ${SOURCE_UNIT_TEST_MAIN}) + set_property(TARGET ${TARGET_NAME} + PROPERTY LINK_FLAGS "${LINKER_FLAGS_COMMON}") + + link_directories(${CMAKE_BINARY_DIR}) + + set(TARGET_LIBS jerry-libm) + if(JERRY_LIBC) + set(TARGET_LIBS ${TARGET_LIBS} jerry-libc) + endif() + target_link_libraries(${TARGET_NAME} ${TARGET_LIBS}) + + add_dependencies(unittests-libm ${TARGET_NAME}) +endforeach() diff --git a/tests/unit/test-libm.c b/tests/unit-libm/test-libm.c similarity index 96% rename from tests/unit/test-libm.c rename to tests/unit-libm/test-libm.c index bcd5403069..9fc33bbe4c 100644 --- a/tests/unit/test-libm.c +++ b/tests/unit-libm/test-libm.c @@ -17,7 +17,10 @@ * Unit test for jerry-libm */ -#include "test-common.h" +#include +#include +#include +#include static bool passed = true; diff --git a/tests/unit/test-libm.inc.h b/tests/unit-libm/test-libm.inc.h similarity index 99% rename from tests/unit/test-libm.inc.h rename to tests/unit-libm/test-libm.inc.h index 17221b04a4..00f2070d96 100644 --- a/tests/unit/test-libm.inc.h +++ b/tests/unit-libm/test-libm.inc.h @@ -13,10 +13,9 @@ * limitations under the License. */ -/* - * Generated by tools/gen-test-libm.sh - * DO NOT EDIT!!! - */ +/* This file is automatically generated by the gen-test-libm.sh script. + * Do not edit! */ + check_double ("acos (0.0)", acos (0.0), 1.57079632679489655800E+00); check_double ("acos (-0.0)", acos (-0.0), 1.57079632679489655800E+00); check_double ("acos (1.0)", acos (1.0), 0.00000000000000000000E+00); diff --git a/tools/gen-test-libm.sh b/tools/gen-test-libm.sh index dc2eb61307..64bba36e3b 100755 --- a/tools/gen-test-libm.sh +++ b/tools/gen-test-libm.sh @@ -15,5 +15,5 @@ # limitations under the License. make -C tools/unit-tests build -tools/unit-tests/gen-test-libm >tests/unit/test-libm.inc.h +tools/unit-tests/gen-test-libm >tests/unit-libm/test-libm.inc.h make -C tools/unit-tests clean diff --git a/tools/unit-tests/gen-test-libm.c b/tools/unit-tests/gen-test-libm.c index 98b5634870..12dddd84d6 100644 --- a/tools/unit-tests/gen-test-libm.c +++ b/tools/unit-tests/gen-test-libm.c @@ -32,7 +32,7 @@ int main (int argc, char **args) { - printf ("/* Copyright JS Foundation and other contributors, http://js.foundation + printf ("/* Copyright JS Foundation and other contributors, http://js.foundation\n" " *\n" " * Licensed under the Apache License, Version 2.0 (the \"License\");\n" " * you may not use this file except in compliance with the License.\n" @@ -47,10 +47,9 @@ main (int argc, char **args) " * limitations under the License.\n" " */\n" "\n" - "/*\n" - " * Generated by tools/gen-test-libm.sh\n" - " * DO NOT EDIT!!!\n" - " */\n"); + "/* This file is automatically generated by the gen-test-libm.sh script.\n" + " * Do not edit! */\n" + "\n"); /* acos tests */ GEN_DBL_TEST (acos (0.0));