Skip to content

Commit 6c34802

Browse files
authored
Merge pull request #8153 from lorjala/unittests-autoname
Unit tests: automatic unit test suite naming
2 parents 843b15b + 8f340b1 commit 6c34802

File tree

19 files changed

+13
-61
lines changed

19 files changed

+13
-61
lines changed

UNITTESTS/CMakeLists.txt

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,17 @@ foreach(testfile ${unittest-file-list})
147147
# Get source files
148148
include("${testfile}")
149149

150-
if(TEST_SUITE_NAME)
151-
set(TEST_SUITES ${TEST_SUITES} ${TEST_SUITE_NAME})
152-
else()
153-
message(FATAL_ERROR "No TEST_SUITE_NAME found in test file. Add it to ${testfile}.")
154-
endif()
150+
get_filename_component(TEST_SUITE_DIR ${testfile} DIRECTORY)
151+
152+
file(RELATIVE_PATH
153+
TEST_SUITE_NAME # output
154+
${PROJECT_SOURCE_DIR} # root
155+
${TEST_SUITE_DIR} #abs dirpath
156+
)
157+
158+
string(REGEX REPLACE "/|\\\\" "-" TEST_SUITE_NAME ${TEST_SUITE_NAME})
159+
160+
set(TEST_SUITES ${TEST_SUITES} ${TEST_SUITE_NAME})
155161

156162
set(LIBS_TO_BE_LINKED gmock_main)
157163

@@ -178,7 +184,7 @@ foreach(testfile ${unittest-file-list})
178184
# Link the executable with the libraries.
179185
target_link_libraries(${TEST_SUITE_NAME} ${LIBS_TO_BE_LINKED})
180186

181-
add_test(NAME "${TEST_SUITE_NAME}UnitTests" COMMAND ${TEST_SUITE_NAME})
187+
add_test(NAME "${TEST_SUITE_NAME}" COMMAND ${TEST_SUITE_NAME})
182188

183189
# Append test build directory to list
184190
list(APPEND BUILD_DIRECTORIES "./CMakeFiles/${TEST_SUITE_NAME}.dir")

UNITTESTS/README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ Each class to be tested requires two files for unit testing:
203203

204204
A unit test definition file `unittest.cmake` requires variables to be set for a test to be configured. File source paths in `unittest.cmake` files need to be relative to the unit test folder and `CMakeLists.txt`.
205205

206-
* **TEST_SUITE_NAME** - Identifier for the test suite. Use naming convention *PATH_TO_THE_TESTABLE_FILE* e.g. *features-netsocket-InternetSocket*
207206
* **unittest-includes** - Include paths for headers needed to build the tests in addition to the base include paths listed in [CMakeLists.txt](CMakeLists.txt). Optional.
208207
* **unittest-sources** - Mbed OS source files and stubs included for the build.
209208
* **unittest-test-sources** - Unit test source files.
@@ -225,8 +224,6 @@ For example to create a unit test for `rtos/Semaphore.cpp`:
225224
1. Create a directory for unit test files in `UNITTESTS/rtos/Semaphore`.
226225
2. Create a test definition file `UNITTESTS/rtos/Semaphore/unittest.cmake` with the following content:
227226
```
228-
set(TEST_SUITE_NAME "rtos-Semaphore")
229-
230227
set(unittest-sources
231228
stubs/mbed_assert.c
232229
../rtos/Semaphore.cpp

UNITTESTS/features/cellular/framework/AT/at_cellularbase/unittest.cmake

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
# UNIT TESTS
44
####################
55

6-
# Unit test suite name
7-
set(TEST_SUITE_NAME "cellular-framework-AT-AT_CellularBase")
8-
96
# Add test specific include paths
107
set(unittest-includes ${unittest-includes}
118
features/cellular/framework/AT/AT_CellularBase

UNITTESTS/features/cellular/framework/AT/at_cellulardevice/unittest.cmake

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
# UNIT TESTS
44
####################
55

6-
# Unit test suite name
7-
set(TEST_SUITE_NAME "at_cellular_device_unit")
8-
96
# Add test specific include paths
107
set(unittest-includes ${unittest-includes}
118
features/cellular/framework/common/util

UNITTESTS/features/cellular/framework/AT/at_cellularinformation/unittest.cmake

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
# UNIT TESTS
44
####################
55

6-
# Unit test suite name
7-
set(TEST_SUITE_NAME "at_cellular_information_unit")
8-
96
# Add test specific include paths
107
set(unittest-includes ${unittest-includes}
118
features/cellular/framework/common/util

UNITTESTS/features/cellular/framework/AT/at_cellularnetwork/unittest.cmake

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
# UNIT TESTS
44
####################
55

6-
# Unit test suite name
7-
set(TEST_SUITE_NAME "at_cellular_network_unit")
8-
96
# Add test specific include paths
107
set(unittest-includes ${unittest-includes}
118
features/cellular/framework/common/util

UNITTESTS/features/cellular/framework/AT/at_cellularpower/unittest.cmake

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
# UNIT TESTS
44
####################
55

6-
# Unit test suite name
7-
set(TEST_SUITE_NAME "at_cellular_power_unit")
8-
96
# Add test specific include paths
107
set(unittest-includes ${unittest-includes}
118
features/cellular/framework/common/util

UNITTESTS/features/cellular/framework/AT/at_cellularsim/unittest.cmake

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
# UNIT TESTS
44
####################
55

6-
# Unit test suite name
7-
set(TEST_SUITE_NAME "at_cellular_sim_unit")
8-
96
# Add test specific include paths
107
set(unittest-includes ${unittest-includes}
118
features/cellular/framework/common/util

UNITTESTS/features/cellular/framework/AT/at_cellularsms/unittest.cmake

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
# UNIT TESTS
44
####################
55

6-
# Unit test suite name
7-
set(TEST_SUITE_NAME "at_cellular_sms_unit")
8-
96
# Add test specific include paths
107
set(unittest-includes ${unittest-includes}
118
features/cellular/framework/common/util

UNITTESTS/features/cellular/framework/AT/at_cellularstack/unittest.cmake

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
# UNIT TESTS
44
####################
55

6-
# Unit test suite name
7-
set(TEST_SUITE_NAME "at_cellular_stack_unit")
8-
96
# Add test specific include paths
107
set(unittest-includes ${unittest-includes}
118
features/cellular/framework/common/util

0 commit comments

Comments
 (0)