javaclass

test.py

158:a52e70c3f294
2005-01-23 Paul Boddie Added "safety measures" for exception offset insertion, although better measures are necessary to avoid bizarre JDK 1.4 exception tables.
     1 #!/usr/bin/env python     2      3 "Run the test suite."     4      5 import os, glob     6      7 def get_test_sources():     8     return glob.glob("*.java")     9     10 def get_test_classes():    11     # Use the original source files to decide which classes have main methods.    12     return [os.path.splitext(f)[0] for f in get_test_sources()]    13     14 def compile_test_files(javac):    15     for java_file in get_test_sources():    16         class_file = os.path.splitext(java_file)[0] + ".class"    17         if not os.path.exists(class_file) or os.path.getmtime(class_file) < os.path.getmtime(java_file):    18             print "Compiling", java_file    19             os.system(javac + " " + java_file)    20     21 def run_test_files(java):    22     for class_ in get_test_classes():    23         print "Running", class_    24         os.system(java + " " + class_)    25     26 if __name__ == "__main__":    27     import sys    28     29     # Find the compiler.    30     31     java_home = os.environ.get("JAVA_HOME")    32     if java_home:    33         javac = os.path.join(java_home, "bin", "javac")    34     elif len(sys.argv) > 1:    35         javac = sys.argv[1]    36     else:    37         print "Cannot find a Java compiler."    38         print "Please specify the full path as an argument to this program"    39         print "or set JAVA_HOME to the JDK installation."    40         sys.exit(1)    41     42     if not os.path.exists(javac):    43         print "The suggested Java compiler cannot be found."    44         sys.exit(1)    45     46     # Compile the programs.    47     48     os.chdir("tests")    49     compile_test_files(javac)    50     run_test_files("runclass.py")    51     52 # vim: tabstop=4 expandtab shiftwidth=4