Jeremy Hylton | ac148b5 | 2000-10-13 22:00:13 +0000 | [diff] [blame] | 1 | """Run the Python regression test using the compiler |
| 2 | |
| 3 | This test runs the standard Python test suite using bytecode generated |
| 4 | by this compiler instead of by the builtin compiler. |
| 5 | |
| 6 | The regression test is run with the interpreter in verbose mode so |
| 7 | that import problems can be observed easily. |
| 8 | """ |
| 9 | |
Jeremy Hylton | 5d1e34a | 2001-09-17 21:31:35 +0000 | [diff] [blame] | 10 | from compiler import compileFile |
Jeremy Hylton | ac148b5 | 2000-10-13 22:00:13 +0000 | [diff] [blame] | 11 | |
| 12 | import os |
| 13 | import sys |
| 14 | import test |
| 15 | import tempfile |
| 16 | |
| 17 | def copy_test_suite(): |
Guido van Rossum | 3b0a329 | 2002-08-09 16:38:32 +0000 | [diff] [blame] | 18 | dest = tempfile.mkdtemp() |
Jeremy Hylton | ac148b5 | 2000-10-13 22:00:13 +0000 | [diff] [blame] | 19 | os.system("cp -r %s/* %s" % (test.__path__[0], dest)) |
| 20 | print "Creating copy of test suite in", dest |
| 21 | return dest |
| 22 | |
Jeremy Hylton | 2a8ec79 | 2001-08-27 20:40:43 +0000 | [diff] [blame] | 23 | def copy_library(): |
Guido van Rossum | 3b0a329 | 2002-08-09 16:38:32 +0000 | [diff] [blame] | 24 | dest = tempfile.mkdtemp() |
Jeremy Hylton | 2a8ec79 | 2001-08-27 20:40:43 +0000 | [diff] [blame] | 25 | libdir = os.path.split(test.__path__[0])[0] |
Jeremy Hylton | 5d1e34a | 2001-09-17 21:31:35 +0000 | [diff] [blame] | 26 | print "Found standard library in", libdir |
Jeremy Hylton | 2a8ec79 | 2001-08-27 20:40:43 +0000 | [diff] [blame] | 27 | print "Creating copy of standard library in", dest |
Jeremy Hylton | 5d1e34a | 2001-09-17 21:31:35 +0000 | [diff] [blame] | 28 | os.system("cp -r %s/* %s" % (libdir, dest)) |
Jeremy Hylton | 2a8ec79 | 2001-08-27 20:40:43 +0000 | [diff] [blame] | 29 | return dest |
| 30 | |
Jeremy Hylton | ac148b5 | 2000-10-13 22:00:13 +0000 | [diff] [blame] | 31 | def compile_files(dir): |
Jeremy Hylton | 5d1e34a | 2001-09-17 21:31:35 +0000 | [diff] [blame] | 32 | print "Compiling", dir, "\n\t", |
Jeremy Hylton | ac148b5 | 2000-10-13 22:00:13 +0000 | [diff] [blame] | 33 | line_len = 10 |
| 34 | for file in os.listdir(dir): |
| 35 | base, ext = os.path.splitext(file) |
Jeremy Hylton | 2a8ec79 | 2001-08-27 20:40:43 +0000 | [diff] [blame] | 36 | if ext == '.py': |
Jeremy Hylton | ac148b5 | 2000-10-13 22:00:13 +0000 | [diff] [blame] | 37 | 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 Hylton | 2a8ec79 | 2001-08-27 20:40:43 +0000 | [diff] [blame] | 43 | try: |
Jeremy Hylton | 5d1e34a | 2001-09-17 21:31:35 +0000 | [diff] [blame] | 44 | compileFile(source) |
Jeremy Hylton | 2a8ec79 | 2001-08-27 20:40:43 +0000 | [diff] [blame] | 45 | except SyntaxError, err: |
| 46 | print err |
| 47 | continue |
Jeremy Hylton | ac148b5 | 2000-10-13 22:00:13 +0000 | [diff] [blame] | 48 | # make sure the .pyc file is not over-written |
| 49 | os.chmod(source + "c", 444) |
Anthony Baxter | c2a5a63 | 2004-08-02 06:10:11 +0000 | [diff] [blame] | 50 | elif file == 'CVS': |
| 51 | pass |
Jeremy Hylton | 2a8ec79 | 2001-08-27 20:40:43 +0000 | [diff] [blame] | 52 | else: |
| 53 | path = os.path.join(dir, file) |
| 54 | if os.path.isdir(path): |
| 55 | print |
Jeremy Hylton | 5d1e34a | 2001-09-17 21:31:35 +0000 | [diff] [blame] | 56 | print |
Jeremy Hylton | 2a8ec79 | 2001-08-27 20:40:43 +0000 | [diff] [blame] | 57 | compile_files(path) |
Jeremy Hylton | 5d1e34a | 2001-09-17 21:31:35 +0000 | [diff] [blame] | 58 | print "\t", |
| 59 | line_len = 10 |
Jeremy Hylton | ac148b5 | 2000-10-13 22:00:13 +0000 | [diff] [blame] | 60 | print |
| 61 | |
Jeremy Hylton | 2a8ec79 | 2001-08-27 20:40:43 +0000 | [diff] [blame] | 62 | def run_regrtest(lib_dir): |
| 63 | test_dir = os.path.join(lib_dir, "test") |
Jeremy Hylton | ac148b5 | 2000-10-13 22:00:13 +0000 | [diff] [blame] | 64 | os.chdir(test_dir) |
Jeremy Hylton | 5d1e34a | 2001-09-17 21:31:35 +0000 | [diff] [blame] | 65 | os.system("PYTHONPATH=%s %s -v regrtest.py" % (lib_dir, sys.executable)) |
Jeremy Hylton | ac148b5 | 2000-10-13 22:00:13 +0000 | [diff] [blame] | 66 | |
| 67 | def cleanup(dir): |
| 68 | os.system("rm -rf %s" % dir) |
| 69 | |
| 70 | def main(): |
Jeremy Hylton | 2a8ec79 | 2001-08-27 20:40:43 +0000 | [diff] [blame] | 71 | lib_dir = copy_library() |
| 72 | compile_files(lib_dir) |
| 73 | run_regrtest(lib_dir) |
| 74 | raw_input("Cleanup?") |
| 75 | cleanup(lib_dir) |
Jeremy Hylton | ac148b5 | 2000-10-13 22:00:13 +0000 | [diff] [blame] | 76 | |
| 77 | if __name__ == "__main__": |
| 78 | main() |