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.
23 Test Java compilation with a live Java 1.6 "javac" compiler.
31 _python_
= TestSCons
._python
_
33 test
= TestSCons
.TestSCons()
34 test
.dir_fixture('java_version_image')
37 where_javac
, java_version
= test
.java_where_javac(version
)
38 javac_path
=os
.path
.dirname(where_javac
)
41 javac_path
='"%s"'%javac_path
42 java_arguments
=["--javac_path=%s"%javac_path
,"--java_version=%s"%version
]
44 test
.run(arguments
= ['.']+java_arguments
)
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'),
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'),
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'),
72 test
.workpath('class4', 'NestedExample$1$1.class'),
73 test
.workpath('class4', 'NestedExample$1.class'),
74 test
.workpath('class4', 'NestedExample.class'),
78 test
.workpath('class5', 'Foo.class'),
79 test
.workpath('class5', 'TestSCons.class'),
83 test
.workpath('class6', 'test$1.class'),
84 test
.workpath('class6', 'test$inner.class'),
85 test
.workpath('class6', 'test.class'),
90 def classes_must_match(dir, expect
):
92 got
= test
.java_get_class_files(test
.workpath(dir))
94 sys
.stderr
.write("Expected the following class files in '%s':\n" % dir)
96 sys
.stderr
.write(' %s\n' % c
)
97 sys
.stderr
.write("Got the following class files in '%s':\n" % dir)
99 sys
.stderr
.write(' %s\n' % c
)
102 def classes_must_not_exist(dir, expect
):
104 present
= [path
for path
in expect
if os
.path
.exists(path
)]
106 sys
.stderr
.write("Found the following unexpected class files in '%s' after cleaning:\n" % dir)
108 sys
.stderr
.write(' %s\n' % c
)
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
,
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
)
143 # indent-tabs-mode:nil
145 # vim: set expandtab tabstop=4 shiftwidth=4: