##// END OF EJS Templates
run-tests: make rematch a static method of TTest
Gregory Szorc -
r21316:ab9bf8a5 default
parent child Browse files
Show More
@@ -695,16 +695,6 b' def escapef(m):'
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.
@@ -729,7 +719,7 b' def globmatch(el, l):'
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."""
@@ -944,6 +934,17 b' class TTest(Test):'
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
@@ -953,7 +954,7 b' class TTest(Test):'
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:
General Comments 0
You need to be logged in to leave comments. Login now