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