blob: 50d06e71f3b6203742c22e075576e61b25aafdfe [file] [log] [blame]
Jeremy Hyltonac148b52000-10-13 22:00:13 +00001"""Run the Python regression test using the compiler
2
3This test runs the standard Python test suite using bytecode generated
4by this compiler instead of by the builtin compiler.
5
6The regression test is run with the interpreter in verbose mode so
7that import problems can be observed easily.
8"""
9
Jeremy Hylton5d1e34a2001-09-17 21:31:35 +000010from compiler import compileFile
Jeremy Hyltonac148b52000-10-13 22:00:13 +000011
12import os
13import sys
14import test
15import tempfile
16
17def copy_test_suite():
Guido van Rossum3b0a3292002-08-09 16:38:32 +000018 dest = tempfile.mkdtemp()
Jeremy Hyltonac148b52000-10-13 22:00:13 +000019 os.system("cp -r %s/* %s" % (test.__path__[0], dest))
20 print "Creating copy of test suite in", dest
21 return dest
22
Jeremy Hylton2a8ec792001-08-27 20:40:43 +000023def copy_library():
Guido van Rossum3b0a3292002-08-09 16:38:32 +000024 dest = tempfile.mkdtemp()
Jeremy Hylton2a8ec792001-08-27 20:40:43 +000025 libdir = os.path.split(test.__path__[0])[0]
Jeremy Hylton5d1e34a2001-09-17 21:31:35 +000026 print "Found standard library in", libdir
Jeremy Hylton2a8ec792001-08-27 20:40:43 +000027 print "Creating copy of standard library in", dest
Jeremy Hylton5d1e34a2001-09-17 21:31:35 +000028 os.system("cp -r %s/* %s" % (libdir, dest))
Jeremy Hylton2a8ec792001-08-27 20:40:43 +000029 return dest
30
Jeremy Hyltonac148b52000-10-13 22:00:13 +000031def compile_files(dir):
Jeremy Hylton5d1e34a2001-09-17 21:31:35 +000032 print "Compiling", dir, "\n\t",
Jeremy Hyltonac148b52000-10-13 22:00:13 +000033 line_len = 10
34 for file in os.listdir(dir):
35 base, ext = os.path.splitext(file)
Jeremy Hylton2a8ec792001-08-27 20:40:43 +000036 if ext == '.py':
Jeremy Hyltonac148b52000-10-13 22:00:13 +000037 source = os.path.join(dir, file)
38 line_len = line_len + len(file) + 1
39 if line_len > 75:
40 print "\n\t",
41 line_len = len(source) + 9
42 print file,
Jeremy Hylton2a8ec792001-08-27 20:40:43 +000043 try:
Jeremy Hylton5d1e34a2001-09-17 21:31:35 +000044 compileFile(source)
Jeremy Hylton2a8ec792001-08-27 20:40:43 +000045 except SyntaxError, err:
46 print err
47 continue
Jeremy Hyltonac148b52000-10-13 22:00:13 +000048 # make sure the .pyc file is not over-written
49 os.chmod(source + "c", 444)
Anthony Baxterc2a5a632004-08-02 06:10:11 +000050 elif file == 'CVS':
51 pass
Jeremy Hylton2a8ec792001-08-27 20:40:43 +000052 else:
53 path = os.path.join(dir, file)
54 if os.path.isdir(path):
55 print
Jeremy Hylton5d1e34a2001-09-17 21:31:35 +000056 print
Jeremy Hylton2a8ec792001-08-27 20:40:43 +000057 compile_files(path)
Jeremy Hylton5d1e34a2001-09-17 21:31:35 +000058 print "\t",
59 line_len = 10
Jeremy Hyltonac148b52000-10-13 22:00:13 +000060 print
61
Jeremy Hylton2a8ec792001-08-27 20:40:43 +000062def run_regrtest(lib_dir):
63 test_dir = os.path.join(lib_dir, "test")
Jeremy Hyltonac148b52000-10-13 22:00:13 +000064 os.chdir(test_dir)
Jeremy Hylton5d1e34a2001-09-17 21:31:35 +000065 os.system("PYTHONPATH=%s %s -v regrtest.py" % (lib_dir, sys.executable))
Jeremy Hyltonac148b52000-10-13 22:00:13 +000066
67def cleanup(dir):
68 os.system("rm -rf %s" % dir)
69
70def main():
Jeremy Hylton2a8ec792001-08-27 20:40:43 +000071 lib_dir = copy_library()
72 compile_files(lib_dir)
73 run_regrtest(lib_dir)
74 raw_input("Cleanup?")
75 cleanup(lib_dir)
Jeremy Hyltonac148b52000-10-13 22:00:13 +000076
77if __name__ == "__main__":
78 main()