tests/run-tests.py
branchstable
changeset 1001 21b3c555b6f4
parent 1000 cc9cdab213e1
child 1002 9a8202faebb3
equal deleted inserted replaced
1000:cc9cdab213e1 1001:21b3c555b6f4
   519 def escapef(m):
   519 def escapef(m):
   520     return escapemap[m.group(0)]
   520     return escapemap[m.group(0)]
   521 def stringescape(s):
   521 def stringescape(s):
   522     return escapesub(escapef, s)
   522     return escapesub(escapef, s)
   523 
   523 
       
   524 def rematch(el, l):
       
   525     try:
       
   526         # ensure that the regex matches to the end of the string
       
   527         return re.match(el + r'\Z', l)
       
   528     except re.error:
       
   529         # el is an invalid regex
       
   530         return False
       
   531 
       
   532 def globmatch(el, l):
       
   533     # The only supported special characters are * and ?. Escaping is
       
   534     # supported.
       
   535     i, n = 0, len(el)
       
   536     res = ''
       
   537     while i < n:
       
   538         c = el[i]
       
   539         i += 1
       
   540         if c == '\\' and el[i] in '*?\\':
       
   541             res += el[i - 1:i + 1]
       
   542             i += 1
       
   543         elif c == '*':
       
   544             res += '.*'
       
   545         elif c == '?':
       
   546             res += '.'
       
   547         else:
       
   548             res += re.escape(c)
       
   549     return rematch(res, l)
       
   550 
   524 def tsttest(test, wd, options, replacements):
   551 def tsttest(test, wd, options, replacements):
   525     t = open(test)
   552     t = open(test)
   526     out = []
   553     out = []
   527     script = []
   554     script = []
   528 
   555 
   605         # similarly, with --debug, output is None
   632         # similarly, with --debug, output is None
   606         if exitcode == SKIPPED_STATUS or output is None:
   633         if exitcode == SKIPPED_STATUS or output is None:
   607             return exitcode, output
   634             return exitcode, output
   608     finally:
   635     finally:
   609         os.remove(name)
   636         os.remove(name)
   610 
       
   611     def rematch(el, l):
       
   612         try:
       
   613             # ensure that the regex matches to the end of the string
       
   614             return re.match(el + r'\Z', l)
       
   615         except re.error:
       
   616             # el is an invalid regex
       
   617             return False
       
   618 
       
   619     def globmatch(el, l):
       
   620         # The only supported special characters are * and ?. Escaping is
       
   621         # supported.
       
   622         i, n = 0, len(el)
       
   623         res = ''
       
   624         while i < n:
       
   625             c = el[i]
       
   626             i += 1
       
   627             if c == '\\' and el[i] in '*?\\':
       
   628                 res += el[i - 1:i + 1]
       
   629                 i += 1
       
   630             elif c == '*':
       
   631                 res += '.*'
       
   632             elif c == '?':
       
   633                 res += '.'
       
   634             else:
       
   635                 res += re.escape(c)
       
   636         return rematch(res, l)
       
   637 
   637 
   638     # Merge the script output back into a unified test
   638     # Merge the script output back into a unified test
   639 
   639 
   640     pos = -1
   640     pos = -1
   641     postout = []
   641     postout = []