Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / devtools / scripts / jsdoc-validator / run_tests.py
blobc591eadfc5472ea1fcf42505256b2b5ea132e369
1 #!/usr/bin/python
3 import hashlib
4 import operator
5 import os
6 import shutil
7 import stat
8 import subprocess
9 import sys
10 import tempfile
13 def rel_to_abs(rel_path):
14 return os.path.join(script_path, rel_path)
16 java_exec = 'java -Xms1024m -server -XX:+TieredCompilation'
17 tests_dir = 'tests'
18 jar_name = 'jsdoc-validator.jar'
19 script_path = os.path.dirname(os.path.abspath(__file__))
20 tests_path = rel_to_abs(tests_dir)
21 validator_jar_file = rel_to_abs(jar_name)
22 golden_file = os.path.join(tests_path, 'golden.dat')
24 test_files = [os.path.join(tests_path, f) for f in os.listdir(tests_path) if f.endswith('.js') and os.path.isfile(os.path.join(tests_path, f))]
26 validator_command = "%s -jar %s %s" % (java_exec, validator_jar_file, " ".join(sorted(test_files)))
29 def run_and_communicate(command, error_template):
30 proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
31 (out, _) = proc.communicate()
32 if proc.returncode:
33 print >> sys.stderr, error_template % proc.returncode
34 sys.exit(proc.returncode)
35 return out
38 def help():
39 print 'usage: %s [option]' % os.path.basename(__file__)
40 print 'Options:'
41 print '--generate-golden: Re-generate golden file'
42 print '--dump: Dump the test results to stdout'
45 def main():
46 need_golden = False
47 need_dump = False
48 if len(sys.argv) > 1:
49 if sys.argv[1] == '--generate-golden':
50 need_golden = True
51 elif sys.argv[1] == '--dump':
52 need_dump = True
53 else:
54 help()
55 return
57 result = run_and_communicate(validator_command, "Error running validator: %d")
58 result = result.replace(script_path, "") # pylint: disable=E1103
59 if need_dump:
60 print result
61 return
63 if need_golden:
64 with open(golden_file, 'wt') as golden:
65 golden.write(result)
66 else:
67 with open(golden_file, 'rt') as golden:
68 golden_text = golden.read()
69 if golden_text == result:
70 print 'OK'
71 else:
72 print 'ERROR: Golden output mismatch'
74 if __name__ == '__main__':
75 main()