diff options
author | Gary Oberbrunner <garyo@oberbrunner.com> | 2014-08-23 20:28:44 (GMT) |
---|---|---|
committer | Gary Oberbrunner <garyo@oberbrunner.com> | 2014-08-23 20:28:44 (GMT) |
commit | a7d764ed831fa3243aa0bd3307f641e1e1f9f8a8 (patch) | |
tree | 0193d9406107790a66098254869e4b070aa6cacc /test/Java | |
parent | a6ea2d760464092ea91a0dd01ba6260288aa3587 (diff) | |
parent | 6db60dbe1c3dc28f24bfca48135bcb4bc9bd66d6 (diff) | |
download | SCons-a7d764ed831fa3243aa0bd3307f641e1e1f9f8a8.zip SCons-a7d764ed831fa3243aa0bd3307f641e1e1f9f8a8.tar.gz SCons-a7d764ed831fa3243aa0bd3307f641e1e1f9f8a8.tar.bz2 |
Merged default branch into python3-port to keep it up to date.
Hand-updated a few things to keep them python3-safe, and handled
several merge conflicts.
Diffstat (limited to 'test/Java')
-rw-r--r-- | test/Java/DerivedSourceTest.py | 124 | ||||
-rw-r--r-- | test/Java/RMIC.py | 89 |
2 files changed, 177 insertions, 36 deletions
diff --git a/test/Java/DerivedSourceTest.py b/test/Java/DerivedSourceTest.py new file mode 100644 index 0000000..c749cf3 --- /dev/null +++ b/test/Java/DerivedSourceTest.py @@ -0,0 +1,124 @@ +#!/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 of javac.py when building java code from derived sources. + +Original issue definition: +Java emitter for derived sources outputs bogus class files. + +Repeatable with any N-tier, with N > 1, Java derived-source builds where +any of the following conditions are meet: +1. The java class does not belong to the root package. +2. A java source (*.java) creates N targets (*.class) where N > 1. +""" + +import os +import TestSCons +import SCons.Node.FS +import SCons.Defaults + +SCons.Defaults.DefaultEnvironment(tools = []) + +test = TestSCons.TestSCons() + +# No result if tools not available +test.no_result( condition=(test.where_is( 'javac' ) is None) ) +test.no_result( condition=(test.where_is( 'jar' ) is None) ) + +# This test is known to fail as of July 2014; see Tigris issue 1771 and issue 2931. +# Once the underlying issue is corrected, this test should be re-enabled. +test.skip_test('Skipping derived-source test until issue 1771 is fixed.\n') + +test.write( + ['Sample.java'], +""" +// Condition 1: class does not exist in the root package. +package org.sample; + +public class Sample { + // Condition 2: inner class definition causes javac to create + // a second class file. + enum InnerEnum { + stuff, + and, + things + } +} +""" +) + +test.write( + ['SConstruct'], +""" +import os + +env = Environment( + tools = [ + 'javac', + 'jar', + ] +) + +env.Command( + os.path.join( 'org', 'sample', 'Sample.java' ), + 'Sample.java', + Copy( + '$TARGET', + '$SOURCE' + ) +) + +# Copy operation makes the *.java file(s) under org derived-source. +env.Java( + 'build', + 'org' +) +""" +) + +expected = test.wrap_stdout( +build_str = +'''\ +Copy("org/sample/Sample.java", "Sample.java") +javac -d build -sourcepath org/sample org/sample/Sample.java ++-. + +-build + | +-build/org + | +-build/org/sample + | +-build/org/sample/Sample$InnerEnum.class + | +-org/sample/Sample.java + | +-build/org/sample/Sample.class + | +-org/sample/Sample.java + +-org + +-org/sample + +-org/sample/Sample.java +'''.replace( '/', os.sep ) +) + +test.run( arguments = '--tree=derived', stdout = expected ) + +test.up_to_date(arguments = '.') diff --git a/test/Java/RMIC.py b/test/Java/RMIC.py index f88dd14..876ed80 100644 --- a/test/Java/RMIC.py +++ b/test/Java/RMIC.py @@ -94,14 +94,31 @@ line 3 where_javac, java_version = test.java_where_javac() where_rmic = test.java_where_rmic() -test.write("wrapper.py", """\ +# Try to get the major/minor Java version +curver = (1, 0) +if java_version.count('.') == 1: + # Check Java version + major, minor = java_version.split('.') + try: + curver = (int(major), int(minor)) + except: + pass + +# Check the version of the found Java compiler. +# If it's 1.8 or higher, we skip the further RMIC test +# because we'll get warnings about the deprecated API... +# it's just not state-of-the-art anymore. +# Note, how we allow simple version strings like "5" and +# "6" to successfully pass this test. +if curver < (1, 8): + test.write("wrapper.py", """\ import os import sys open('%s', 'ab').write("wrapper.py %%s\\n" %% " ".join(sys.argv[1:])) os.system(" ".join(sys.argv[1:])) """ % test.workpath('wrapper.out').replace('\\', '\\\\')) -test.write('SConstruct', """ + test.write('SConstruct', """ foo = Environment(tools = ['javac', 'rmic'], JAVAC = r'%(where_javac)s', RMIC = r'%(where_rmic)s') @@ -121,15 +138,15 @@ bar_classes = [c for c in bar_classes if str(c).find('Hello') == -1] bar.RMIC(target = Dir('outdir2'), source = bar_classes) """ % locals() ) -test.subdir('com', - ['com', 'other'], - ['com', 'sub'], - ['com', 'sub', 'foo'], - ['com', 'sub', 'bar'], - 'src3a', - 'src3b') - -test.write(['com', 'sub', 'foo', 'Hello.java'], """\ + test.subdir('com', + ['com', 'other'], + ['com', 'sub'], + ['com', 'sub', 'foo'], + ['com', 'sub', 'bar'], + 'src3a', + 'src3b') + + test.write(['com', 'sub', 'foo', 'Hello.java'], """\ package com.sub.foo; import java.rmi.Remote; @@ -140,7 +157,7 @@ public interface Hello extends Remote { } """) -test.write(['com', 'sub', 'foo', 'Example1.java'], """\ + test.write(['com', 'sub', 'foo', 'Example1.java'], """\ package com.sub.foo; import java.rmi.Naming; @@ -179,7 +196,7 @@ public class Example1 extends UnicastRemoteObject implements Hello { } """) -test.write(['com', 'sub', 'foo', 'Example2.java'], """\ + test.write(['com', 'sub', 'foo', 'Example2.java'], """\ package com.sub.foo; import java.rmi.Naming; @@ -218,7 +235,7 @@ public class Example2 extends UnicastRemoteObject implements Hello { } """) -test.write(['com', 'sub', 'bar', 'Hello.java'], """\ + test.write(['com', 'sub', 'bar', 'Hello.java'], """\ package com.sub.bar; import java.rmi.Remote; @@ -229,7 +246,7 @@ public interface Hello extends Remote { } """) -test.write(['com', 'sub', 'bar', 'Example3.java'], """\ + test.write(['com', 'sub', 'bar', 'Example3.java'], """\ package com.sub.bar; import java.rmi.Naming; @@ -268,7 +285,7 @@ public class Example3 extends UnicastRemoteObject implements Hello { } """) -test.write(['com', 'sub', 'bar', 'Example4.java'], """\ + test.write(['com', 'sub', 'bar', 'Example4.java'], """\ package com.sub.bar; import java.rmi.Naming; @@ -307,26 +324,26 @@ public class Example4 extends UnicastRemoteObject implements Hello { } """) -test.run(arguments = '.') - -test.fail_test(test.read('wrapper.out') != "wrapper.py %s -d outdir2 -classpath class2 com.sub.bar.Example3 com.sub.bar.Example4\n" % where_rmic) - -test.must_exist(test.workpath('outdir1', 'com', 'sub', 'foo', 'Example1_Stub.class')) -test.must_exist(test.workpath('outdir1', 'com', 'sub', 'foo', 'Example2_Stub.class')) -test.must_exist(test.workpath('outdir2', 'com', 'sub', 'bar', 'Example3_Stub.class')) -test.must_exist(test.workpath('outdir2', 'com', 'sub', 'bar', 'Example4_Stub.class')) - -# We used to check for _Skel.class files as well, but they're not -# generated by default starting with Java 1.5, and they apparently -# haven't been needed for a while. Don't bother looking, even if we're -# running Java 1.4. If we think they're needed but they don't exist -# the test.up_to_date() call below will detect it. -#test.must_exist(test.workpath('outdir1', 'com', 'sub', 'foo', 'Example1_Skel.class')) -#test.must_exist(test.workpath('outdir1', 'com', 'sub', 'foo', 'Example2_Skel.class')) -#test.must_exist(test.workpath('outdir2', 'com', 'sub', 'bar', 'Example3_Skel.class')) -#test.must_exist(test.workpath('outdir2', 'com', 'sub', 'bar', 'Example4_Skel.class')) - -test.up_to_date(arguments = '.') + test.run(arguments = '.') + + test.fail_test(test.read('wrapper.out') != "wrapper.py %s -d outdir2 -classpath class2 com.sub.bar.Example3 com.sub.bar.Example4\n" % where_rmic) + + test.must_exist(test.workpath('outdir1', 'com', 'sub', 'foo', 'Example1_Stub.class')) + test.must_exist(test.workpath('outdir1', 'com', 'sub', 'foo', 'Example2_Stub.class')) + test.must_exist(test.workpath('outdir2', 'com', 'sub', 'bar', 'Example3_Stub.class')) + test.must_exist(test.workpath('outdir2', 'com', 'sub', 'bar', 'Example4_Stub.class')) + + # We used to check for _Skel.class files as well, but they're not + # generated by default starting with Java 1.5, and they apparently + # haven't been needed for a while. Don't bother looking, even if we're + # running Java 1.4. If we think they're needed but they don't exist + # the test.up_to_date() call below will detect it. + #test.must_exist(test.workpath('outdir1', 'com', 'sub', 'foo', 'Example1_Skel.class')) + #test.must_exist(test.workpath('outdir1', 'com', 'sub', 'foo', 'Example2_Skel.class')) + #test.must_exist(test.workpath('outdir2', 'com', 'sub', 'bar', 'Example3_Skel.class')) + #test.must_exist(test.workpath('outdir2', 'com', 'sub', 'bar', 'Example4_Skel.class')) + + test.up_to_date(arguments = '.') test.pass_test() |