tests/run-tests.py
changeset 21316 ab9bf8a5e573
parent 21315 56610da39b48
child 21317 58a599784a0c
equal deleted inserted replaced
21315:56610da39b48 21316:ab9bf8a5e573
   693 def escapef(m):
   693 def escapef(m):
   694     return escapemap[m.group(0)]
   694     return escapemap[m.group(0)]
   695 def stringescape(s):
   695 def stringescape(s):
   696     return escapesub(escapef, s)
   696     return escapesub(escapef, s)
   697 
   697 
   698 def rematch(el, l):
       
   699     try:
       
   700         # use \Z to ensure that the regex matches to the end of the string
       
   701         if os.name == 'nt':
       
   702             return re.match(el + r'\r?\n\Z', l)
       
   703         return re.match(el + r'\n\Z', l)
       
   704     except re.error:
       
   705         # el is an invalid regex
       
   706         return False
       
   707 
       
   708 def globmatch(el, l):
   698 def globmatch(el, l):
   709     # The only supported special characters are * and ? plus / which also
   699     # The only supported special characters are * and ? plus / which also
   710     # matches \ on windows. Escaping of these characters is supported.
   700     # matches \ on windows. Escaping of these characters is supported.
   711     if el + '\n' == l:
   701     if el + '\n' == l:
   712         if os.altsep:
   702         if os.altsep:
   727             res += '.'
   717             res += '.'
   728         elif c == '/' and os.altsep:
   718         elif c == '/' and os.altsep:
   729             res += '[/\\\\]'
   719             res += '[/\\\\]'
   730         else:
   720         else:
   731             res += re.escape(c)
   721             res += re.escape(c)
   732     return rematch(res, l)
   722     return TTest.rematch(res, l)
   733 
   723 
   734 class TTest(Test):
   724 class TTest(Test):
   735     """A "t test" is a test backed by a .t file."""
   725     """A "t test" is a test backed by a .t file."""
   736 
   726 
   737     def _run(self, testtmp, replacements, env):
   727     def _run(self, testtmp, replacements, env):
   942             exitcode = False # Set exitcode to warned.
   932             exitcode = False # Set exitcode to warned.
   943 
   933 
   944         return exitcode, postout
   934         return exitcode, postout
   945 
   935 
   946     @staticmethod
   936     @staticmethod
       
   937     def rematch(el, l):
       
   938         try:
       
   939             # use \Z to ensure that the regex matches to the end of the string
       
   940             if os.name == 'nt':
       
   941                 return re.match(el + r'\r?\n\Z', l)
       
   942             return re.match(el + r'\n\Z', l)
       
   943         except re.error:
       
   944             # el is an invalid regex
       
   945             return False
       
   946 
       
   947     @staticmethod
   947     def linematch(el, l):
   948     def linematch(el, l):
   948         if el == l: # perfect match (fast)
   949         if el == l: # perfect match (fast)
   949             return True
   950             return True
   950         if el:
   951         if el:
   951             if el.endswith(" (esc)\n"):
   952             if el.endswith(" (esc)\n"):
   952                 el = el[:-7].decode('string-escape') + '\n'
   953                 el = el[:-7].decode('string-escape') + '\n'
   953             if el == l or os.name == 'nt' and el[:-1] + '\r\n' == l:
   954             if el == l or os.name == 'nt' and el[:-1] + '\r\n' == l:
   954                 return True
   955                 return True
   955             if el.endswith(" (re)\n"):
   956             if el.endswith(" (re)\n"):
   956                 return rematch(el[:-6], l)
   957                 return TTest.rematch(el[:-6], l)
   957             if el.endswith(" (glob)\n"):
   958             if el.endswith(" (glob)\n"):
   958                 return globmatch(el[:-8], l)
   959                 return globmatch(el[:-8], l)
   959             if os.altsep and l.replace('\\', '/') == el:
   960             if os.altsep and l.replace('\\', '/') == el:
   960                 return '+glob'
   961                 return '+glob'
   961         return False
   962         return False