summaryrefslogtreecommitdiffstats
path: root/Tools/compiler/regrtest.py
blob: fd990a951485f709d66b8d6e29f1e63c4ff5e9b9 (plain)
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
"""Run the Python regression test using the compiler

This test runs the standard Python test suite using bytecode generated
by this compiler instead of by the builtin compiler.

The regression test is run with the interpreter in verbose mode so
that import problems can be observed easily.
"""

from compiler import compile

import os
import sys
import test
import tempfile

def copy_test_suite():
    dest = tempfile.mktemp()
    os.mkdir(dest)
    os.system("cp -r %s/* %s" % (test.__path__[0], dest))
    print "Creating copy of test suite in", dest
    return dest

def compile_files(dir):
    print "Compiling",
    line_len = 10
    for file in os.listdir(dir):
        base, ext = os.path.splitext(file)
        if ext == '.py' and base[:4] == 'test':
            source = os.path.join(dir, file)
            line_len = line_len + len(file) + 1
            if line_len > 75:
                print "\n\t",
                line_len = len(source) + 9
            print file,
            compile(source)
            # make sure the .pyc file is not over-written
            os.chmod(source + "c", 444)
    print

def run_regrtest(test_dir):
    os.chdir(test_dir)
    os.system("%s -v regrtest.py" % sys.executable)

def cleanup(dir):
    os.system("rm -rf %s" % dir)

def main():
    test_dir = copy_test_suite()
    compile_files(test_dir)
    run_regrtest(test_dir)
    cleanup(test_dir)

if __name__ == "__main__":
    main()