1.1 --- a/runclass.py Mon Jan 24 00:46:54 2005 +0100
1.2 +++ b/runclass.py Mon Jan 24 20:08:56 2005 +0100
1.3 @@ -5,6 +5,21 @@
1.4 import javaclass.classhook
1.5 import java.lang
1.6
1.7 +# NOTE: Simple __this__ package loader to potentially avoid repeated import
1.8 +# NOTE: issues exposed by test.py.
1.9 +
1.10 +def load_classes(class_names):
1.11 +
1.12 + "Load the classes with the given 'class_names'."
1.13 +
1.14 + module = __import__("__this__", globals(), locals(), class_names)
1.15 + objs = []
1.16 + for class_name in class_names:
1.17 + objs.append(getattr(module, class_name))
1.18 + return objs
1.19 +
1.20 +# The more general class loader.
1.21 +
1.22 def load_class(class_name):
1.23
1.24 "Load the class with the given 'class_name'."
2.1 --- a/test.py Mon Jan 24 00:46:54 2005 +0100
2.2 +++ b/test.py Mon Jan 24 20:08:56 2005 +0100
2.3 @@ -3,6 +3,8 @@
2.4 "Run the test suite."
2.5
2.6 import os, glob
2.7 +import runclass
2.8 +import java.lang
2.9
2.10 def get_test_sources():
2.11 return glob.glob("*.java")
2.12 @@ -18,10 +20,11 @@
2.13 print "Compiling", java_file
2.14 os.system(javac + " " + java_file)
2.15
2.16 -def run_test_files(java):
2.17 - for class_ in get_test_classes():
2.18 - print "Running", class_
2.19 - os.system(java + " " + class_)
2.20 +def run_test_files():
2.21 + classes = runclass.load_classes(get_test_classes())
2.22 + for cls in classes:
2.23 + print "Running", cls
2.24 + runclass.run_class(cls, [java.lang.String("Test")])
2.25
2.26 if __name__ == "__main__":
2.27 import sys
2.28 @@ -34,12 +37,13 @@
2.29 elif len(sys.argv) > 1:
2.30 javac = sys.argv[1]
2.31 else:
2.32 - print "Cannot find a Java compiler."
2.33 - print "Please specify the full path as an argument to this program"
2.34 - print "or set JAVA_HOME to the JDK installation."
2.35 - sys.exit(1)
2.36 + print "Guessing that javac is your Java compiler."
2.37 + print "If this does not work then please specify the full path as an"
2.38 + print "argument to this program or set JAVA_HOME to refer to the JDK"
2.39 + print "installation."
2.40 + javac = "javac"
2.41
2.42 - if not os.path.exists(javac):
2.43 + if javac != "javac" and not os.path.exists(javac):
2.44 print "The suggested Java compiler cannot be found."
2.45 sys.exit(1)
2.46
2.47 @@ -47,6 +51,8 @@
2.48
2.49 os.chdir("tests")
2.50 compile_test_files(javac)
2.51 - run_test_files("runclass.py")
2.52 + run_test_files()
2.53 +
2.54 + print "Tests complete."
2.55
2.56 # vim: tabstop=4 expandtab shiftwidth=4