1 #!/usr/bin/env python 2 3 "Run the test suite." 4 5 import os, glob 6 import runclass 7 import java.lang 8 9 def get_test_sources(): 10 return glob.glob("*.java") 11 12 def get_test_classes(): 13 # Use the original source files to decide which classes have main methods. 14 return [os.path.splitext(f)[0] for f in get_test_sources()] 15 16 def compile_test_files(javac): 17 for java_file in get_test_sources(): 18 class_file = os.path.splitext(java_file)[0] + ".class" 19 if not os.path.exists(class_file) or os.path.getmtime(class_file) < os.path.getmtime(java_file): 20 print "Compiling", java_file 21 os.system(javac + " " + java_file) 22 23 def run_test_files(): 24 classes = runclass.load_classes(get_test_classes()) 25 for cls in classes: 26 print "Running", cls 27 runclass.run_class(cls, [java.lang.String("Test")]) 28 29 if __name__ == "__main__": 30 import sys 31 32 # Find the compiler. 33 34 java_home = os.environ.get("JAVA_HOME") 35 if java_home: 36 javac = os.path.join(java_home, "bin", "javac") 37 elif len(sys.argv) > 1: 38 javac = sys.argv[1] 39 else: 40 print "Guessing that javac is your Java compiler." 41 print "If this does not work then please specify the full path as an" 42 print "argument to this program or set JAVA_HOME to refer to the JDK" 43 print "installation." 44 javac = "javac" 45 46 if javac != "javac" and not os.path.exists(javac): 47 print "The suggested Java compiler cannot be found." 48 sys.exit(1) 49 50 # Compile the programs. 51 52 os.chdir("tests") 53 compile_test_files(javac) 54 run_test_files() 55 56 print "Tests complete." 57 58 # vim: tabstop=4 expandtab shiftwidth=4