5 # Copyright The SCons Foundation
7 # Permission is hereby granted, free of charge, to any person obtaining
8 # a copy of this software and associated documentation files (the
9 # "Software"), to deal in the Software without restriction, including
10 # without limitation the rights to use, copy, modify, merge, publish,
11 # distribute, sublicense, and/or sell copies of the Software, and to
12 # permit persons to whom the Software is furnished to do so, subject to
13 # the following conditions:
15 # The above copyright notice and this permission notice shall be included
16 # in all copies or substantial portions of the Software.
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
19 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 Test Java compilation with a live Java 1.5 "javac" compiler.
35 _python_
= TestSCons
._python
_
37 test
= TestSCons
.TestSCons()
39 where_javac
, java_version
= test
.java_where_javac('1.5')
43 test
.write('SConstruct', """
44 env = Environment(tools = ['javac'],
46 JAVAC = r'%(where_javac)s')
47 env.Java(target = 'class1', source = 'com/sub/foo')
48 env.Java(target = 'class2', source = 'com/sub/bar')
49 env.Java(target = 'class3', source = ['src1', 'src2'])
50 env.Java(target = 'class4', source = ['src4'])
51 env.Java(target = 'class5', source = ['src5'])
52 env.Java(target = 'class6', source = ['src6'])
57 ['com', 'sub', 'foo'],
58 ['com', 'sub', 'bar'],
65 test
.write(['com', 'sub', 'foo', 'Example1.java'], """\
71 public static void main(String[] args)
79 test
.write(['com', 'sub', 'foo', 'Example2.java'], """\
85 public static void main(String[] args)
93 test
.write(['com', 'sub', 'foo', 'Example3.java'], """\
99 public static void main(String[] args)
107 test
.write(['com', 'sub', 'bar', 'Example4.java'], """\
110 public class Example4
113 public static void main(String[] args)
121 test
.write(['com', 'sub', 'bar', 'Example5.java'], """\
124 public class Example5
127 public static void main(String[] args)
135 test
.write(['com', 'sub', 'bar', 'Example6.java'], """\
138 public class Example6
141 public static void main(String[] args)
149 test
.write(['src1', 'Example7.java'], """\
150 public class Example7
153 public static void main(String[] args)
161 # Acid-test file for parsing inner Java classes, courtesy Chad Austin.
162 test
.write(['src2', 'Test.java'], """\
167 public void execute();
176 public void execute() {
177 System.out.println("In Inner");
181 String s1 = "class A";
182 String s2 = "new Listener() { }";
184 /* new Listener() { } */
187 public static void main(String[] args) {
193 public void execute() {
194 use(new Listener( ) {
195 public void execute() {
196 System.out.println("Inside execute()");
205 void use(Listener l) {
213 public void execute() {
220 # Testing nested anonymous inner classes, courtesy Brandon Mansfield.
221 test
.write(['src4', 'NestedExample.java'], """\
222 // import java.util.*;
224 public class NestedExample
226 public NestedExample()
234 try {Thread.sleep(200);}
235 catch (Exception e) {}
240 try {Thread.sleep(200);}
241 catch (Exception e) {}
248 public static void main(String argv[])
255 # Test not finding an anonymous class when the second token after a
256 # "new" is a closing brace. This duplicates a test from the unit tests,
257 # but lets us make sure that we correctly determine that everything is
258 # up-to-date after the build.
259 test
.write(['src5', 'TestSCons.java'], """\
261 public static void main(String[] args) {
262 Foo[] fooArray = new Foo[] { new Foo() };
269 # Test private inner class instantiation, courtesy Tilo Prutz:
270 # https://github.com/SCons/scons/issues/1594
271 test
.write(['src6', 'TestSCons.java'], """\
289 test
.run(arguments
= '.')
292 test
.workpath('class1', 'com', 'other', 'Example2.class'),
293 test
.workpath('class1', 'com', 'sub', 'foo', 'Example1.class'),
294 test
.workpath('class1', 'com', 'sub', 'foo', 'Example3.class'),
298 test
.workpath('class2', 'com', 'other', 'Example5.class'),
299 test
.workpath('class2', 'com', 'sub', 'bar', 'Example4.class'),
300 test
.workpath('class2', 'com', 'sub', 'bar', 'Example6.class'),
304 test
.workpath('class3', 'Empty.class'),
305 test
.workpath('class3', 'Example7.class'),
306 test
.workpath('class3', 'Listener.class'),
307 test
.workpath('class3', 'Private$1.class'),
308 test
.workpath('class3', 'Private.class'),
309 test
.workpath('class3', 'Test$1$1.class'),
310 test
.workpath('class3', 'Test$1.class'),
311 test
.workpath('class3', 'Test$Inner$1.class'),
312 test
.workpath('class3', 'Test$Inner.class'),
313 test
.workpath('class3', 'Test.class'),
317 test
.workpath('class4', 'NestedExample$1$1.class'),
318 test
.workpath('class4', 'NestedExample$1.class'),
319 test
.workpath('class4', 'NestedExample.class'),
323 test
.workpath('class5', 'Foo.class'),
324 test
.workpath('class5', 'TestSCons.class'),
328 test
.workpath('class6', 'test$1.class'),
329 test
.workpath('class6', 'test$inner.class'),
330 test
.workpath('class6', 'test.class'),
335 def classes_must_match(dir, expect
):
337 got
= test
.java_get_class_files(test
.workpath(dir))
339 sys
.stderr
.write("Expected the following class files in '%s':\n" % dir)
341 sys
.stderr
.write(' %s\n' % c
)
342 sys
.stderr
.write("Got the following class files in '%s':\n" % dir)
344 sys
.stderr
.write(' %s\n' % c
)
347 def classes_must_not_exist(dir, expect
):
349 present
= [path
for path
in expect
if os
.path
.exists(path
)]
351 sys
.stderr
.write("Found the following unexpected class files in '%s' after cleaning:\n" % dir)
353 sys
.stderr
.write(' %s\n' % c
)
356 classes_must_match('class1', expect_1
)
357 classes_must_match('class2', expect_2
)
358 classes_must_match('class3', expect_3
)
359 classes_must_match('class4', expect_4
)
360 classes_must_match('class5', expect_5
)
361 classes_must_match('class6', expect_6
)
363 test
.fail_test(failed
)
365 test
.up_to_date(options
='--debug=explain', arguments
= '.')
367 test
.run(arguments
= '-c .')
369 classes_must_not_exist('class1', expect_1
)
370 classes_must_not_exist('class2', expect_2
)
371 classes_must_not_exist('class3', expect_3
)
372 classes_must_not_exist('class4', expect_4
)
373 classes_must_not_exist('class5', expect_5
)
374 # This test case should pass, but doesn't.
375 # The expect_6 list contains the class files that the Java compiler
376 # actually creates, apparently because of the "private" instantiation
377 # of the "inner" class. Our parser doesn't currently detect this, so
378 # it doesn't know to remove that generated class file.
379 #classes_must_not_exist('class6', expect_6)
381 test
.fail_test(failed
)
387 # indent-tabs-mode:nil
389 # vim: set expandtab tabstop=4 shiftwidth=4: