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