From ff90146aeecad96bdb3d5a9af2d8a382095bdfe0 Mon Sep 17 00:00:00 2001 From: Francesco Date: Fri, 12 Sep 2025 03:54:30 +0200 Subject: [PATCH] refactor(test): remove relative include --- meson.build | 41 ++++++++++++++++++++++++++++++++--------- test/hashmap/hm1.c | 3 +-- test/queue/queue1.c | 3 +-- test/socket/socket1.c | 3 +-- test/stack/stack1.c | 3 +-- test/string/str1.c | 3 +-- test/string/str2.c | 3 +-- test/string/str3.c | 3 +-- test/vector/vec1.c | 3 +-- 9 files changed, 40 insertions(+), 25 deletions(-) diff --git a/meson.build b/meson.build index cbe0fbb..218580f 100644 --- a/meson.build +++ b/meson.build @@ -2,7 +2,7 @@ project( 'testlib', 'c', version: '0.1', - default_options: ['c_std=c17','warning_level=3'], + default_options: ['c_std=c17', 'warning_level=3'], ) cc = meson.get_compiler('c') @@ -11,23 +11,23 @@ cc = meson.get_compiler('c') lib_src = files( 'hashmap/myhashmap.c', 'queue/myqueue.c', + 'socket/mysocket.c', + 'stack/mystack.c', 'string/mystring.c', 'vector/myvector.c', - 'stack/mystack.c', - 'socket/mysocket.c', ) # Test files test_src = files( - 'test/test.c', 'test/hashmap/hm1.c', 'test/queue/queue1.c', + 'test/socket/socket1.c', + 'test/stack/stack1.c', 'test/string/str1.c', 'test/string/str2.c', 'test/string/str3.c', + 'test/test.c', 'test/vector/vec1.c', - 'test/stack/stack1.c', - 'test/socket/socket1.c', ) # Windows Socket lib @@ -35,12 +35,35 @@ winsock_dep = cc.find_library('ws2_32', required: false) # Include directories inc_dir = include_directories('string', 'queue', 'hashmap', 'vector', 'stack', 'socket') +win_inc_dir = include_directories('c:/include/') # Static library -myclib_lib = static_library('myclib', lib_src, include_directories: inc_dir, dependencies: winsock_dep, install: true) +myclib_lib = static_library( + 'myclib', + lib_src, + include_directories: inc_dir, + dependencies: winsock_dep, + install: true, +) # Install headers -install_headers(['hashmap/myhashmap.h', 'queue/myqueue.h', 'string/mystring.h', 'vector/myvector.h', 'stack/mystack.h', 'socket/mysocket.h'], subdir: 'myclib') +install_headers( + [ + 'hashmap/myhashmap.h', + 'queue/myqueue.h', + 'string/mystring.h', + 'vector/myvector.h', + 'stack/mystack.h', + 'socket/mysocket.h', + ], + subdir: 'myclib', +) # Test executable -executable('testlib', lib_src + test_src, include_directories: inc_dir, dependencies: winsock_dep) +executable( + 'testlib', + lib_src + test_src, + include_directories: [inc_dir, win_inc_dir], + dependencies: winsock_dep, + link_with: myclib_lib, +) diff --git a/test/hashmap/hm1.c b/test/hashmap/hm1.c index 0d345fd..02fb189 100644 --- a/test/hashmap/hm1.c +++ b/test/hashmap/hm1.c @@ -1,10 +1,9 @@ #include +#include #include #include #include -#include "../../hashmap/myhashmap.h" - #define MAX_STR_LEN 64 /* My custom data type stored as value */ diff --git a/test/queue/queue1.c b/test/queue/queue1.c index 75603db..b258a63 100644 --- a/test/queue/queue1.c +++ b/test/queue/queue1.c @@ -1,6 +1,5 @@ #include - -#include "../../queue/myqueue.h" +#include void test_queue1(void) { /* Allocate a new queue */ diff --git a/test/socket/socket1.c b/test/socket/socket1.c index f308aa6..1ad7a92 100644 --- a/test/socket/socket1.c +++ b/test/socket/socket1.c @@ -1,8 +1,7 @@ +#include #include #include -#include "../../socket/mysocket.h" - void test_socket1(void) { sock_platform_init(); struct addrinfo hints, *res, *p; diff --git a/test/stack/stack1.c b/test/stack/stack1.c index 7fb4630..17c6be4 100644 --- a/test/stack/stack1.c +++ b/test/stack/stack1.c @@ -1,8 +1,7 @@ #include +#include #include -#include "../../stack/mystack.h" - void test_stack1(void) { stack_s *stack = stack_new(32, sizeof(int)); int num = 10; diff --git a/test/string/str1.c b/test/string/str1.c index 4288d3c..4762f9a 100644 --- a/test/string/str1.c +++ b/test/string/str1.c @@ -1,10 +1,9 @@ #include +#include #include #include #include -#include "../../string/mystring.h" - void test_str1(void) { size_t length; size_t capacity; diff --git a/test/string/str2.c b/test/string/str2.c index 60a7907..bdca11e 100644 --- a/test/string/str2.c +++ b/test/string/str2.c @@ -1,8 +1,7 @@ #include +#include #include -#include "../../string/mystring.h" - void test_str2(void) { string_s *s1 = string_new("Hello, world!", 0); assert(s1 != NULL); diff --git a/test/string/str3.c b/test/string/str3.c index 4a23a79..c8af528 100644 --- a/test/string/str3.c +++ b/test/string/str3.c @@ -1,8 +1,7 @@ #include +#include #include -#include "../../string/mystring.h" - void test_str3(void) { /* Make a new string from format */ string_s *s = string_format("My name is %s (%d)", "John", 21); diff --git a/test/vector/vec1.c b/test/vector/vec1.c index 6c1acbb..26ff920 100644 --- a/test/vector/vec1.c +++ b/test/vector/vec1.c @@ -1,8 +1,7 @@ #include +#include #include -#include "../../vector/myvector.h" - typedef struct my_elem { char name[32]; int age;