blob: 1739fdd296a6c0949bcebd63dd0a9f2359723525 [file] [log] [blame]
Blink Reformat4c46d092018-04-07 15:32:37 +00001#!/usr/bin/python
2
3import hashlib
4import operator
5import os
6import shutil
7import stat
8import subprocess
9import sys
10import tempfile
11
12
13def rel_to_abs(rel_path):
14 return os.path.join(script_path, rel_path)
15
16
17java_exec = 'java -Xms1024m -server -XX:+TieredCompilation'
18tests_dir = 'tests'
19jar_name = 'jsdoc_validator.jar'
20script_path = os.path.dirname(os.path.abspath(__file__))
21tests_path = rel_to_abs(tests_dir)
22validator_jar_file = rel_to_abs(jar_name)
23golden_file = os.path.join(tests_path, 'golden.dat')
24
25test_files = [
Yang Guo4fd355c2019-09-19 10:59:03 +020026 os.path.join(tests_path, f)
27 for f in os.listdir(tests_path)
Blink Reformat4c46d092018-04-07 15:32:37 +000028 if f.endswith('.js') and os.path.isfile(os.path.join(tests_path, f))
29]
30
31validator_command = "%s -jar %s %s" % (java_exec, validator_jar_file, " ".join(sorted(test_files)))
32
33
34def run_and_communicate(command, error_template):
35 proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
36 (out, _) = proc.communicate()
37 if proc.returncode:
38 print >> sys.stderr, error_template % proc.returncode
39 sys.exit(proc.returncode)
40 return out
41
42
43def help():
44 print 'usage: %s [option]' % os.path.basename(__file__)
45 print 'Options:'
46 print '--generate-golden: Re-generate golden file'
47 print '--dump: Dump the test results to stdout'
48
49
50def main():
51 need_golden = False
52 need_dump = False
53 if len(sys.argv) > 1:
54 if sys.argv[1] == '--generate-golden':
55 need_golden = True
56 elif sys.argv[1] == '--dump':
57 need_dump = True
58 else:
59 help()
60 return
61
62 result = run_and_communicate(validator_command, "Error running validator: %d")
63 result = result.replace(script_path, "") # pylint: disable=E1103
64 if need_dump:
65 print result
66 return
67
68 if need_golden:
69 with open(golden_file, 'wt') as golden:
70 golden.write(result)
71 else:
72 with open(golden_file, 'rt') as golden:
73 golden_text = golden.read()
74 if golden_text == result:
75 print 'OK'
76 else:
77 print 'ERROR: Golden output mismatch'
78
79
80if __name__ == '__main__':
81 main()