Skip to content

Commit 980f2ae

Browse files
committed
add auto test workflow
1 parent 704f996 commit 980f2ae

File tree

4 files changed

+53
-10
lines changed

4 files changed

+53
-10
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Windows CMake Build & Test
2+
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
pull_request:
8+
branches:
9+
- develop
10+
11+
jobs:
12+
build:
13+
runs-on: windows-latest
14+
15+
steps:
16+
- name: Checkout Repository
17+
uses: actions/checkout@v4
18+
19+
- name: Install MinGW
20+
run: |
21+
choco install mingw --version=12.2.0 -y
22+
echo "C:\ProgramData\chocolatey\lib\mingw\tools\install\mingw64\bin" >> $GITHUB_PATH
23+
gcc --version
24+
25+
- name: Build
26+
run: |
27+
mkdir __build__
28+
cd __build__
29+
cmake -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=gcc -S.. -G Ninja
30+
cmake --build .
31+
32+
- name: Run Tests
33+
working-directory: __build__
34+
run: |
35+
ctest . --output-on-failure

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ project(LwLibPROJECT)
66
if(NOT PROJECT_IS_TOP_LEVEL)
77
add_subdirectory(lwshell)
88
else()
9+
enable_testing()
910
add_executable(${PROJECT_NAME})
1011
target_sources(${PROJECT_NAME} PRIVATE
1112
${CMAKE_CURRENT_LIST_DIR}/dev/main.c
@@ -23,4 +24,7 @@ else()
2324
# Add compile options to the library, which will propagate options to executable through public link
2425
target_compile_definitions(lwshell PUBLIC WIN32 _DEBUG CONSOLE LWSHELL_DEV)
2526
target_compile_options(lwshell PUBLIC -Wall -Wextra -Wpedantic)
27+
28+
# Add test
29+
add_test(NAME Test COMMAND $<TARGET_FILE:${CMAKE_PROJECT_NAME}>)
2630
endif()

dev/main.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#endif
1919

2020
void example_minimal(void);
21-
extern void run_test(void);
21+
extern int run_test(void);
2222

2323
#if LWSHELL_CFG_USE_OUTPUT
2424

@@ -28,7 +28,7 @@ extern void run_test(void);
2828
* \param[in] lw: LwSHELL instance
2929
*/
3030
static void
31-
shell_output(const char* str, lwshell_t* lw) {
31+
prv_shell_output(const char* str, lwshell_t* lw) {
3232
(void)lw;
3333
printf("%s", str);
3434
if (*str == '\r') {
@@ -133,17 +133,14 @@ static const lwshell_cmd_t static_cmds[] = {
133133
/* Program entry point */
134134
int
135135
main(void) {
136-
/* Init library */
137-
lwshell_init();
136+
return run_test();
138137

138+
#if 0
139139
#if LWSHELL_CFG_USE_OUTPUT
140140
/* Add optional output function for the purpose of the feedback */
141-
lwshell_set_output_fn(shell_output);
141+
lwshell_set_output_fn(prv_shell_output);
142142
#endif /* LWSHELL_CFG_USE_OUTPUT */
143143

144-
/* Run the test */
145-
run_test();
146-
147144
#if LWSHELL_CFG_USE_DYNAMIC_COMMANDS
148145
/* Define shell commands */
149146
lwshell_register_cmd("addint", addint_cmd, "Adds 2 integer numbers and prints them");
@@ -173,4 +170,5 @@ main(void) {
173170
lwshell_input(str, strlen(str));
174171
}
175172
return 0;
173+
#endif
176174
}

tests/test.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ static const test_str_t commands[] = {
4848
},
4949
};
5050
static uint32_t current_cmd_index;
51+
static int failed = 0;
5152

5253
/**
5354
* \brief Test command function
@@ -66,6 +67,7 @@ prv_test_cmd(int32_t argc, char** argv) {
6667
if (cmd_args_count != argc) {
6768
printf("Test failed: Expected argument count (%02u) does not match actual argument count (%02u)\r\n",
6869
(unsigned)cmd_args_count, (unsigned)argc);
70+
failed = 1;
6971
return -1;
7072
}
7173

@@ -75,6 +77,7 @@ prv_test_cmd(int32_t argc, char** argv) {
7577
if (strcmp(cmd->args_list[idx], argv[idx]) != 0) {
7678
printf("Test failed: Argument index %02u, value \"%s\" does not match actual argument value \"%s\"\r\n",
7779
(unsigned)idx, cmd->args_list[idx], argv[idx]);
80+
failed = 1;
7881
return -1;
7982
}
8083
}
@@ -86,15 +89,18 @@ prv_test_cmd(int32_t argc, char** argv) {
8689
* \brief Global test run function
8790
*
8891
*/
89-
void
92+
int
9093
run_test(void) {
91-
lwshell_register_cmd("test", prv_test_cmd, "Test command function\r\n");
94+
failed = 0;
9295

9396
printf("Running test...\r\n");
97+
lwshell_init();
98+
lwshell_register_cmd("test", prv_test_cmd, "Test command function\r\n");
9499

95100
/* Run all commands */
96101
for (current_cmd_index = 0; current_cmd_index < LWSHELL_ARRAYSIZE(commands); ++current_cmd_index) {
97102
lwshell_input(commands[current_cmd_index].command, strlen(commands[current_cmd_index].command));
98103
}
99104
printf("Tests completed...\r\n");
105+
return failed ? -1 : 0;
100106
}

0 commit comments

Comments
 (0)