OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/python |
| 2 |
| 3 import hashlib |
| 4 import operator |
| 5 import os |
| 6 import shutil |
| 7 import stat |
| 8 import subprocess |
| 9 import sys |
| 10 import tempfile |
| 11 |
| 12 |
| 13 def rel_to_abs(rel_path): |
| 14 return os.path.join(script_path, rel_path) |
| 15 |
| 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') |
| 23 |
| 24 test_files = [os.path.join(tests_path, f) for f in os.listdir(tests_path) if f.e
ndswith('.js') and os.path.isfile(os.path.join(tests_path, f))] |
| 25 |
| 26 validator_command = "%s -jar %s %s" % (java_exec, validator_jar_file, " ".join(s
orted(test_files))) |
| 27 |
| 28 |
| 29 def run_and_communicate(command, error_template): |
| 30 proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.S
TDOUT, 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 |
| 36 |
| 37 |
| 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' |
| 43 |
| 44 |
| 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 |
| 56 |
| 57 result = run_and_communicate(validator_command, "Error running validator: %d
") |
| 58 if need_dump: |
| 59 print result |
| 60 return |
| 61 |
| 62 if need_golden: |
| 63 with open(golden_file, 'wt') as golden: |
| 64 golden.write(result) |
| 65 else: |
| 66 with open(golden_file, 'rt') as golden: |
| 67 golden_text = golden.read() |
| 68 if golden_text == result: |
| 69 print 'OK' |
| 70 else: |
| 71 print 'ERROR: Golden output mismatch' |
| 72 |
| 73 if __name__ == '__main__': |
| 74 main() |
OLD | NEW |