[PATCH] D30380: Teach lit to expand glob expressions

Zachary Turner via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Feb 25 14:08:16 PST 2017


zturner updated this revision to Diff 89801.

https://reviews.llvm.org/D30380

Files:
  llvm/docs/CommandGuide/lit.rst
  llvm/test/Other/Inputs/glob-input
  llvm/test/Other/lit-globbing.ll
  llvm/utils/lit/lit/TestRunner.py


Index: llvm/utils/lit/lit/TestRunner.py
===================================================================
--- llvm/utils/lit/lit/TestRunner.py
+++ llvm/utils/lit/lit/TestRunner.py
@@ -1,4 +1,5 @@
 from __future__ import absolute_import
+import glob
 import os, signal, subprocess, sys
 import re
 import platform
@@ -734,6 +735,14 @@
                 b = b.replace("\\","\\\\")
             ln = re.sub(a, b, ln)
 
+        while True:
+            # First expand any glob expressions.
+            m = re.search(r"%\[\[(.*?)]]", ln)
+            if m is None:
+                break
+            result = [os.path.normpath(x) for x in glob.glob(m.groups()[0])]
+            ln = ln.replace(m.group(), " ".join(result))
+
         # Strip the trailing newline and any extra whitespace.
         return ln.strip()
     # Note Python 3 map() gives an iterator rather than a list so explicitly
Index: llvm/test/Other/lit-globbing.ll
===================================================================
--- /dev/null
+++ llvm/test/Other/lit-globbing.ll
@@ -0,0 +1,16 @@
+RUN: echo No%[[Foo*]]Match | FileCheck -check-prefix=NOMATCH %s
+RUN: echo Test1 > %T/Test1.txt
+RUN: echo Test2 > %T/Test2.txt
+RUN: echo Test12 > %T/Test12.txt
+RUN: echo Left%[[%T/Test?.txt]]Right | FileCheck -check-prefix=MATCH %s
+RUN: echo Left%[[%S/Inputs/glob-input]]Right | FileCheck -check-prefix=MATCH2 %s
+RUN: echo Left%[[%T/Test1.*]]%[[%T/Test2.*]]%[[%T/Test1.*]]Right | FileCheck -check-prefix=MATCH3 %s
+
+NOMATCH: NoMatch
+
+MATCH-NOT: Test12.txt
+MATCH: Left{{.*}}Test1.txt{{.*}}Test2.txtRight
+
+MATCH2: Left{{.*}}glob-inputRight
+
+MATCH3: Left{{.*}}Test1.txt{{.*}}Test2.txt{{.*}}Test1.txtRight
\ No newline at end of file
Index: llvm/docs/CommandGuide/lit.rst
===================================================================
--- llvm/docs/CommandGuide/lit.rst
+++ llvm/docs/CommandGuide/lit.rst
@@ -388,6 +388,7 @@
  %S         source dir (directory of the file currently being run)
  %p         same as %S
  %{pathsep} path separator
+ %[[glob]]  A list of all files matching the glob expression, separated by spaces.
  %t         temporary file name unique to the test
  %T         temporary directory unique to the test
  %%         %


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30380.89801.patch
Type: text/x-patch
Size: 2245 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170225/2f1ce21f/attachment.bin>


More information about the llvm-commits mailing list