| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/python | |
| 2 | |
| 3 import cStringIO as StringIO | |
| 4 from fnmatch import fnmatch | |
| 5 import difflib | |
| 6 import os | |
| 7 import sys | |
| 8 | |
| 9 | |
| 10 def get_name(filename): | |
| 11 return os.path.splitext(filename)[0] | |
| 12 | |
| 13 | |
| 14 def list_dir(dir_path, filter_func): | |
| 15 return sorted(filter(filter_func, os.listdir(dir_path)), key=get_name) | |
| 16 | |
| 17 | |
| 18 def main(): | |
| 19 test_dir = os.path.dirname(os.path.realpath(__file__)) | |
| 20 testcase_dir = os.path.join(test_dir, 'testcases') | |
| 21 testcase_file = os.path.join(test_dir, 'testcases.js') | |
| 22 | |
| 23 def is_testcase_file(filename): | |
| 24 return ( | |
| 25 fnmatch(filename, "*.html") and | |
| 26 not fnmatch(filename, "manual-test*") and | |
| 27 not fnmatch(filename, "disabled-*")) | |
| 28 | |
| 29 new_testcases = StringIO.StringIO() | |
| 30 new_testcases.write("""\ | |
| 31 // This file is automatically generated by test/update-testcases.py. | |
| 32 // Disable tests by adding them to test/disabled-testcases | |
| 33 """) | |
| 34 new_testcases.write('var tests = [\n \'') | |
| 35 new_testcases.write( | |
| 36 '\',\n \''.join(list_dir(testcase_dir, is_testcase_file))) | |
| 37 new_testcases.write('\',\n];\n') | |
| 38 new_testcases.seek(0) | |
| 39 new_testcases_lines = new_testcases.readlines() | |
| 40 | |
| 41 current_testcases_lines = file(testcase_file).readlines() | |
| 42 | |
| 43 lines = list(difflib.unified_diff( | |
| 44 current_testcases_lines, new_testcases_lines, | |
| 45 fromfile=testcase_file, tofile=testcase_file)) | |
| 46 | |
| 47 if len(lines) == 0: | |
| 48 sys.stdout.write('Nothing to do\n') | |
| 49 sys.exit(0) | |
| 50 | |
| 51 if not "--dry-run" in sys.argv: | |
| 52 file(testcase_file, "w").write("".join(new_testcases_lines)) | |
| 53 sys.stdout.write( | |
| 54 'Updating %s with the following diff.\n' % testcase_file) | |
| 55 | |
| 56 for line in lines: | |
| 57 sys.stdout.write(line) | |
| 58 | |
| 59 sys.exit(1) | |
| 60 | |
| 61 | |
| 62 if __name__ == '__main__': | |
| 63 main() | |
| OLD | NEW |