PageRenderTime 43ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/regression/breakage2tst.py

#
Python | 203 lines | 174 code | 3 blank | 26 comment | 1 complexity | 6dd97d425f124ce20780a7a527ab5b57 MD5 | raw file
Possible License(s): GPL-3.0
  1. #! /usr/bin/env python
  2. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
  3. # This program is distributed with GNU Go, a Go program. #
  4. # #
  5. # Write gnugo@gnu.org or see http://www.gnu.org/software/gnugo/ #
  6. # for more information. #
  7. # #
  8. # Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005 and 2006 #
  9. # by the Free Software Foundation. #
  10. # #
  11. # This program is free software; you can redistribute it and/or #
  12. # modify it under the terms of the GNU General Public License #
  13. # as published by the Free Software Foundation - version 3 #
  14. # or (at your option) any later version. #
  15. # #
  16. # This program is distributed in the hope that it will be #
  17. # useful, but WITHOUT ANY WARRANTY; without even the implied #
  18. # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR #
  19. # PURPOSE. See the GNU General Public License in file COPYING #
  20. # for more details. #
  21. # #
  22. # You should have received a copy of the GNU General Public #
  23. # License along with this program; if not, write to the Free #
  24. # Software Foundation, Inc., 51 Franklin Street, Fifth Floor, #
  25. # Boston, MA 02111, USA. #
  26. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
  27. import string
  28. import sys, getopt
  29. import re
  30. help_string = """
  31. Usage:
  32. breakage2tst.py [--pike] <BREAKAGE_FILE
  33. This creates a command line invoking regress.pike to run all tes
  34. cases that appear as unexpected PASS or FAIL in BREAKAGE_FILE.
  35. breakage2tst.py [--pike] --update <BREAKAGE_FILE
  36. This changes all .tst files so that the expected results match
  37. the behaviour of the version that produced BREAKAGE_FILE.
  38. In both cases, it needs to be run from the regression test directory.
  39. """
  40. # This prints out the list of tests from testfile in the format
  41. # <tstfile>:number
  42. def write_tests(tstfilename, tests):
  43. for number, expected in tests:
  44. print "%s:%d" % (tstfilename, number),
  45. def toggled_result(resultline, expected):
  46. if (re.search(r"\]$", resultline)):
  47. if (not expected == 0):
  48. print "Result line doesn't match 'unexpected FAIL':",
  49. print resultline
  50. sys.exit(2)
  51. return (re.sub(r"\]$", "]*", resultline))
  52. elif (re.search(r"\]\*$", resultline)):
  53. if (not expected == 1):
  54. print "Result line doesn't match 'unexpected PASS':",
  55. print resultline
  56. sys.exit(2)
  57. return (re.sub(r"\]\*$", "]", resultline))
  58. else:
  59. print "Couldn't parse alleged result line:", resultline
  60. sys.exit(2)
  61. # This toggles the expected result in the .tst-file "tstfilename" for
  62. # all tests whose id is listed in "tests"
  63. def update_tstfile(tstfilename, tests):
  64. if len(tests) == 0:
  65. print tstfilename, "unchanged."
  66. return
  67. print "Updating", tstfilename
  68. tstfile = open(tstfilename, 'r')
  69. tstlines = tstfile.readlines()
  70. tstfile.close
  71. new_tstfile = ''
  72. for number, expected in tests:
  73. current_line = tstlines.pop(0)
  74. command_pattern = re.compile("^%d " % number)
  75. # Look for the line containing the command with matching id,
  76. # while keeping recent commands and comments
  77. while (not command_pattern.match(current_line)):
  78. new_tstfile = new_tstfile + current_line
  79. current_line = tstlines.pop(0)
  80. # Found match. Now look for the result line:
  81. while (not re.match(r"^#\?", current_line)):
  82. new_tstfile = new_tstfile + current_line
  83. current_line = tstlines.pop(0)
  84. new_tstfile = new_tstfile + toggled_result(current_line,
  85. expected)
  86. # Now copy the rest of the file without change.
  87. new_tstfile = new_tstfile + string.join(tstlines, '')
  88. tstfile = open(tstfilename, 'w')
  89. tstfile.write(new_tstfile)
  90. tstfile.close
  91. def parse_input(do_work):
  92. tests = []
  93. filename = ''
  94. while 1:
  95. try:
  96. inputline = raw_input()
  97. except EOFError:
  98. do_work(filename, tests)
  99. break
  100. else:
  101. s = string.split(inputline)
  102. if len(s) == 0:
  103. continue
  104. if (re.search(r"regress\.sh", s[0])
  105. or re.search(r"eval\.sh", s[0])):
  106. if (filename != ''):
  107. do_work(filename, tests)
  108. filename = re.search(r"[^\s]+\.tst", inputline).group()
  109. tests = []
  110. elif (re.search("PASS", string.join(s[1:3]))):
  111. tests.append([int(s[0]), 1])
  112. elif (re.search("FAIL", string.join(s[1:3]))):
  113. tests.append([int(s[0]), 0])
  114. def parse_pike_input(do_work):
  115. tests = []
  116. filename = ''
  117. while 1:
  118. try:
  119. inputline = raw_input()
  120. except EOFError:
  121. if (filename != ''):
  122. do_work(filename, tests)
  123. break
  124. else:
  125. s = string.split(inputline)
  126. if (not re.search(r"\:", s[0])):
  127. continue
  128. new_filename = re.search(r"[^:]+", s[0]).group() \
  129. + ".tst"
  130. if (filename != new_filename):
  131. if (filename != ''):
  132. do_work(filename, tests)
  133. filename = new_filename
  134. tests = []
  135. number = int(re.search(r"[\d]+$", s[0]).group())
  136. if (s[1] == "PASS"):
  137. tests.append([number, 1])
  138. elif (s[1] == "FAIL"):
  139. tests.append([number, 0])
  140. else:
  141. print "Inconsistent input line:", inputline
  142. sys.exit(2)
  143. def main():
  144. mode = 0
  145. pike = 0
  146. try:
  147. opts, args = getopt.getopt(sys.argv[1:], "",
  148. ["update", "help", "pike"])
  149. except getopt.GetoptError:
  150. print "breakage2tst: Unrecognized option."
  151. print help_string
  152. sys.exit(2)
  153. if (args != []):
  154. print "I know nothing about arguments", args
  155. print help_string
  156. sys.exit(2)
  157. for o, a in opts:
  158. if (o == "--help"):
  159. print help_string
  160. sys.exit()
  161. if (o == "--update"):
  162. mode = 1
  163. if (o == "--pike"):
  164. pike = 1
  165. if (mode == 0):
  166. print "./regress.pike ",
  167. do_work = write_tests
  168. else:
  169. do_work = update_tstfile
  170. if (pike):
  171. parse_pike_input(do_work)
  172. else:
  173. parse_input(do_work)
  174. if (mode == 0):
  175. print
  176. else:
  177. print "Done."
  178. main()