Detect test framework during test import
A framework the test can be written in can be 'shell' or
'beakerlib'. When beaker is used, it is possible to detect it in
test (.sh) file, so I'm searching for it with the regex and saving
in data dict.
Resolves
@@ -170,7 +170,7 @@ def read(path, makefile, nitrate, purpose, disabled, types):
data for individual testcases (if multiple nitrate testcases found).
"""
- data = dict(framework='beakerlib')
+ data = dict()
echo("Checking the '{0}' directory.".format(path))
# Make sure there is a metadata tree initialized
@@ -212,6 +212,24 @@ def read(path, makefile, nitrate, purpose, disabled, types):
makefile, flags=re.MULTILINE)
makefile = re.sub('.*rhts-lint.*', '', makefile)
+ # Detect framework
+ try:
+ test_script = \
+ re.search(r'^run:.*\n\t\.\/(.*)$', makefile, re.M).group(1)
+ test_path = os.path.join(path, test_script)
+ except AttributeError:
+ raise ConvertError("Unable to parse '.sh' file from a makefile.")
+ try:
+ with open(test_path, encoding='utf-8') as test_file:
+ test = test_file.read()
+ if re.search('beakerlib', test, re.M).group() == 'beakerlib':
+ data['framework'] = 'beakerlib'
+ else:
+ data['framework'] = 'shell'
+ echo(style('framework: ', fg='green') + data['framework'])
+ except IOError:
+ raise ConvertError("Unable to open '{0}'.".format(test_path))
+
# Create testinfo.desc file with resolved variables
try:
process = subprocess.run(
