[lit] Factor ShTest format script command parsing from other processing.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188357 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Daniel Dunbar 2013-08-14 05:07:04 +00:00
parent 493e8d4bf5
commit 5403214852

View File

@ -309,6 +309,25 @@ def isExpectedFail(test, xfails):
return False return False
def parseIntegratedTestScriptCommands(sourcepath):
"""
parseIntegratedTestScriptCommands(source_path) -> commands
Parse the commands in an integrated test script file into a list of
(line_number, command_type, line).
"""
line_number = 0
for ln in open(sourcepath):
line_number += 1
if 'RUN:' in ln:
yield (line_number, 'RUN', ln[ln.index('RUN:')+4:])
elif 'XFAIL:' in ln:
yield (line_number, 'XFAIL', ln[ln.index('XFAIL:') + 6:])
elif 'REQUIRES:' in ln:
yield (line_number, 'REQUIRES', ln[ln.index('REQUIRES:') + 9:])
elif 'END.' in ln:
yield (line_number, 'END', ln[ln.index('END.') + 4:])
def parseIntegratedTestScript(test, normalize_slashes=False, def parseIntegratedTestScript(test, normalize_slashes=False,
extra_substitutions=[]): extra_substitutions=[]):
"""parseIntegratedTestScript - Scan an LLVM/Clang style integrated test """parseIntegratedTestScript - Scan an LLVM/Clang style integrated test
@ -359,14 +378,9 @@ def parseIntegratedTestScript(test, normalize_slashes=False,
script = [] script = []
xfails = [] xfails = []
requires = [] requires = []
line_number = 0 for line_number, command_type, ln in \
for ln in open(sourcepath): parseIntegratedTestScriptCommands(sourcepath):
line_number += 1 if command_type == 'RUN':
if 'RUN:' in ln:
# Isolate the command to run.
index = ln.index('RUN:')
ln = ln[index+4:]
# Trim trailing whitespace. # Trim trailing whitespace.
ln = ln.rstrip() ln = ln.rstrip()
@ -384,16 +398,17 @@ def parseIntegratedTestScript(test, normalize_slashes=False,
script[-1] = script[-1][:-1] + ln script[-1] = script[-1][:-1] + ln
else: else:
script.append(ln) script.append(ln)
elif 'XFAIL:' in ln: elif command_type == 'XFAIL':
items = ln[ln.index('XFAIL:') + 6:].split(',') xfails.extend([s.strip() for s in ln.split(',')])
xfails.extend([s.strip() for s in items]) elif command_type == 'REQUIRES':
elif 'REQUIRES:' in ln: requires.extend([s.strip() for s in ln.split(',')])
items = ln[ln.index('REQUIRES:') + 9:].split(',') elif command_type == 'END':
requires.extend([s.strip() for s in items]) # END commands are only honored if the rest of the line is empty.
elif 'END.' in ln: if not ln.strip():
# Check for END. lines.
if ln[ln.index('END.'):].strip() == 'END.':
break break
else:
raise ValueError("unknown script command type: %r" % (
command_type,))
# Apply substitutions to the script. Allow full regular # Apply substitutions to the script. Allow full regular
# expression syntax. Replace each matching occurrence of regular # expression syntax. Replace each matching occurrence of regular