[ci skip] update generated files
[scons.git] / test / Java / Java-1.6.py
blobc759e87b5467687403027c5da5d46cab9b426f1f
1 #!/usr/bin/env python
3 # Permission is hereby granted, free of charge, to any person obtaining
4 # a copy of this software and associated documentation files (the
5 # "Software"), to deal in the Software without restriction, including
6 # without limitation the rights to use, copy, modify, merge, publish,
7 # distribute, sublicense, and/or sell copies of the Software, and to
8 # permit persons to whom the Software is furnished to do so, subject to
9 # the following conditions:
11 # The above copyright notice and this permission notice shall be included
12 # in all copies or substantial portions of the Software.
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
15 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
16 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 """
23 Test Java compilation with a live Java 1.6 "javac" compiler.
24 """
26 import os
27 import sys
29 import TestSCons
31 _python_ = TestSCons._python_
33 test = TestSCons.TestSCons()
34 test.dir_fixture('java_version_image')
36 version = '1.6'
37 where_javac, java_version = test.java_where_javac(version)
38 javac_path=os.path.dirname(where_javac)
40 if ' ' in javac_path:
41 javac_path ='"%s"'%javac_path
42 java_arguments=["--javac_path=%s"%javac_path,"--java_version=%s"%version]
44 test.run(arguments = ['.']+java_arguments)
46 expect_1 = [
47 test.workpath('class1', 'com', 'other', 'Example2.class'),
48 test.workpath('class1', 'com', 'sub', 'foo', 'Example1.class'),
49 test.workpath('class1', 'com', 'sub', 'foo', 'Example3.class'),
52 expect_2 = [
53 test.workpath('class2', 'com', 'other', 'Example5.class'),
54 test.workpath('class2', 'com', 'sub', 'bar', 'Example4.class'),
55 test.workpath('class2', 'com', 'sub', 'bar', 'Example6.class'),
58 expect_3 = [
59 test.workpath('class3', 'Empty.class'),
60 test.workpath('class3', 'Example7.class'),
61 test.workpath('class3', 'Listener.class'),
62 test.workpath('class3', 'Private$1.class'),
63 test.workpath('class3', 'Private.class'),
64 test.workpath('class3', 'Test$1$1.class'),
65 test.workpath('class3', 'Test$1.class'),
66 test.workpath('class3', 'Test$Inner$1.class'),
67 test.workpath('class3', 'Test$Inner.class'),
68 test.workpath('class3', 'Test.class'),
71 expect_4 = [
72 test.workpath('class4', 'NestedExample$1$1.class'),
73 test.workpath('class4', 'NestedExample$1.class'),
74 test.workpath('class4', 'NestedExample.class'),
77 expect_5 = [
78 test.workpath('class5', 'Foo.class'),
79 test.workpath('class5', 'TestSCons.class'),
82 expect_6 = [
83 test.workpath('class6', 'test$1.class'),
84 test.workpath('class6', 'test$inner.class'),
85 test.workpath('class6', 'test.class'),
88 failed = None
90 def classes_must_match(dir, expect):
91 global failed
92 got = test.java_get_class_files(test.workpath(dir))
93 if expect != got:
94 sys.stderr.write("Expected the following class files in '%s':\n" % dir)
95 for c in expect:
96 sys.stderr.write(' %s\n' % c)
97 sys.stderr.write("Got the following class files in '%s':\n" % dir)
98 for c in got:
99 sys.stderr.write(' %s\n' % c)
100 failed = 1
102 def classes_must_not_exist(dir, expect):
103 global failed
104 present = [path for path in expect if os.path.exists(path)]
105 if present:
106 sys.stderr.write("Found the following unexpected class files in '%s' after cleaning:\n" % dir)
107 for c in present:
108 sys.stderr.write(' %s\n' % c)
109 failed = 1
111 classes_must_match('class1', expect_1)
112 classes_must_match('class2', expect_2)
113 classes_must_match('class3', expect_3)
114 classes_must_match('class4', expect_4)
115 classes_must_match('class5', expect_5)
116 classes_must_match('class6', expect_6)
118 test.fail_test(failed)
120 test.up_to_date(options=["--debug=explain"]+java_arguments,
121 arguments = '.')
123 test.run(arguments = ['-c','.']+java_arguments)
125 classes_must_not_exist('class1', expect_1)
126 classes_must_not_exist('class2', expect_2)
127 classes_must_not_exist('class3', expect_3)
128 classes_must_not_exist('class4', expect_4)
129 classes_must_not_exist('class5', expect_5)
130 # This test case should pass, but doesn't.
131 # The expect_6 list contains the class files that the Java compiler
132 # actually creates, apparently because of the "private" instantiation
133 # of the "inner" class. Our parser doesn't currently detect this, so
134 # it doesn't know to remove that generated class file.
135 #classes_must_not_exist('class6', expect_6)
137 test.fail_test(failed)
139 test.pass_test()
141 # Local Variables:
142 # tab-width:4
143 # indent-tabs-mode:nil
144 # End:
145 # vim: set expandtab tabstop=4 shiftwidth=4: