Skip to content

Commit

Permalink
PR #8440 from Matan: run-unit-tests.py config for C++ tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maloel committed Feb 25, 2021
2 parents 343ee60 + 387f664 commit 86c4ae8
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions unit-tests/run-unit-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,40 @@ 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
# 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
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"
self._config = TestConfigFromText(cpp_path, r'//#\s*test:')
else:
log.w( log.red + testname + log.reset + ':', 'No matching .cpp file was found; no configuration will be used!' )

@property
def command(self):
return [self.exe]
Expand Down

0 comments on commit 86c4ae8

Please sign in to comment.