| 
									
										
										
										
											2000-10-13 22:00:13 +00:00
										 |  |  | """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. | 
					
						
							|  |  |  | """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | from compiler import compile | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import os | 
					
						
							|  |  |  | import sys | 
					
						
							|  |  |  | import test | 
					
						
							|  |  |  | import tempfile | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def copy_test_suite(): | 
					
						
							|  |  |  |     dest = tempfile.mktemp() | 
					
						
							|  |  |  |     os.mkdir(dest) | 
					
						
							|  |  |  |     os.system("cp -r %s/* %s" % (test.__path__[0], dest)) | 
					
						
							|  |  |  |     print "Creating copy of test suite in", dest | 
					
						
							|  |  |  |     return dest | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-08-27 20:40:43 +00:00
										 |  |  | def copy_library(): | 
					
						
							|  |  |  |     dest = tempfile.mktemp() | 
					
						
							|  |  |  |     os.mkdir(dest) | 
					
						
							|  |  |  |     libdir = os.path.split(test.__path__[0])[0] | 
					
						
							|  |  |  |     os.system("cp -r %s/* %s" % (libdir, dest)) | 
					
						
							|  |  |  |     print "Creating copy of standard library in", dest | 
					
						
							|  |  |  |     return dest | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-10-13 22:00:13 +00:00
										 |  |  | def compile_files(dir): | 
					
						
							| 
									
										
										
										
											2001-08-27 20:40:43 +00:00
										 |  |  |     print "Compiling", dir | 
					
						
							| 
									
										
										
										
											2000-10-13 22:00:13 +00:00
										 |  |  |     line_len = 10 | 
					
						
							|  |  |  |     for file in os.listdir(dir): | 
					
						
							|  |  |  |         base, ext = os.path.splitext(file) | 
					
						
							| 
									
										
										
										
											2001-08-27 20:40:43 +00:00
										 |  |  |         if ext == '.py': | 
					
						
							| 
									
										
										
										
											2000-10-13 22:00:13 +00:00
										 |  |  |             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, | 
					
						
							| 
									
										
										
										
											2001-08-27 20:40:43 +00:00
										 |  |  |             try: | 
					
						
							|  |  |  |                 compile(source) | 
					
						
							|  |  |  |             except SyntaxError, err: | 
					
						
							|  |  |  |                 print err | 
					
						
							|  |  |  |                 continue | 
					
						
							| 
									
										
										
										
											2000-10-13 22:00:13 +00:00
										 |  |  |             # make sure the .pyc file is not over-written | 
					
						
							|  |  |  |             os.chmod(source + "c", 444) | 
					
						
							| 
									
										
										
										
											2001-08-27 20:40:43 +00:00
										 |  |  |         else: | 
					
						
							|  |  |  |             path = os.path.join(dir, file) | 
					
						
							|  |  |  |             if os.path.isdir(path): | 
					
						
							|  |  |  |                 print | 
					
						
							|  |  |  |                 compile_files(path) | 
					
						
							| 
									
										
										
										
											2000-10-13 22:00:13 +00:00
										 |  |  |     print | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-08-27 20:40:43 +00:00
										 |  |  | def run_regrtest(lib_dir): | 
					
						
							|  |  |  |     test_dir = os.path.join(lib_dir, "test") | 
					
						
							| 
									
										
										
										
											2000-10-13 22:00:13 +00:00
										 |  |  |     os.chdir(test_dir) | 
					
						
							| 
									
										
										
										
											2001-08-27 20:40:43 +00:00
										 |  |  |     os.system("PYTHONPATH=%s %s -v regrtest.py -r" % (lib_dir, sys.executable)) | 
					
						
							| 
									
										
										
										
											2000-10-13 22:00:13 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | def cleanup(dir): | 
					
						
							|  |  |  |     os.system("rm -rf %s" % dir) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def main(): | 
					
						
							| 
									
										
										
										
											2001-08-27 20:40:43 +00:00
										 |  |  |     lib_dir = copy_library() | 
					
						
							|  |  |  |     compile_files(lib_dir) | 
					
						
							|  |  |  |     run_regrtest(lib_dir) | 
					
						
							|  |  |  |     raw_input("Cleanup?") | 
					
						
							|  |  |  |     cleanup(lib_dir) | 
					
						
							| 
									
										
										
										
											2000-10-13 22:00:13 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | if __name__ == "__main__": | 
					
						
							|  |  |  |     main() |