summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Knight <knight@baldmt.com>2004-11-11 11:34:27 (GMT)
committerSteven Knight <knight@baldmt.com>2004-11-11 11:34:27 (GMT)
commitd74794f92c9d9cdbf0e4b4c07a9b303bdb02fe66 (patch)
tree833bb29e6c6e44a5f7eb3d063ebb138a7af244f4
parent8136dc27333b13b7b51d0e94819767adf10ac123 (diff)
downloadSCons-d74794f92c9d9cdbf0e4b4c07a9b303bdb02fe66.zip
SCons-d74794f92c9d9cdbf0e4b4c07a9b303bdb02fe66.tar.gz
SCons-d74794f92c9d9cdbf0e4b4c07a9b303bdb02fe66.tar.bz2
Fix hard-coding of Java paths in tests. (Kevin Quick)
-rw-r--r--src/CHANGES.txt2
-rw-r--r--test/JAR.py50
-rw-r--r--test/JARFLAGS.py47
-rw-r--r--test/JAVAC.py25
-rw-r--r--test/JAVACFLAGS.py22
-rw-r--r--test/JAVAH.py52
6 files changed, 140 insertions, 58 deletions
diff --git a/src/CHANGES.txt b/src/CHANGES.txt
index ded0c5c..3b63109 100644
--- a/src/CHANGES.txt
+++ b/src/CHANGES.txt
@@ -268,6 +268,8 @@ RELEASE 0.97 - XXX
the source directory and trying to use entries from the build_dir
as sources for other targets in the build-dir.
+ - Fix hard-coding of JDK path names in various Java tests.
+
From Levi Stephen:
- Allow $JARCHDIR to be expanded to other construction variables.
diff --git a/test/JAR.py b/test/JAR.py
index cec6c5b..ea51213 100644
--- a/test/JAR.py
+++ b/test/JAR.py
@@ -67,7 +67,7 @@ line 3
test.run(arguments = '.', stderr = None)
-test.fail_test(test.read('test1.jar') != "test1.class\nline 3\n")
+test.must_match('test1.jar', "test1.class\nline 3\n")
if os.path.normcase('.class') == os.path.normcase('.CLASS'):
@@ -85,7 +85,7 @@ line 3
test.run(arguments = '.', stderr = None)
- test.fail_test(test.read('test2.jar') != "test2.CLASS\nline 3\n")
+ test.must_match('test2.jar', "test2.CLASS\nline 3\n")
test.write('myjar2.py', r"""
import sys
@@ -116,11 +116,32 @@ test.write('foo.mf',
blah
""")
test.run(arguments='classes.jar')
-test.fail_test(test.read('classes.jar') != 'cvfm classes.jar foo.mf -C testdir bar.class\n')
-
-if not os.path.exists('/usr/local/j2sdk1.3.1/bin/javac'):
- print "Could not find Java, skipping test(s)."
- test.pass_test(1)
+test.must_match('classes.jar',
+ 'cvfm classes.jar foo.mf -C testdir bar.class\n')
+
+if test.detect_tool('javac'):
+ where_javac = test.detect('JAVAC', 'javac')
+else:
+ import SCons.Environment
+ env = SCons.Environment.Environment()
+ where_javac = env.WhereIs('javac', os.environ['PATH'])
+ if not where_javac:
+ where_javac = env.WhereIs('javac', '/usr/local/j2sdk1.3.1/bin')
+ if not where_javac:
+ print "Could not find Java javac, skipping test(s)."
+ test.pass_test(1)
+
+if test.detect_tool('jar'):
+ where_jar = test.detect('JAR', 'jar')
+else:
+ import SCons.Environment
+ env = SCons.Environment.Environment()
+ where_jar = env.WhereIs('jar', os.environ['PATH'])
+ if not where_jar:
+ where_jar = env.WhereIs('jar', '/usr/local/j2sdk1.3.1/bin')
+ if not where_jar:
+ print "Could not find Java jar, skipping test(s)."
+ test.pass_test(1)
test.write("wrapper.py", """\
@@ -133,15 +154,15 @@ os.system(string.join(sys.argv[1:], " "))
test.write('SConstruct', """
foo = Environment(tools = ['javac', 'jar'],
- JAVAC = '/usr/local/j2sdk1.3.1/bin/javac',
- JAR = '/usr/local/j2sdk1.3.1/bin/jar')
+ JAVAC = '%(where_javac)s',
+ JAR = '%(where_jar)s')
jar = foo.Dictionary('JAR')
-bar = foo.Copy(JAR = r'%s wrapper.py ' + jar)
+bar = foo.Copy(JAR = r'%(python)s wrapper.py ' + jar)
foo.Java(target = 'classes', source = 'com/sub/foo')
bar.Java(target = 'classes', source = 'com/sub/bar')
foo.Jar(target = 'foo', source = 'classes/com/sub/foo')
bar.Jar(target = 'bar', source = 'classes/com/sub/bar')
-""" % python)
+""" % locals())
test.subdir('com',
['com', 'sub'],
@@ -234,10 +255,11 @@ public class Example6
test.run(arguments = '.')
-test.fail_test(test.read('wrapper.out') != "wrapper.py /usr/local/j2sdk1.3.1/bin/jar cf bar.jar classes/com/sub/bar\n")
+test.must_match('wrapper.out',
+ "wrapper.py %(where_jar)s cf bar.jar classes/com/sub/bar\n" % locals())
-test.fail_test(not os.path.exists(test.workpath('foo.jar')))
-test.fail_test(not os.path.exists(test.workpath('bar.jar')))
+test.must_exist('foo.jar')
+test.must_exist('bar.jar')
test.up_to_date(arguments = '.')
diff --git a/test/JARFLAGS.py b/test/JARFLAGS.py
index 539806f..7e3669d 100644
--- a/test/JARFLAGS.py
+++ b/test/JARFLAGS.py
@@ -32,15 +32,39 @@ test = TestSCons.TestSCons()
test.subdir('src')
+if test.detect_tool('javac'):
+ where_javac = test.detect('JAVAC', 'javac')
+else:
+ import SCons.Environment
+ env = SCons.Environment.Environment()
+ where_javac = env.WhereIs('javac', os.environ['PATH'])
+ if not where_javac:
+ where_javac = env.WhereIs('javac', '/usr/local/j2sdk1.3.1/bin')
+ if not where_javac:
+ print "Could not find Java javac, skipping test(s)."
+ test.pass_test(1)
+
+if test.detect_tool('jar'):
+ where_jar = test.detect('JAR', 'jar')
+else:
+ import SCons.Environment
+ env = SCons.Environment.Environment()
+ where_jar = env.WhereIs('jar', os.environ['PATH'])
+ if not where_jar:
+ where_jar = env.WhereIs('jar', '/usr/local/j2sdk1.3.1/bin')
+ if not where_jar:
+ print "Could not find Java jar, skipping test(s)."
+ test.pass_test(1)
+
test.write('SConstruct', """
env = Environment(tools = ['javac', 'jar'],
- JAVAC = '/usr/local/j2sdk1.3.1/bin/javac',
- JAR = '/usr/local/j2sdk1.3.1/bin/jar',
+ JAVAC = '%(where_javac)s',
+ JAR = '%(where_jar)s',
JARFLAGS = 'cvf')
env['JARFLAGS'] = 'cvf'
class_files = env.Java(target = 'classes', source = 'src')
env.Jar(target = 'test.jar', source = class_files)
-""")
+""" % locals())
test.write(['src', 'Example1.java'], """\
package src;
@@ -56,18 +80,15 @@ public class Example1
}
""")
-if not os.path.exists('/usr/local/j2sdk1.3.1/bin/javac'):
- print "Could not find Java, skipping test(s)."
- test.pass_test(1)
-
test.run(arguments = '.',
+ match=TestSCons.match_re_dotall,
stdout = test.wrap_stdout("""\
-/usr/local/j2sdk1.3.1/bin/javac -d classes -sourcepath src src/Example1.java
-/usr/local/j2sdk1.3.1/bin/jar cvf test.jar classes/src/Example1.class
-added manifest
-adding: classes/src/Example1.class(in = 265) (out= 199)(deflated 24%)
-"""))
+%(where_javac)s -d classes -sourcepath src src/Example1\.java
+%(where_jar)s cvf test.jar classes/src/Example1\.class
+.*
+adding: classes/src/Example1\.class.*
+""" % locals()))
-test.fail_test(not os.path.exists(test.workpath('test.jar')))
+test.must_exist('test.jar')
test.pass_test()
diff --git a/test/JAVAC.py b/test/JAVAC.py
index fafe3a9..779045f 100644
--- a/test/JAVAC.py
+++ b/test/JAVAC.py
@@ -70,7 +70,7 @@ line 3
test.run(arguments = '.', stderr = None)
-test.fail_test(test.read('test1.class') != "test1.java\nline 3\n")
+test.must_match('test1.class', "test1.java\nline 3\n")
if os.path.normcase('.java') == os.path.normcase('.JAVA'):
@@ -88,12 +88,21 @@ line 3
test.run(arguments = '.', stderr = None)
- test.fail_test(test.read('test2.class') != "test2.JAVA\nline 3\n")
+ test.must_match('test2.class', "test2.JAVA\nline 3\n")
-if not os.path.exists('/usr/local/j2sdk1.3.1/bin/javac'):
- print "Could not find Java, skipping test(s)."
- test.pass_test(1)
+if test.detect_tool('javac'):
+ where_javac = test.detect('JAVAC', 'javac')
+else:
+ import SCons.Environment
+ env = SCons.Environment.Environment()
+ where_javac = env.WhereIs('javac', os.environ['PATH'])
+ if not where_javac:
+ where_javac = env.WhereIs('javac', '/usr/local/j2sdk1.3.1/bin')
+ if not where_javac:
+ print "Could not find Java, skipping test(s)."
+ test.pass_test(1)
+
test.write("wrapper.py", """\
@@ -106,13 +115,13 @@ os.system(string.join(sys.argv[1:], " "))
test.write('SConstruct', """
foo = Environment(tools = ['javac'],
- JAVAC = '/usr/local/j2sdk1.3.1/bin/javac')
+ JAVAC = '%s')
javac = foo.Dictionary('JAVAC')
bar = foo.Copy(JAVAC = r'%s wrapper.py ' + javac)
foo.Java(target = 'class1', source = 'com/sub/foo')
bar.Java(target = 'class2', source = 'com/sub/bar')
foo.Java(target = 'class3', source = ['src1', 'src2'])
-""" % python)
+""" % (where_javac, python))
test.subdir('com',
['com', 'sub'],
@@ -278,7 +287,7 @@ class Private {
test.run(arguments = '.')
-test.must_match('wrapper.out', "wrapper.py /usr/local/j2sdk1.3.1/bin/javac -d class2 -sourcepath com/sub/bar com/sub/bar/Example4.java com/sub/bar/Example5.java com/sub/bar/Example6.java\n")
+test.must_match('wrapper.out', "wrapper.py %s -d class2 -sourcepath com/sub/bar com/sub/bar/Example4.java com/sub/bar/Example5.java com/sub/bar/Example6.java\n" % where_javac)
test.must_exist(test.workpath('class1', 'com', 'sub', 'foo', 'Example1.class'))
test.must_exist(test.workpath('class1', 'com', 'other', 'Example2.class'))
diff --git a/test/JAVACFLAGS.py b/test/JAVACFLAGS.py
index 6e02bb6..ef084cd 100644
--- a/test/JAVACFLAGS.py
+++ b/test/JAVACFLAGS.py
@@ -30,18 +30,26 @@ import TestSCons
test = TestSCons.TestSCons()
-if not os.path.exists('/usr/local/j2sdk1.3.1/bin/javac'):
- print "Could not find Java, skipping test(s)."
- test.pass_test(1)
+if test.detect_tool('javac'):
+ where_javac = test.detect('JAVAC', 'javac')
+else:
+ import SCons.Environment
+ env = SCons.Environment.Environment()
+ where_javac = env.WhereIs('javac', os.environ['PATH'])
+ if not where_javac:
+ where_javac = env.WhereIs('javac', '/usr/local/j2sdk1.3.1/bin')
+ if not where_javac:
+ print "Could not find Java javac, skipping test(s)."
+ test.pass_test(1)
test.subdir('src')
test.write('SConstruct', """
env = Environment(tools = ['javac'],
- JAVAC = '/usr/local/j2sdk1.3.1/bin/javac',
+ JAVAC = '%(where_javac)s',
JAVACFLAGS = '-O')
env.Java(target = 'classes', source = 'src')
-""")
+""" % locals())
test.write(['src', 'Example1.java'], """\
package src;
@@ -58,8 +66,8 @@ public class Example1
""")
test.run(arguments = '.',
- stdout = test.wrap_stdout("/usr/local/j2sdk1.3.1/bin/javac -O -d classes -sourcepath src src/Example1.java\n"))
+ stdout = test.wrap_stdout("%(where_javac)s -O -d classes -sourcepath src src/Example1.java\n" % locals()))
-test.fail_test(not os.path.exists(test.workpath('classes', 'src', 'Example1.class')))
+test.must_exist(['classes', 'src', 'Example1.class'])
test.pass_test()
diff --git a/test/JAVAH.py b/test/JAVAH.py
index b318335..b70fde0 100644
--- a/test/JAVAH.py
+++ b/test/JAVAH.py
@@ -73,7 +73,7 @@ line 3
test.run(arguments = '.', stderr = None)
-test.fail_test(test.read('test1.h') != "test1.java\nline 3\n")
+test.must_match('test1.h', "test1.java\nline 3\n")
if os.path.normcase('.java') == os.path.normcase('.JAVA'):
@@ -91,12 +91,32 @@ line 3
test.run(arguments = '.', stderr = None)
- test.fail_test(test.read('test2.h') != "test2.JAVA\nline 3\n")
+ test.must_match('test2.h', "test2.JAVA\nline 3\n")
-if not os.path.exists('/usr/local/j2sdk1.3.1/bin/javah'):
- print "Could not find Java, skipping test(s)."
- test.pass_test(1)
+if test.detect_tool('javac'):
+ where_javac = test.detect('JAVAC', 'javac')
+else:
+ import SCons.Environment
+ env = SCons.Environment.Environment()
+ where_javac = env.WhereIs('javac', os.environ['PATH'])
+ if not where_javac:
+ where_javac = env.WhereIs('javac', '/usr/local/j2sdk1.3.1/bin')
+ if not where_javac:
+ print "Could not find Java javac, skipping test(s)."
+ test.pass_test(1)
+
+if test.detect_tool('javah'):
+ where_javah = test.detect('JAVAH', 'javah')
+else:
+ import SCons.Environment
+ env = SCons.Environment.Environment()
+ where_javah = env.WhereIs('javah', os.environ['PATH'])
+ if not where_javah:
+ where_javah = env.WhereIs('javah', '/usr/local/j2sdk1.3.1/bin')
+ if not where_javah:
+ print "Could not find Java javah, skipping test(s)."
+ test.pass_test(1)
@@ -110,10 +130,10 @@ os.system(string.join(sys.argv[1:], " "))
test.write('SConstruct', """
foo = Environment(tools = ['javac', 'javah'],
- JAVAC = '/usr/local/j2sdk1.3.1/bin/javac',
- JAVAH = '/usr/local/j2sdk1.3.1/bin/javah')
+ JAVAC = '%(where_javac)s',
+ JAVAH = '%(where_javah)s')
javah = foo.Dictionary('JAVAH')
-bar = foo.Copy(JAVAH = r'%s wrapper.py ' + javah)
+bar = foo.Copy(JAVAH = r'%(python)s wrapper.py ' + javah)
foo.Java(target = 'class1', source = 'com/sub/foo')
bar_classes = bar.Java(target = 'class2', source = 'com/sub/bar')
foo_classes = foo.Java(target = 'class3', source = 'src')
@@ -128,7 +148,7 @@ foo.Install('class4/com/sub/foo', 'class1/com/sub/foo/Example1.class')
foo.JavaH(target = 'outdir4',
source = ['class4/com/sub/foo/Example1.class'],
JAVACLASSDIR = 'class4')
-""" % python)
+""" % locals())
test.subdir('com',
['com', 'sub'],
@@ -280,15 +300,15 @@ class Private {
test.run(arguments = '.')
-test.fail_test(test.read('wrapper.out') != "wrapper.py /usr/local/j2sdk1.3.1/bin/javah -d outdir2 -classpath class2 com.sub.bar.Example4 com.other.Example5 com.sub.bar.Example6\n")
+test.fail_test(test.read('wrapper.out') != "wrapper.py %(where_javah)s -d outdir2 -classpath class2 com.sub.bar.Example4 com.other.Example5 com.sub.bar.Example6\n" % locals())
-test.fail_test(not os.path.exists(test.workpath('outdir1', 'com_sub_foo_Example1.h')))
-test.fail_test(not os.path.exists(test.workpath('outdir1', 'com_other_Example2.h')))
-test.fail_test(not os.path.exists(test.workpath('outdir1', 'com_sub_foo_Example3.h')))
+test.must_exist(['outdir1', 'com_sub_foo_Example1.h'])
+test.must_exist(['outdir1', 'com_other_Example2.h'])
+test.must_exist(['outdir1', 'com_sub_foo_Example3.h'])
-test.fail_test(not os.path.exists(test.workpath('outdir2', 'com_sub_bar_Example4.h')))
-test.fail_test(not os.path.exists(test.workpath('outdir2', 'com_other_Example5.h')))
-test.fail_test(not os.path.exists(test.workpath('outdir2', 'com_sub_bar_Example6.h')))
+test.must_exist(['outdir2', 'com_sub_bar_Example4.h'])
+test.must_exist(['outdir2', 'com_other_Example5.h'])
+test.must_exist(['outdir2', 'com_sub_bar_Example6.h'])
test.up_to_date(arguments = '.')