File: run_tests.py

package info (click to toggle)
chromium-browser 41.0.2272.118-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 2,189,132 kB
  • sloc: cpp: 9,691,462; ansic: 3,341,451; python: 712,689; asm: 518,779; xml: 208,926; java: 169,820; sh: 119,353; perl: 68,907; makefile: 28,311; yacc: 13,305; objc: 11,385; tcl: 3,186; cs: 2,225; sql: 2,217; lex: 2,215; lisp: 1,349; pascal: 1,256; awk: 407; ruby: 155; sed: 53; php: 14; exp: 11
file content (75 lines) | stat: -rwxr-xr-x 2,142 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/python

import hashlib
import operator
import os
import shutil
import stat
import subprocess
import sys
import tempfile


def rel_to_abs(rel_path):
    return os.path.join(script_path, rel_path)

java_exec = 'java -Xms1024m -server -XX:+TieredCompilation'
tests_dir = 'tests'
jar_name = 'jsdoc-validator.jar'
script_path = os.path.dirname(os.path.abspath(__file__))
tests_path = rel_to_abs(tests_dir)
validator_jar_file = rel_to_abs(jar_name)
golden_file = os.path.join(tests_path, 'golden.dat')

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))]

validator_command = "%s -jar %s %s" % (java_exec, validator_jar_file, " ".join(sorted(test_files)))


def run_and_communicate(command, error_template):
    proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
    (out, _) = proc.communicate()
    if proc.returncode:
        print >> sys.stderr, error_template % proc.returncode
        sys.exit(proc.returncode)
    return out


def help():
    print 'usage: %s [option]' % os.path.basename(__file__)
    print 'Options:'
    print '--generate-golden: Re-generate golden file'
    print '--dump: Dump the test results to stdout'


def main():
    need_golden = False
    need_dump = False
    if len(sys.argv) > 1:
        if sys.argv[1] == '--generate-golden':
            need_golden = True
        elif sys.argv[1] == '--dump':
            need_dump = True
        else:
            help()
            return

    result = run_and_communicate(validator_command, "Error running validator: %d")
    result = result.replace(script_path, "")  # pylint: disable=E1103
    if need_dump:
        print result
        return

    if need_golden:
        with open(golden_file, 'wt') as golden:
            golden.write(result)
    else:
        with open(golden_file, 'rt') as golden:
            golden_text = golden.read()
            if golden_text == result:
                print 'OK'
            else:
                print 'ERROR: Golden output mismatch'

if __name__ == '__main__':
    main()