From 317adfc8b743d275124497bdf1c72b97d055e938 Mon Sep 17 00:00:00 2001 From: Alexander Kornienko Date: Wed, 14 Nov 2012 20:26:19 +0000 Subject: [PATCH] Added %(line), %(line+), %(line-) substitutions to lit llvm-svn: 167971 --- llvm/docs/TestingGuide.html | 5 +++++ llvm/utils/lit/lit/TestRunner.py | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/llvm/docs/TestingGuide.html b/llvm/docs/TestingGuide.html index d90c8ad..1be7551 100644 --- a/llvm/docs/TestingGuide.html +++ b/llvm/docs/TestingGuide.html @@ -723,6 +723,11 @@ define two separate CHECK lines that match on the same line.
The full path to the test case's source. This is suitable for passing on the command line as the input to an llvm tool.
+
%(line), %(line+number), %(line-number)
+
The number of the line where this variable is used, with an optional + integer offset. This can be used in tests with multiple RUN: lines, which + reference test file's line numbers.
+
$srcdir
The source directory from where the "make check" was run.
diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py index 0c1911e..e339652 100644 --- a/llvm/utils/lit/lit/TestRunner.py +++ b/llvm/utils/lit/lit/TestRunner.py @@ -432,7 +432,9 @@ def parseIntegratedTestScript(test, normalize_slashes=False, script = [] xfails = [] requires = [] + line_number = 0 for ln in open(sourcepath): + line_number += 1 if 'RUN:' in ln: # Isolate the command to run. index = ln.index('RUN:') @@ -441,6 +443,15 @@ def parseIntegratedTestScript(test, normalize_slashes=False, # Trim trailing whitespace. ln = ln.rstrip() + # Substitute line number expressions + ln = re.sub('%\(line\)', str(line_number), ln) + def replace_line_number(match): + if match.group(1) == '+': + return str(line_number + int(match.group(2))) + if match.group(1) == '-': + return str(line_number - int(match.group(2))) + ln = re.sub('%\(line *([\+-]) *(\d+)\)', replace_line_number, ln) + # Collapse lines with trailing '\\'. if script and script[-1][-1] == '\\': script[-1] = script[-1][:-1] + ln -- 2.7.4