regrtest.py 2.1 KB
Newer Older
1 2 3 4 5 6 7 8 9
"""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.
"""

10
from compiler import compileFile
11 12 13 14 15 16 17

import os
import sys
import test
import tempfile

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

23
def copy_library():
24
    dest = tempfile.mkdtemp()
25
    libdir = os.path.split(test.__path__[0])[0]
26
    print "Found standard library in", libdir
27
    print "Creating copy of standard library in", dest
28
    os.system("cp -r %s/* %s" % (libdir, dest))
29 30
    return dest

31
def compile_files(dir):
32
    print "Compiling", dir, "\n\t",
33 34 35
    line_len = 10
    for file in os.listdir(dir):
        base, ext = os.path.splitext(file)
36
        if ext == '.py':
37 38 39 40 41 42
            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,
43
            try:
44
                compileFile(source)
45 46 47
            except SyntaxError, err:
                print err
                continue
48 49
            # make sure the .pyc file is not over-written
            os.chmod(source + "c", 444)
50 51
        elif file == 'CVS':
            pass
52 53 54
        else:
            path = os.path.join(dir, file)
            if os.path.isdir(path):
55
                print
56 57
                print
                compile_files(path)
58 59
                print "\t",
                line_len = 10
60 61
    print

62 63
def run_regrtest(lib_dir):
    test_dir = os.path.join(lib_dir, "test")
64
    os.chdir(test_dir)
65
    os.system("PYTHONPATH=%s %s -v regrtest.py" % (lib_dir, sys.executable))
66 67 68 69 70

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

def main():
71 72 73 74 75
    lib_dir = copy_library()
    compile_files(lib_dir)
    run_regrtest(lib_dir)
    raw_input("Cleanup?")
    cleanup(lib_dir)
76 77 78

if __name__ == "__main__":
    main()