tests/run-tests.py
branchstable
changeset 801 413c6fe6d1e3
parent 800 c4211177a2fc
child 802 630d72ae4f76
equal deleted inserted replaced
800:c4211177a2fc 801:413c6fe6d1e3
   507             return re.match(el + r'\Z', l)
   507             return re.match(el + r'\Z', l)
   508         except re.error:
   508         except re.error:
   509             # el is an invalid regex
   509             # el is an invalid regex
   510             return False
   510             return False
   511 
   511 
       
   512     def globmatch(el, l):
       
   513         # The only supported special characters are * and ?. Escaping is
       
   514         # supported.
       
   515         i, n = 0, len(el)
       
   516         res = ''
       
   517         while i < n:
       
   518             c = el[i]
       
   519             i += 1
       
   520             if c == '\\' and el[i] in '*?\\':
       
   521                 res += el[i-1:i+1]
       
   522                 i += 1
       
   523             elif c == '*':
       
   524                 res += '.*'
       
   525             elif c == '?':
       
   526                 res += '.'
       
   527             else:
       
   528                 res += re.escape(c)
       
   529         return rematch(res, l)
       
   530 
   512     pos = -1
   531     pos = -1
   513     postout = []
   532     postout = []
   514     ret = 0
   533     ret = 0
   515     for n, l in enumerate(output):
   534     for n, l in enumerate(output):
   516         if l.startswith(salt):
   535         if l.startswith(salt):
   526             if pos in expected and expected[pos]:
   545             if pos in expected and expected[pos]:
   527                 el = expected[pos].pop(0)
   546                 el = expected[pos].pop(0)
   528 
   547 
   529             if el == l: # perfect match (fast)
   548             if el == l: # perfect match (fast)
   530                 postout.append("  " + l)
   549                 postout.append("  " + l)
   531             elif el and el.endswith(" (re)\n") and rematch(el[:-6] + '\n', l):
   550             elif (el and
   532                 postout.append("  " + el) # fallback regex match
   551                   (el.endswith(" (re)\n") and rematch(el[:-6] + '\n', l) or
       
   552                    el.endswith(" (glob)\n") and globmatch(el[:-8] + '\n', l))):
       
   553                 postout.append("  " + el) # fallback regex/glob match
   533             else:
   554             else:
   534                 postout.append("  " + l) # let diff deal with it
   555                 postout.append("  " + l) # let diff deal with it
   535 
   556 
   536     if pos in after:
   557     if pos in after:
   537         postout += after.pop(pos)
   558         postout += after.pop(pos)