javaclass

Changeset

144:86cfbf965337
2005-01-23 Paul Boddie raw files shortlog changelog graph Added a simple "test everything" program.
test.py (file)
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test.py	Sun Jan 23 01:01:25 2005 +0100
     1.3 @@ -0,0 +1,52 @@
     1.4 +#!/usr/bin/env python
     1.5 +
     1.6 +"Run the test suite."
     1.7 +
     1.8 +import os, glob
     1.9 +
    1.10 +def get_test_sources():
    1.11 +    return glob.glob("*.java")
    1.12 +
    1.13 +def get_test_classes():
    1.14 +    # Use the original source files to decide which classes have main methods.
    1.15 +    return [os.path.splitext(f)[0] for f in get_test_sources()]
    1.16 +
    1.17 +def compile_test_files(javac):
    1.18 +    for java_file in get_test_sources():
    1.19 +        class_file = os.path.splitext(java_file)[0] + ".class"
    1.20 +        if not os.path.exists(class_file) or os.path.getmtime(class_file) < os.path.getmtime(java_file):
    1.21 +            print "Compiling", java_file
    1.22 +            os.system(javac + " " + java_file)
    1.23 +
    1.24 +def run_test_files(java):
    1.25 +    for class_ in get_test_classes():
    1.26 +        print "Running", class_
    1.27 +        os.system(java + " " + class_)
    1.28 +
    1.29 +if __name__ == "__main__":
    1.30 +    import sys
    1.31 +
    1.32 +    # Find the compiler.
    1.33 +
    1.34 +    java_home = os.environ.get("JAVA_HOME")
    1.35 +    if java_home:
    1.36 +        javac = os.path.join(java_home, "bin", "javac")
    1.37 +    elif len(sys.argv) > 1:
    1.38 +        javac = sys.argv[1]
    1.39 +    else:
    1.40 +        print "Cannot find a Java compiler."
    1.41 +        print "Please specify the full path as an argument to this program"
    1.42 +        print "or set JAVA_HOME to the JDK installation."
    1.43 +        sys.exit(1)
    1.44 +
    1.45 +    if not os.path.exists(javac):
    1.46 +        print "The suggested Java compiler cannot be found."
    1.47 +        sys.exit(1)
    1.48 +
    1.49 +    # Compile the programs.
    1.50 +
    1.51 +    os.chdir("tests")
    1.52 +    compile_test_files(javac)
    1.53 +    run_test_files("runclass.py")
    1.54 +
    1.55 +# vim: tabstop=4 expandtab shiftwidth=4