Skip to content

Commit 1683482

Browse files
committed
test: add option for multiple tests
1 parent 2944e9d commit 1683482

File tree

25 files changed

+737
-338
lines changed

25 files changed

+737
-338
lines changed

.github/workflows/build-and-test.yml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
push:
55
branches:
66
- develop
7+
- test
78
pull_request:
89
branches:
910
- develop
@@ -22,14 +23,7 @@ jobs:
2223
echo "C:\ProgramData\chocolatey\lib\mingw\tools\install\mingw64\bin" >> $GITHUB_PATH
2324
gcc --version
2425
25-
- name: Build for 32-bit
26-
run: |
27-
mkdir __build__
28-
cd __build__
29-
cmake -S.. -T host=x86 -A Win32
30-
cmake --build .
31-
3226
- name: Run Tests
33-
working-directory: __build__
27+
working-directory: tests
3428
run: |
35-
ctest . --output-on-failure -C Debug
29+
python test.py --github

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ bld/
8181
[Ll]og/
8282
_build/
8383
build/
84+
__build__/
8485

8586
# Visual Studio 2015/2017 cache/options directory
8687
.vs/

CMakeLists.txt

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,6 @@ project(LwLibPROJECT)
66
if(NOT PROJECT_IS_TOP_LEVEL)
77
add_subdirectory(lwmem)
88
else()
9-
# Set default compile flags for GCC
10-
if(CMAKE_COMPILER_IS_GNUCXX)
11-
message(STATUS "GCC detected, adding compile flags")
12-
set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra")
13-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra")
14-
endif(CMAKE_COMPILER_IS_GNUCXX)
15-
16-
enable_testing()
17-
add_executable(${PROJECT_NAME})
18-
target_sources(${PROJECT_NAME} PUBLIC
19-
${CMAKE_CURRENT_LIST_DIR}/dev/main.cpp
20-
${CMAKE_CURRENT_LIST_DIR}/tests/lwmem_test.c
21-
${CMAKE_CURRENT_LIST_DIR}/tests/lwmem_test_simple.c
22-
${CMAKE_CURRENT_LIST_DIR}/tests/lwmem_test_region.c
23-
${CMAKE_CURRENT_LIST_DIR}/tests/lwmem_test_available_mem.c
24-
25-
# win32 port
26-
${CMAKE_CURRENT_LIST_DIR}/lwmem/src/system/lwmem_sys_win32.c
27-
)
28-
target_include_directories(${PROJECT_NAME} PUBLIC
29-
${CMAKE_CURRENT_LIST_DIR}
30-
${CMAKE_CURRENT_LIST_DIR}/dev
31-
${CMAKE_CURRENT_LIST_DIR}/tests
32-
)
33-
34-
# Add subdir with lwmem and link to the project
35-
set(LWMEM_OPTS_FILE ${CMAKE_CURRENT_LIST_DIR}/dev/lwmem_opts.h)
36-
add_subdirectory(lwmem)
37-
target_link_libraries(${PROJECT_NAME} PUBLIC lwmem_cpp)
38-
39-
# Add compile options to the library, which will propagate options to executable through public link
40-
target_compile_definitions(lwmem PUBLIC WIN32 _DEBUG CONSOLE LWMEM_DEV)
41-
42-
# Add test
43-
add_test(NAME Test COMMAND $<TARGET_FILE:${CMAKE_PROJECT_NAME}>)
9+
set(TEST_CMAKE_FILE_NAME "test_memory_structure/cmake.cmake")
10+
add_subdirectory(tests)
4411
endif()

docs/examples_src/example_realloc_enlarge_full.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#define ASSERT(x) \
1+
#define TEST_ASSERT(x) \
22
do { \
33
if (!(x)) { \
44
printf("Assert failed with condition (" #x ")\r\n"); \
@@ -46,31 +46,31 @@ main(void) {
4646
printf("State 3a\r\n");
4747
rptr1 = lwmem_realloc(ptr2, 8);
4848
lwmem_debug_print(1, 1);
49-
ASSERT(rptr1 == ptr2);
49+
TEST_ASSERT(rptr1 == ptr2);
5050

5151
/* Create 3b case */
5252
printf("\r\n------------------------------------------------------------------------\r\n");
5353
lwmem_debug_restore_to_saved();
5454
printf("State 3b\r\n");
5555
rptr2 = lwmem_realloc(ptr2, 20);
5656
lwmem_debug_print(1, 1);
57-
ASSERT(rptr2 == ptr1);
57+
TEST_ASSERT(rptr2 == ptr1);
5858

5959
/* Create 3c case */
6060
printf("\r\n------------------------------------------------------------------------\r\n");
6161
lwmem_debug_restore_to_saved();
6262
printf("State 3c\r\n");
6363
rptr3 = lwmem_realloc(ptr2, 24);
6464
lwmem_debug_print(1, 1);
65-
ASSERT(rptr3 == ptr1);
65+
TEST_ASSERT(rptr3 == ptr1);
6666

6767
/* Create 3d case */
6868
printf("\r\n------------------------------------------------------------------------\r\n");
6969
lwmem_debug_restore_to_saved();
7070
printf("State 3d\r\n");
7171
rptr4 = lwmem_realloc(ptr2, 36);
7272
lwmem_debug_print(1, 1);
73-
ASSERT(rptr4 != ptr1 && rptr4 != ptr2 && rptr4 != ptr3 && rptr4 != ptr4);
73+
TEST_ASSERT(rptr4 != ptr1 && rptr4 != ptr2 && rptr4 != ptr3 && rptr4 != ptr4);
7474

7575
return 0;
7676
}

tests/CMakeLists.txt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
cmake_minimum_required(VERSION 3.22)
2+
3+
# Setup project
4+
project(LwLibPROJECT)
5+
6+
# Set default compile flags for GCC
7+
if(CMAKE_COMPILER_IS_GNUCXX)
8+
message(STATUS "GCC detected, adding compile flags")
9+
set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra")
10+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra")
11+
endif(CMAKE_COMPILER_IS_GNUCXX)
12+
13+
enable_testing()
14+
add_executable(${CMAKE_PROJECT_NAME})
15+
target_sources(${CMAKE_PROJECT_NAME} PRIVATE
16+
${CMAKE_CURRENT_LIST_DIR}/test_file.cpp
17+
)
18+
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE
19+
${CMAKE_CURRENT_LIST_DIR}/
20+
)
21+
22+
# Include file that can add more sources and prepare lib parameters
23+
include(${TEST_CMAKE_FILE_NAME})
24+
25+
# Add subdir with lwmem and link to project
26+
set(LWMEM_SYS_PORT "win32")
27+
add_subdirectory("../lwmem" lwmem)
28+
target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC lwmem_cpp)
29+
target_compile_definitions(lwmem_cpp PUBLIC LWMEM_DEV)
30+
31+
# Add test
32+
add_test(NAME Test COMMAND $<TARGET_FILE:${CMAKE_PROJECT_NAME}>)

tests/lwmem_test.c

Lines changed: 0 additions & 226 deletions
This file was deleted.

0 commit comments

Comments
 (0)