From 397828c1a4e10a2e05586931c57bb6b29fa3397f Mon Sep 17 00:00:00 2001 From: TheoryOfNekomata Date: Sat, 25 Feb 2023 12:35:17 +0800 Subject: [PATCH] Organize codebase Extract tests from source directory. --- CMakeLists.txt | 28 +++++++++++++++---- .../src/packages/game}/data.test.c | 6 ++-- .../src/packages/game}/geometry.test.c | 4 +-- .../src/packages/game}/input.test.c | 22 +++++++-------- .../src/packages/game}/memory.test.c | 2 +- .../src/packages/game}/output.test.c | 2 +- src/packages/log/IZ_intercept.h | 2 +- 7 files changed, 42 insertions(+), 24 deletions(-) rename {src/packages/game/data => __tests__/src/packages/game}/data.test.c (98%) rename {src/packages/game/geometry => __tests__/src/packages/game}/geometry.test.c (98%) rename {src/packages/game/input => __tests__/src/packages/game}/input.test.c (96%) rename {src/packages/game/memory => __tests__/src/packages/game}/memory.test.c (98%) rename {src/packages/game/output => __tests__/src/packages/game}/output.test.c (95%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 54185d3..9e463c5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -76,6 +76,12 @@ include_directories( "${CMAKE_HOME_DIRECTORY}/dependencies/libwebsockets/build/include" "${CMAKE_HOME_DIRECTORY}/dependencies/openssl/${IZ_PROJECT_ARCH}/include" "${CMAKE_HOME_DIRECTORY}/dependencies/sqlite" + + "${CMAKE_HOME_DIRECTORY}" + "${CMAKE_HOME_DIRECTORY}/src/packages" + "${CMAKE_HOME_DIRECTORY}/__mocks__" + "${CMAKE_HOME_DIRECTORY}/__mocks__/src/packages" + "${CMAKE_HOME_DIRECTORY}/__tests__/src/packages" ) if (IZ_PLATFORM STREQUAL "WINDOWS") @@ -95,6 +101,12 @@ elseif(IZ_PLATFORM STREQUAL "MACOS") /usr/local/include /usr/local/include/SDL2 /usr/local/include/openssl + + "${CMAKE_HOME_DIRECTORY}" + "${CMAKE_HOME_DIRECTORY}/src/packages" + "${CMAKE_HOME_DIRECTORY}/__mocks__" + "${CMAKE_HOME_DIRECTORY}/__mocks__/src/packages" + "${CMAKE_HOME_DIRECTORY}/__tests__/src/packages" ) link_directories( @@ -105,6 +117,12 @@ elseif(IZ_PLATFORM STREQUAL "UNIX") /usr/local/include /usr/local/include/SDL2 /usr/local/include/openssl + + "${CMAKE_HOME_DIRECTORY}" + "${CMAKE_HOME_DIRECTORY}/src/packages" + "${CMAKE_HOME_DIRECTORY}/__mocks__" + "${CMAKE_HOME_DIRECTORY}/__mocks__/src/packages" + "${CMAKE_HOME_DIRECTORY}/__tests__/src/packages" ) link_directories( @@ -206,7 +224,7 @@ add_executable( src/packages/game/geometry/IZ_rect.c src/packages/game/geometry/IZ_vector2d.h src/packages/game/geometry/IZ_vector2d.c - src/packages/game/geometry/geometry.test.c + __tests__/src/packages/game/geometry.test.c ) add_executable( @@ -241,7 +259,7 @@ add_executable( src/packages/stdinc/IZ_stdlib.h __mocks__/src/packages/stdinc/IZ_stdlib.mock.h - src/packages/game/input/input.test.c + __tests__/src/packages/game/input.test.c __mocks__/src/packages/config/IZ_config.mock.h ) @@ -263,7 +281,7 @@ add_executable( src/packages/config/IZ_config.h src/packages/game/output/video/IZ_video.h src/packages/game/output/video/IZ_video.c - src/packages/game/output/output.test.c + __tests__/src/packages/game/output.test.c ) add_executable( @@ -287,7 +305,7 @@ add_executable( src/packages/game/data/IZ_list.h src/packages/game/memory/IZ_pool.h src/packages/game/memory/IZ_pool.c - src/packages/game/memory/memory.test.c + __tests__/src/packages/game/memory.test.c ) target_link_libraries( @@ -306,7 +324,7 @@ add_executable( src/packages/game/data/IZ_list.h src/packages/game/data/IZ_list.c - src/packages/game/data/data.test.c + __tests__/src/packages/game/data.test.c ) target_link_libraries( diff --git a/src/packages/game/data/data.test.c b/__tests__/src/packages/game/data.test.c similarity index 98% rename from src/packages/game/data/data.test.c rename to __tests__/src/packages/game/data.test.c index b958599..044ad02 100644 --- a/src/packages/game/data/data.test.c +++ b/__tests__/src/packages/game/data.test.c @@ -1,7 +1,7 @@ #include -#include "../../common/IZ_common.h" -#include "../../../../__mocks__/src/packages/stdinc/IZ_stdlib.mock.h" -#include "IZ_list.h" +#include +#include +#include bool NodeExists(IZ_ListNode** node, u64 _index, IZ_List* list) { return *((u64*) (*node)->value) == 42069; diff --git a/src/packages/game/geometry/geometry.test.c b/__tests__/src/packages/game/geometry.test.c similarity index 98% rename from src/packages/game/geometry/geometry.test.c rename to __tests__/src/packages/game/geometry.test.c index 2c08769..9b5c23a 100644 --- a/src/packages/game/geometry/geometry.test.c +++ b/__tests__/src/packages/game/geometry.test.c @@ -1,6 +1,6 @@ #include -#include "IZ_vector2d.h" -#include "IZ_rect.h" +#include +#include spec("geometry") { describe("vector2d") { diff --git a/src/packages/game/input/input.test.c b/__tests__/src/packages/game/input.test.c similarity index 96% rename from src/packages/game/input/input.test.c rename to __tests__/src/packages/game/input.test.c index 446d42b..1a2b4ea 100644 --- a/src/packages/game/input/input.test.c +++ b/__tests__/src/packages/game/input.test.c @@ -1,15 +1,15 @@ #include -#include "../../../../__mocks__/subprojects/SDL/SDL_keyboard.mock.h" -#include "../../../../__mocks__/subprojects/SDL/SDL_joystick.mock.h" -#include "../../../../__mocks__/subprojects/SDL/SDL_stdinc.mock.h" -#include "../../../../__mocks__/subprojects/minIni/minIni.mock.h" -#include "../../../../__mocks__/subprojects/portmidi/portmidi.mock.h" -#include "../../../../__mocks__/src/packages/stdinc/IZ_string.mock.h" -#include "../../../../__mocks__/src/packages/stdinc/IZ_stdlib.mock.h" -#include "../../../../__mocks__/src/packages/config/IZ_config.mock.h" -#include "IZ_keyboard.h" -#include "IZ_joystick.h" -#include "IZ_midi.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include i16 GenerateAxisValueWithinThreshold(u16 threshold) { return rand() % threshold; diff --git a/src/packages/game/memory/memory.test.c b/__tests__/src/packages/game/memory.test.c similarity index 98% rename from src/packages/game/memory/memory.test.c rename to __tests__/src/packages/game/memory.test.c index e5fd428..1dafc8a 100644 --- a/src/packages/game/memory/memory.test.c +++ b/__tests__/src/packages/game/memory.test.c @@ -2,7 +2,7 @@ #include "../../../../__mocks__/src/packages/log/IZ_log.mock.h" #include "../../../../__mocks__/src/packages/stdinc/IZ_stdlib.mock.h" #include "../../../../__mocks__/src/packages/stdinc/IZ_string.mock.h" -#include "IZ_pool.h" +#include "../../../../src/packages/game/memory/IZ_pool.h" struct DummyInnerStruct { i8 f; diff --git a/src/packages/game/output/output.test.c b/__tests__/src/packages/game/output.test.c similarity index 95% rename from src/packages/game/output/output.test.c rename to __tests__/src/packages/game/output.test.c index 3020c71..8896e11 100644 --- a/src/packages/game/output/output.test.c +++ b/__tests__/src/packages/game/output.test.c @@ -2,7 +2,7 @@ #include "../../../../__mocks__/subprojects/minIni/minIni.mock.h" #include "../../../../__mocks__/subprojects/SDL/SDL_stdinc.mock.h" #include "../../../../__mocks__/subprojects/SDL/SDL_render.mock.h" -#include "video/IZ_video.h" +#include "../../../../src/packages/game/output/video/IZ_video.h" const char* IZ_ConfigGetCommandlineOption(u8 argc, const char* argv[], const char* val) { size_t n = strlen(val); diff --git a/src/packages/log/IZ_intercept.h b/src/packages/log/IZ_intercept.h index 2f89501..103ea41 100644 --- a/src/packages/log/IZ_intercept.h +++ b/src/packages/log/IZ_intercept.h @@ -2,7 +2,7 @@ #define IZ_INTERCEPT_H #include -#include "libwebsockets.h" +#include #include "../common/IZ_common.h" #include "../stdinc/IZ_string.h" #include "IZ_log.h"