summaryrefslogtreecommitdiffstats
path: root/test/Java
diff options
context:
space:
mode:
authorWilliam Deegan <bill@baddogconsulting.com>2018-09-30 18:20:39 (GMT)
committerWilliam Deegan <bill@baddogconsulting.com>2018-09-30 18:20:39 (GMT)
commit6c916c5723add8bd00f891d1bad165b79696400a (patch)
treef7bb4c55587712dc07b6e77850f87ebd6404530b /test/Java
parent748b05d34deacb718a57b2463aa9a1f10958740c (diff)
downloadSCons-6c916c5723add8bd00f891d1bad165b79696400a.zip
SCons-6c916c5723add8bd00f891d1bad165b79696400a.tar.gz
SCons-6c916c5723add8bd00f891d1bad165b79696400a.tar.bz2
change method of finding javac from using full path (which fails when it has a space in it), to appending the path to javac to env['ENV']['PATH']. (Which is basically what msvc/msvs do)
Diffstat (limited to 'test/Java')
-rw-r--r--test/Java/Java-1.6.py260
-rw-r--r--test/Java/Java-1.8.py149
-rw-r--r--test/Java/java_version_image/SConstruct33
-rw-r--r--test/Java/java_version_image/class6/test$1.classbin0 -> 165 bytes
-rw-r--r--test/Java/java_version_image/com/sub/bar/Example4.java11
-rw-r--r--test/Java/java_version_image/com/sub/bar/Example5.java11
-rw-r--r--test/Java/java_version_image/com/sub/bar/Example6.java11
-rw-r--r--test/Java/java_version_image/com/sub/foo/Example1.java11
-rw-r--r--test/Java/java_version_image/com/sub/foo/Example2.java11
-rw-r--r--test/Java/java_version_image/com/sub/foo/Example3.java11
-rw-r--r--test/Java/java_version_image/src1/Example7.java9
-rw-r--r--test/Java/java_version_image/src2/Test.java55
-rw-r--r--test/Java/java_version_image/src4/NestedExample.java31
-rw-r--r--test/Java/java_version_image/src5/TestSCons.java7
-rw-r--r--test/Java/java_version_image/src6/TestSCons.java13
15 files changed, 373 insertions, 250 deletions
diff --git a/test/Java/Java-1.6.py b/test/Java/Java-1.6.py
index 04a9155..f1ca14c 100644
--- a/test/Java/Java-1.6.py
+++ b/test/Java/Java-1.6.py
@@ -35,258 +35,17 @@ import TestSCons
_python_ = TestSCons._python_
test = TestSCons.TestSCons()
+test.dir_fixture('java_version_image')
-where_javac, java_version = test.java_where_javac('1.6')
+version = '1.6'
+where_javac, java_version = test.java_where_javac(version)
+javac_path=os.path.dirname(where_javac)
+test.verbose_set(1)
+java_arguments=["--javac_path=%s"%javac_path,"--java_version=%s"%version]
-test.write('SConstruct', """
-env = Environment(tools = ['javac'],
- JAVAVERSION = '1.6',
- JAVAC = r'%(where_javac)s')
-env.Java(target = 'class1', source = 'com/sub/foo')
-env.Java(target = 'class2', source = 'com/sub/bar')
-env.Java(target = 'class3', source = ['src1', 'src2'])
-env.Java(target = 'class4', source = ['src4'])
-env.Java(target = 'class5', source = ['src5'])
-env.Java(target = 'class6', source = ['src6'])
-""" % locals())
-
-test.subdir('com',
- ['com', 'sub'],
- ['com', 'sub', 'foo'],
- ['com', 'sub', 'bar'],
- 'src1',
- 'src2',
- 'src4',
- 'src5',
- 'src6')
-
-test.write(['com', 'sub', 'foo', 'Example1.java'], """\
-package com.sub.foo;
-
-public class Example1
-{
-
- public static void main(String[] args)
- {
-
- }
-
-}
-""")
-
-test.write(['com', 'sub', 'foo', 'Example2.java'], """\
-package com.other;
-
-public class Example2
-{
-
- public static void main(String[] args)
- {
-
- }
-
-}
-""")
-
-test.write(['com', 'sub', 'foo', 'Example3.java'], """\
-package com.sub.foo;
-
-public class Example3
-{
-
- public static void main(String[] args)
- {
-
- }
-
-}
-""")
-
-test.write(['com', 'sub', 'bar', 'Example4.java'], """\
-package com.sub.bar;
-
-public class Example4
-{
-
- public static void main(String[] args)
- {
-
- }
-
-}
-""")
-
-test.write(['com', 'sub', 'bar', 'Example5.java'], """\
-package com.other;
-
-public class Example5
-{
-
- public static void main(String[] args)
- {
-
- }
-
-}
-""")
-
-test.write(['com', 'sub', 'bar', 'Example6.java'], """\
-package com.sub.bar;
-
-public class Example6
-{
-
- public static void main(String[] args)
- {
-
- }
-
-}
-""")
-
-test.write(['src1', 'Example7.java'], """\
-public class Example7
-{
-
- public static void main(String[] args)
- {
-
- }
-
-}
-""")
-
-# Acid-test file for parsing inner Java classes, courtesy Chad Austin.
-test.write(['src2', 'Test.java'], """\
-class Empty {
-}
-
-interface Listener {
- public void execute();
-}
-
-public
-class
-Test {
- class Inner {
- void go() {
- use(new Listener() {
- public void execute() {
- System.out.println("In Inner");
- }
- });
- }
- String s1 = "class A";
- String s2 = "new Listener() { }";
- /* class B */
- /* new Listener() { } */
- }
-
- public static void main(String[] args) {
- new Test().run();
- }
-
- void run() {
- use(new Listener() {
- public void execute() {
- use(new Listener( ) {
- public void execute() {
- System.out.println("Inside execute()");
- }
- });
- }
- });
-
- new Inner().go();
- }
-
- void use(Listener l) {
- l.execute();
- }
-}
-
-class Private {
- void run() {
- new Listener() {
- public void execute() {
- }
- };
- }
-}
-""")
-
-# Testing nested anonymous inner classes, courtesy Brandon Mansfield.
-test.write(['src4', 'NestedExample.java'], """\
-// import java.util.*;
-
-public class NestedExample
-{
- public NestedExample()
- {
- new Thread() {
- public void start()
- {
- new Thread() {
- public void start()
- {
- try {Thread.sleep(200);}
- catch (Exception e) {}
- }
- };
- while (true)
- {
- try {Thread.sleep(200);}
- catch (Exception e) {}
- }
- }
- };
- }
-
-
- public static void main(String argv[])
- {
- new NestedExample();
- }
-}
-""")
-
-# Test not finding an anonymous class when the second token after a
-# "new" is a closing brace. This duplicates a test from the unit tests,
-# but lets us make sure that we correctly determine that everything is
-# up-to-date after the build.
-test.write(['src5', 'TestSCons.java'], """\
-class TestSCons {
- public static void main(String[] args) {
- Foo[] fooArray = new Foo[] { new Foo() };
- }
-}
-
-class Foo { }
-""")
-
-# Test private inner class instantiation, courtesy Tilo Prutz:
-# https://github.com/SCons/scons/issues/1594
-test.write(['src6', 'TestSCons.java'], """\
-class test
-{
- test()
- {
- super();
- new inner();
- }
-
- static class inner
- {
- private inner() {}
- }
-}
-""")
-
-
-
-test.run(arguments = '.')
+test.run(arguments = ['.']+java_arguments)
expect_1 = [
test.workpath('class1', 'com', 'other', 'Example2.class'),
@@ -362,9 +121,10 @@ classes_must_match('class6', expect_6)
test.fail_test(failed)
-test.up_to_date(options='--debug=explain', arguments = '.')
+test.up_to_date(options=["--debug=explain"]+java_arguments,
+ arguments = '.')
-test.run(arguments = '-c .')
+test.run(arguments = ['.']+java_arguments)
classes_must_not_exist('class1', expect_1)
classes_must_not_exist('class2', expect_2)
diff --git a/test/Java/Java-1.8.py b/test/Java/Java-1.8.py
new file mode 100644
index 0000000..a56c1b0
--- /dev/null
+++ b/test/Java/Java-1.8.py
@@ -0,0 +1,149 @@
+#!/usr/bin/env python
+#
+# __COPYRIGHT__
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+
+"""
+Test Java compilation with a live Java 1.6 "javac" compiler.
+"""
+
+import os
+import sys
+
+import TestSCons
+
+_python_ = TestSCons._python_
+
+test = TestSCons.TestSCons()
+test.dir_fixture('java_version_image')
+
+version = '1.8'
+where_javac, java_version = test.java_where_javac(version)
+javac_path=os.path.dirname(where_javac)
+
+test.verbose_set(1)
+
+java_arguments=["--javac_path=%s"%javac_path,"--java_version=%s"%version]
+
+test.run(arguments = ['.']+java_arguments)
+
+expect_1 = [
+ test.workpath('class1', 'com', 'other', 'Example2.class'),
+ test.workpath('class1', 'com', 'sub', 'foo', 'Example1.class'),
+ test.workpath('class1', 'com', 'sub', 'foo', 'Example3.class'),
+]
+
+expect_2 = [
+ test.workpath('class2', 'com', 'other', 'Example5.class'),
+ test.workpath('class2', 'com', 'sub', 'bar', 'Example4.class'),
+ test.workpath('class2', 'com', 'sub', 'bar', 'Example6.class'),
+]
+
+expect_3 = [
+ test.workpath('class3', 'Empty.class'),
+ test.workpath('class3', 'Example7.class'),
+ test.workpath('class3', 'Listener.class'),
+ test.workpath('class3', 'Private$1.class'),
+ test.workpath('class3', 'Private.class'),
+ test.workpath('class3', 'Test$1$1.class'),
+ test.workpath('class3', 'Test$1.class'),
+ test.workpath('class3', 'Test$Inner$1.class'),
+ test.workpath('class3', 'Test$Inner.class'),
+ test.workpath('class3', 'Test.class'),
+]
+
+expect_4 = [
+ test.workpath('class4', 'NestedExample$1$1.class'),
+ test.workpath('class4', 'NestedExample$1.class'),
+ test.workpath('class4', 'NestedExample.class'),
+]
+
+expect_5 = [
+ test.workpath('class5', 'Foo.class'),
+ test.workpath('class5', 'TestSCons.class'),
+]
+
+expect_6 = [
+ test.workpath('class6', 'test$1.class'),
+ test.workpath('class6', 'test$inner.class'),
+ test.workpath('class6', 'test.class'),
+]
+
+failed = None
+
+def classes_must_match(dir, expect):
+ global failed
+ got = test.java_get_class_files(test.workpath(dir))
+ if expect != got:
+ sys.stderr.write("Expected the following class files in '%s':\n" % dir)
+ for c in expect:
+ sys.stderr.write(' %s\n' % c)
+ sys.stderr.write("Got the following class files in '%s':\n" % dir)
+ for c in got:
+ sys.stderr.write(' %s\n' % c)
+ failed = 1
+
+def classes_must_not_exist(dir, expect):
+ global failed
+ present = [path for path in expect if os.path.exists(path)]
+ if present:
+ sys.stderr.write("Found the following unexpected class files in '%s' after cleaning:\n" % dir)
+ for c in present:
+ sys.stderr.write(' %s\n' % c)
+ failed = 1
+
+classes_must_match('class1', expect_1)
+classes_must_match('class2', expect_2)
+classes_must_match('class3', expect_3)
+classes_must_match('class4', expect_4)
+classes_must_match('class5', expect_5)
+classes_must_match('class6', expect_6)
+
+test.fail_test(failed)
+
+test.up_to_date(options=["--debug=explain"]+java_arguments,
+ arguments = '.')
+
+test.run(arguments = ['.']+java_arguments)
+
+classes_must_not_exist('class1', expect_1)
+classes_must_not_exist('class2', expect_2)
+classes_must_not_exist('class3', expect_3)
+classes_must_not_exist('class4', expect_4)
+classes_must_not_exist('class5', expect_5)
+# This test case should pass, but doesn't.
+# The expect_6 list contains the class files that the Java compiler
+# actually creates, apparently because of the "private" instantiation
+# of the "inner" class. Our parser doesn't currently detect this, so
+# it doesn't know to remove that generated class file.
+#classes_must_not_exist('class6', expect_6)
+
+test.fail_test(failed)
+
+test.pass_test()
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/test/Java/java_version_image/SConstruct b/test/Java/java_version_image/SConstruct
new file mode 100644
index 0000000..6e3b11b
--- /dev/null
+++ b/test/Java/java_version_image/SConstruct
@@ -0,0 +1,33 @@
+
+AddOption('--javac_path',
+ dest='javac_path',
+ action='store',
+ default='/usr/bin',
+ type='string')
+
+AddOption('--java_version',
+ dest='java_version',
+ action='store',
+ default='1.6',
+ type='string')
+
+path=GetOption('javac_path')
+
+version = GetOption('java_version')
+
+env = Environment(tools = ['javac'],
+ JAVAVERSION = version,
+ )
+
+
+env.AppendENVPath('PATH',path)
+
+# print('PATH:%s'%env['ENV']['PATH'])
+
+
+env.Java(target = 'class1', source = 'com/sub/foo')
+env.Java(target = 'class2', source = 'com/sub/bar')
+env.Java(target = 'class3', source = ['src1', 'src2'])
+env.Java(target = 'class4', source = ['src4'])
+env.Java(target = 'class5', source = ['src5'])
+env.Java(target = 'class6', source = ['src6'])
diff --git a/test/Java/java_version_image/class6/test$1.class b/test/Java/java_version_image/class6/test$1.class
new file mode 100644
index 0000000..dd58d98
--- /dev/null
+++ b/test/Java/java_version_image/class6/test$1.class
Binary files differ
diff --git a/test/Java/java_version_image/com/sub/bar/Example4.java b/test/Java/java_version_image/com/sub/bar/Example4.java
new file mode 100644
index 0000000..0748d54
--- /dev/null
+++ b/test/Java/java_version_image/com/sub/bar/Example4.java
@@ -0,0 +1,11 @@
+package com.sub.bar;
+
+public class Example4
+{
+
+ public static void main(String[] args)
+ {
+
+ }
+
+}
diff --git a/test/Java/java_version_image/com/sub/bar/Example5.java b/test/Java/java_version_image/com/sub/bar/Example5.java
new file mode 100644
index 0000000..69d2937
--- /dev/null
+++ b/test/Java/java_version_image/com/sub/bar/Example5.java
@@ -0,0 +1,11 @@
+package com.other;
+
+public class Example5
+{
+
+ public static void main(String[] args)
+ {
+
+ }
+
+}
diff --git a/test/Java/java_version_image/com/sub/bar/Example6.java b/test/Java/java_version_image/com/sub/bar/Example6.java
new file mode 100644
index 0000000..1811b80
--- /dev/null
+++ b/test/Java/java_version_image/com/sub/bar/Example6.java
@@ -0,0 +1,11 @@
+package com.sub.bar;
+
+public class Example6
+{
+
+ public static void main(String[] args)
+ {
+
+ }
+
+}
diff --git a/test/Java/java_version_image/com/sub/foo/Example1.java b/test/Java/java_version_image/com/sub/foo/Example1.java
new file mode 100644
index 0000000..82aac2e
--- /dev/null
+++ b/test/Java/java_version_image/com/sub/foo/Example1.java
@@ -0,0 +1,11 @@
+package com.sub.foo;
+
+public class Example1
+{
+
+ public static void main(String[] args)
+ {
+
+ }
+
+}
diff --git a/test/Java/java_version_image/com/sub/foo/Example2.java b/test/Java/java_version_image/com/sub/foo/Example2.java
new file mode 100644
index 0000000..6349ac9
--- /dev/null
+++ b/test/Java/java_version_image/com/sub/foo/Example2.java
@@ -0,0 +1,11 @@
+package com.other;
+
+public class Example2
+{
+
+ public static void main(String[] args)
+ {
+
+ }
+
+}
diff --git a/test/Java/java_version_image/com/sub/foo/Example3.java b/test/Java/java_version_image/com/sub/foo/Example3.java
new file mode 100644
index 0000000..092f0cd
--- /dev/null
+++ b/test/Java/java_version_image/com/sub/foo/Example3.java
@@ -0,0 +1,11 @@
+package com.sub.foo;
+
+public class Example3
+{
+
+ public static void main(String[] args)
+ {
+
+ }
+
+}
diff --git a/test/Java/java_version_image/src1/Example7.java b/test/Java/java_version_image/src1/Example7.java
new file mode 100644
index 0000000..80d94f2
--- /dev/null
+++ b/test/Java/java_version_image/src1/Example7.java
@@ -0,0 +1,9 @@
+public class Example7
+{
+
+ public static void main(String[] args)
+ {
+
+ }
+
+}
diff --git a/test/Java/java_version_image/src2/Test.java b/test/Java/java_version_image/src2/Test.java
new file mode 100644
index 0000000..6f224b0
--- /dev/null
+++ b/test/Java/java_version_image/src2/Test.java
@@ -0,0 +1,55 @@
+class Empty {
+}
+
+interface Listener {
+ public void execute();
+}
+
+public
+class
+Test {
+ class Inner {
+ void go() {
+ use(new Listener() {
+ public void execute() {
+ System.out.println("In Inner");
+ }
+ });
+ }
+ String s1 = "class A";
+ String s2 = "new Listener() { }";
+ /* class B */
+ /* new Listener() { } */
+ }
+
+ public static void main(String[] args) {
+ new Test().run();
+ }
+
+ void run() {
+ use(new Listener() {
+ public void execute() {
+ use(new Listener( ) {
+ public void execute() {
+ System.out.println("Inside execute()");
+ }
+ });
+ }
+ });
+
+ new Inner().go();
+ }
+
+ void use(Listener l) {
+ l.execute();
+ }
+}
+
+class Private {
+ void run() {
+ new Listener() {
+ public void execute() {
+ }
+ };
+ }
+}
diff --git a/test/Java/java_version_image/src4/NestedExample.java b/test/Java/java_version_image/src4/NestedExample.java
new file mode 100644
index 0000000..531f2e9
--- /dev/null
+++ b/test/Java/java_version_image/src4/NestedExample.java
@@ -0,0 +1,31 @@
+// import java.util.*;
+
+public class NestedExample
+{
+ public NestedExample()
+ {
+ new Thread() {
+ public void start()
+ {
+ new Thread() {
+ public void start()
+ {
+ try {Thread.sleep(200);}
+ catch (Exception e) {}
+ }
+ };
+ while (true)
+ {
+ try {Thread.sleep(200);}
+ catch (Exception e) {}
+ }
+ }
+ };
+ }
+
+
+ public static void main(String argv[])
+ {
+ new NestedExample();
+ }
+}
diff --git a/test/Java/java_version_image/src5/TestSCons.java b/test/Java/java_version_image/src5/TestSCons.java
new file mode 100644
index 0000000..46572c4
--- /dev/null
+++ b/test/Java/java_version_image/src5/TestSCons.java
@@ -0,0 +1,7 @@
+class TestSCons {
+ public static void main(String[] args) {
+ Foo[] fooArray = new Foo[] { new Foo() };
+ }
+}
+
+class Foo { }
diff --git a/test/Java/java_version_image/src6/TestSCons.java b/test/Java/java_version_image/src6/TestSCons.java
new file mode 100644
index 0000000..1aeed2f
--- /dev/null
+++ b/test/Java/java_version_image/src6/TestSCons.java
@@ -0,0 +1,13 @@
+class test
+{
+ test()
+ {
+ super();
+ new inner();
+ }
+
+ static class inner
+ {
+ private inner() {}
+ }
+}