diff --git a/CHANGES b/CHANGES index 110bd77d3..457cf3a96 100644 --- a/CHANGES +++ b/CHANGES @@ -40,6 +40,7 @@ Misc: - Qt: Don't rebuild library view if style hasn't changed - Qt: Redo GameController into multiple classes - SDL: Fix 2.0.5 build on macOS under some circumstances + - Test: Restructure test suite into multiple executables 0.6.0: (2017-07-16) Features: diff --git a/CMakeLists.txt b/CMakeLists.txt index 229d7e5a7..0a6a7503d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -861,10 +861,16 @@ if(BUILD_SUITE) include_directories(AFTER ${CMOCKA_INCLUDE_DIRS}) link_directories(${CMOCKA_LIBRARY_DIRS}) - add_executable(${BINARY_NAME}-suite ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/test/suite-main.c ${TEST_SRC}) - target_link_libraries(${BINARY_NAME}-suite ${BINARY_NAME} ${PLATFORM_LIBRARY} cmocka) - set_target_properties(${BINARY_NAME}-suite PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}") - add_test(${BINARY_NAME}-suite ${BINARY_NAME}-suite) + foreach(TEST IN LISTS TEST_SRC) + string(REPLACE "${CMAKE_SOURCE_DIR}/src/" "" TEST_NAME "${TEST}") + string(REPLACE "/" "-" TEST_NAME "${TEST_NAME}") + string(REPLACE "-test" "" TEST_NAME "${TEST_NAME}") + string(REPLACE ".c" "" TEST_NAME "${TEST_NAME}") + add_executable(test-${TEST_NAME} ${TEST}) + target_link_libraries(test-${TEST_NAME} ${BINARY_NAME} ${PLATFORM_LIBRARY} cmocka) + set_target_properties(test-${TEST_NAME} PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}") + add_test(${TEST_NAME} test-${TEST_NAME}) + endforeach() endif() if(BUILD_EXAMPLE) diff --git a/src/core/test/core.c b/src/core/test/core.c index 3fcebaf31..10c566b2c 100644 --- a/src/core/test/core.c +++ b/src/core/test/core.c @@ -34,9 +34,3 @@ M_TEST_SUITE_DEFINE(mCore, #endif cmocka_unit_test(findNullVF), cmocka_unit_test(findEmpty)) - -int TestRunCore(void) { - int failures = 0; - failures += M_TEST_SUITE_RUN(mCore); - return failures; -} diff --git a/src/gb/test/gb.c b/src/gb/test/gb.c deleted file mode 100644 index 2a21b3228..000000000 --- a/src/gb/test/gb.c +++ /dev/null @@ -1,20 +0,0 @@ -/* Copyright (c) 2013-2016 Jeffrey Pfau - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "util/test/suite.h" - -M_TEST_SUITE_DECLARE(GBCore); -M_TEST_SUITE_DECLARE(GBMBC); -M_TEST_SUITE_DECLARE(GBMemory); -M_TEST_SUITE_DECLARE(GBRTC); - -int TestRunGB(void) { - int failures = 0; - failures += M_TEST_SUITE_RUN(GBCore); - failures += M_TEST_SUITE_RUN(GBMBC); - failures += M_TEST_SUITE_RUN(GBMemory); - failures += M_TEST_SUITE_RUN(GBRTC); - return failures; -} diff --git a/src/gb/test/gb.h b/src/gb/test/gb.h deleted file mode 100644 index 572a21466..000000000 --- a/src/gb/test/gb.h +++ /dev/null @@ -1,12 +0,0 @@ -/* Copyright (c) 2013-2016 Jeffrey Pfau - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef TEST_GB_H -#define TEST_GB_H -#include - -int TestRunGB(void); - -#endif diff --git a/src/gba/test/gba.c b/src/gba/test/gba.c deleted file mode 100644 index 58186cd00..000000000 --- a/src/gba/test/gba.c +++ /dev/null @@ -1,14 +0,0 @@ -/* Copyright (c) 2013-2016 Jeffrey Pfau - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "util/test/suite.h" - -M_TEST_SUITE_DECLARE(GBACore); - -int TestRunGBA(void) { - int failures = 0; - failures += M_TEST_SUITE_RUN(GBACore); - return failures; -} diff --git a/src/gba/test/gba.h b/src/gba/test/gba.h deleted file mode 100644 index 1e50b1d39..000000000 --- a/src/gba/test/gba.h +++ /dev/null @@ -1,12 +0,0 @@ -/* Copyright (c) 2013-2016 Jeffrey Pfau - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef TEST_GBA_H -#define TEST_GBA_H -#include - -int TestRunGBA(void); - -#endif diff --git a/src/platform/test/suite-main.c b/src/platform/test/suite-main.c deleted file mode 100644 index 2eb03f626..000000000 --- a/src/platform/test/suite-main.c +++ /dev/null @@ -1,27 +0,0 @@ -/* Copyright (c) 2013-2016 Jeffrey Pfau - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "util/test/suite.h" - -#include "util/test/util.h" -#include "core/test/core.h" -#ifdef M_CORE_GBA -#include "gba/test/gba.h" -#endif -#ifdef M_CORE_GB -#include "gb/test/gb.h" -#endif - -int main() { - int failures = TestRunUtil(); - failures += TestRunCore(); -#ifdef M_CORE_GBA - failures += TestRunGBA(); -#endif -#ifdef M_CORE_GB - failures += TestRunGB(); -#endif - return failures != 0; -} diff --git a/src/util/test/suite.h b/src/util/test/suite.h index dd947830d..5fc85938a 100644 --- a/src/util/test/suite.h +++ b/src/util/test/suite.h @@ -12,14 +12,12 @@ #define M_TEST_DEFINE(NAME) static void NAME (void **state ATTRIBUTE_UNUSED) -#define M_TEST_SUITE(NAME) _testSuite_ ## NAME -#define M_TEST_SUITE_RUN(NAME) (printf("\nRunning suite %s\n", # NAME), M_TEST_SUITE(NAME)()) #define M_TEST_SUITE_DEFINE(NAME, ...) M_TEST_SUITE_DEFINE_EX(NAME, NULL, NULL, __VA_ARGS__) #define M_TEST_SUITE_DEFINE_SETUP(NAME, ...) M_TEST_SUITE_DEFINE_EX(NAME, _testSuite_setup_ ## NAME, NULL, __VA_ARGS__) #define M_TEST_SUITE_DEFINE_TEARDOWN(NAME, ...) M_TEST_SUITE_DEFINE_EX(NAME, NULL, _testSuite_teardown_ ## NAME, __VA_ARGS__) #define M_TEST_SUITE_DEFINE_SETUP_TEARDOWN(NAME, ...) M_TEST_SUITE_DEFINE_EX(NAME, _testSuite_setup_ ## NAME, _testSuite_teardown_ ## NAME, __VA_ARGS__) #define M_TEST_SUITE_DEFINE_EX(NAME, SETUP, TEARDOWN, ...) \ - int M_TEST_SUITE(NAME) (void) { \ + int main(void) { \ const static struct CMUnitTest tests[] = { \ __VA_ARGS__ \ }; \ @@ -29,6 +27,4 @@ #define M_TEST_SUITE_SETUP(NAME) static int _testSuite_setup_ ## NAME (void **state ATTRIBUTE_UNUSED) #define M_TEST_SUITE_TEARDOWN(NAME) static int _testSuite_teardown_ ## NAME (void **state ATTRIBUTE_UNUSED) -#define M_TEST_SUITE_DECLARE(NAME) extern int M_TEST_SUITE(NAME) (void) - #endif diff --git a/src/util/test/util.c b/src/util/test/util.c deleted file mode 100644 index 658601c4f..000000000 --- a/src/util/test/util.c +++ /dev/null @@ -1,16 +0,0 @@ -/* Copyright (c) 2013-2016 Jeffrey Pfau - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "util/test/suite.h" - -M_TEST_SUITE_DECLARE(TextCodec); -M_TEST_SUITE_DECLARE(VFS); - -int TestRunUtil(void) { - int failures = 0; - failures += M_TEST_SUITE_RUN(TextCodec); - failures += M_TEST_SUITE_RUN(VFS); - return failures; -} diff --git a/src/util/test/util.h b/src/util/test/util.h deleted file mode 100644 index 0a665b995..000000000 --- a/src/util/test/util.h +++ /dev/null @@ -1,12 +0,0 @@ -/* Copyright (c) 2013-2016 Jeffrey Pfau - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef TEST_UTIL_H -#define TEST_UTIL_H -#include - -int TestRunUtil(void); - -#endif