13 def rel_to_abs(rel_path
):
14 return os
.path
.join(script_path
, rel_path
)
16 java_exec
= 'java -Xms1024m -server -XX:+TieredCompilation'
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()
33 print >> sys
.stderr
, error_template
% proc
.returncode
34 sys
.exit(proc
.returncode
)
39 print 'usage: %s [option]' % os
.path
.basename(__file__
)
41 print '--generate-golden: Re-generate golden file'
42 print '--dump: Dump the test results to stdout'
49 if sys
.argv
[1] == '--generate-golden':
51 elif sys
.argv
[1] == '--dump':
57 result
= run_and_communicate(validator_command
, "Error running validator: %d")
58 result
= result
.replace(script_path
, "") # pylint: disable=E1103
64 with
open(golden_file
, 'wt') as golden
:
67 with
open(golden_file
, 'rt') as golden
:
68 golden_text
= golden
.read()
69 if golden_text
== result
:
72 print 'ERROR: Golden output mismatch'
74 if __name__
== '__main__':