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 | |
| 10 | from compiler import compile |
| 11 | |
| 12 | import os |
| 13 | import sys |
| 14 | import test |
| 15 | import tempfile |
| 16 | |
| 17 | def copy_test_suite(): |
| 18 | dest = tempfile.mktemp() |
| 19 | os.mkdir(dest) |
| 20 | os.system("cp -r %s/* %s" % (test.__path__[0], dest)) |
| 21 | print "Creating copy of test suite in", dest |
| 22 | return dest |
| 23 | |
| 24 | def compile_files(dir): |
| 25 | print "Compiling", |
| 26 | line_len = 10 |
| 27 | for file in os.listdir(dir): |
| 28 | base, ext = os.path.splitext(file) |
| 29 | if ext == '.py' and base[:4] == 'test': |
| 30 | source = os.path.join(dir, file) |
| 31 | line_len = line_len + len(file) + 1 |
| 32 | if line_len > 75: |
| 33 | print "\n\t", |
| 34 | line_len = len(source) + 9 |
| 35 | print file, |
| 36 | compile(source) |
| 37 | # make sure the .pyc file is not over-written |
| 38 | os.chmod(source + "c", 444) |
| 39 | print |
| 40 | |
| 41 | def run_regrtest(test_dir): |
| 42 | os.chdir(test_dir) |
| 43 | os.system("%s -v regrtest.py" % sys.executable) |
| 44 | |
| 45 | def cleanup(dir): |
| 46 | os.system("rm -rf %s" % dir) |
| 47 | |
| 48 | def main(): |
| 49 | test_dir = copy_test_suite() |
| 50 | compile_files(test_dir) |
| 51 | run_regrtest(test_dir) |
| 52 | cleanup(test_dir) |
| 53 | |
| 54 | if __name__ == "__main__": |
| 55 | main() |