From 396ac31945c4e44215249839a61515f77a6eb031 Mon Sep 17 00:00:00 2001 From: MMirbach Date: Wed, 24 Feb 2021 21:08:34 +0200 Subject: [PATCH 1/3] added config set up for cpp tests --- unit-tests/run-unit-tests.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/unit-tests/run-unit-tests.py b/unit-tests/run-unit-tests.py index 7eacbf079b..5889518965 100644 --- a/unit-tests/run-unit-tests.py +++ b/unit-tests/run-unit-tests.py @@ -371,9 +371,33 @@ def __init__( self, testname, exe ): :param testname: name of the test :param exe: full path to executable """ + global current_dir Test.__init__(self, testname) self.exe = exe + # Finding the c/cpp file of the test to get the configuration + split_testname = testname.split( '-' ) + cpp_path = current_dir + found_test_dir = False + + while not found_test_dir: + found_test_dir = True + for i in range(2, len(split_testname) ): + tmp_path = cpp_path + os.sep + '-'.join(split_testname[1:i]) + if os.path.isdir(tmp_path): + cpp_path = tmp_path + del split_testname[1:i] + found_test_dir = False + break + + cpp_path += os.sep + '-'.join( split_testname ) + if os.path.isfile( cpp_path + ".cpp" ): + cpp_path += ".cpp" + else: + cpp_path += ".c" + + self._config = TestConfigFromText( cpp_path, r'//\s*#\s*test:' ) + @property def command(self): return [self.exe] From dc7beb03b1a091c41c127c12ad95878c5e2b902a Mon Sep 17 00:00:00 2001 From: MMirbach Date: Thu, 25 Feb 2021 08:40:58 +0200 Subject: [PATCH 2/3] added comments --- unit-tests/run-unit-tests.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/unit-tests/run-unit-tests.py b/unit-tests/run-unit-tests.py index 5889518965..a66b3d1ccd 100644 --- a/unit-tests/run-unit-tests.py +++ b/unit-tests/run-unit-tests.py @@ -382,9 +382,9 @@ def __init__( self, testname, exe ): while not found_test_dir: found_test_dir = True - for i in range(2, len(split_testname) ): - tmp_path = cpp_path + os.sep + '-'.join(split_testname[1:i]) - if os.path.isdir(tmp_path): + for i in range(2, len(split_testname) ): # Checking if the next part of the test name is a sub-directory + tmp_path = cpp_path + os.sep + '-'.join(split_testname[1:i]) # The next sub-directory could have several words + if os.path.isdir(tmp_path): cpp_path = tmp_path del split_testname[1:i] found_test_dir = False From 387f664dbba6f269440bd0ac0a8f428dfe50e6c1 Mon Sep 17 00:00:00 2001 From: MMirbach Date: Thu, 25 Feb 2021 09:37:43 +0200 Subject: [PATCH 3/3] CR fixes --- unit-tests/run-unit-tests.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/unit-tests/run-unit-tests.py b/unit-tests/run-unit-tests.py index a66b3d1ccd..43f9bbb8be 100644 --- a/unit-tests/run-unit-tests.py +++ b/unit-tests/run-unit-tests.py @@ -376,11 +376,19 @@ def __init__( self, testname, exe ): self.exe = exe # Finding the c/cpp file of the test to get the configuration + # TODO: this is limited to a structure in which .cpp files and directories do not share names + # For example: + # unit-tests/ + # func/ + # ... + # test-func.cpp + # test-func.cpp will not be found! split_testname = testname.split( '-' ) cpp_path = current_dir found_test_dir = False while not found_test_dir: + # index 0 should be 'test' as tests always start with it found_test_dir = True for i in range(2, len(split_testname) ): # Checking if the next part of the test name is a sub-directory tmp_path = cpp_path + os.sep + '-'.join(split_testname[1:i]) # The next sub-directory could have several words @@ -393,10 +401,9 @@ def __init__( self, testname, exe ): cpp_path += os.sep + '-'.join( split_testname ) if os.path.isfile( cpp_path + ".cpp" ): cpp_path += ".cpp" + self._config = TestConfigFromText(cpp_path, r'//#\s*test:') else: - cpp_path += ".c" - - self._config = TestConfigFromText( cpp_path, r'//\s*#\s*test:' ) + log.w( log.red + testname + log.reset + ':', 'No matching .cpp file was found; no configuration will be used!' ) @property def command(self):