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.8 "javac" compiler.
35 _python_
= TestSCons
._python
_
37 test
= TestSCons
.TestSCons()
38 test
.dir_fixture('java_version_image')
41 where_javac
, java_version
= test
.java_where_javac(version
)
42 javac_path
=os
.path
.dirname(where_javac
)
45 javac_path
='"%s"'%javac_path
46 java_arguments
=["--javac_path=%s"%javac_path
,"--java_version=%s"%version
]
48 test
.run(arguments
= ['.']+java_arguments
)
51 test
.workpath('class1', 'com', 'other', 'Example2.class'),
52 test
.workpath('class1', 'com', 'sub', 'foo', 'Example1.class'),
53 test
.workpath('class1', 'com', 'sub', 'foo', 'Example3.class'),
57 test
.workpath('class2', 'com', 'other', 'Example5.class'),
58 test
.workpath('class2', 'com', 'sub', 'bar', 'Example4.class'),
59 test
.workpath('class2', 'com', 'sub', 'bar', 'Example6.class'),
63 test
.workpath('class3', 'Empty.class'),
64 test
.workpath('class3', 'Example7.class'),
65 test
.workpath('class3', 'Listener.class'),
66 test
.workpath('class3', 'Private$1.class'),
67 test
.workpath('class3', 'Private.class'),
68 test
.workpath('class3', 'Test$1$1.class'),
69 test
.workpath('class3', 'Test$1.class'),
70 test
.workpath('class3', 'Test$Inner$1.class'),
71 test
.workpath('class3', 'Test$Inner.class'),
72 test
.workpath('class3', 'Test.class'),
76 test
.workpath('class4', 'NestedExample$1$1.class'),
77 test
.workpath('class4', 'NestedExample$1.class'),
78 test
.workpath('class4', 'NestedExample.class'),
82 test
.workpath('class5', 'Foo.class'),
83 test
.workpath('class5', 'TestSCons.class'),
87 test
.workpath('class6', 'test$1.class'),
88 test
.workpath('class6', 'test$inner.class'),
89 test
.workpath('class6', 'test.class'),
94 def classes_must_match(dir, expect
):
96 got
= test
.java_get_class_files(test
.workpath(dir))
98 sys
.stderr
.write("Expected the following class files in '%s':\n" % dir)
100 sys
.stderr
.write(' %s\n' % c
)
101 sys
.stderr
.write("Got the following class files in '%s':\n" % dir)
103 sys
.stderr
.write(' %s\n' % c
)
106 def classes_must_not_exist(dir, expect
):
108 present
= [path
for path
in expect
if os
.path
.exists(path
)]
110 sys
.stderr
.write("Found the following unexpected class files in '%s' after cleaning:\n" % dir)
112 sys
.stderr
.write(' %s\n' % c
)
115 classes_must_match('class1', expect_1
)
116 classes_must_match('class2', expect_2
)
117 classes_must_match('class3', expect_3
)
118 classes_must_match('class4', expect_4
)
119 classes_must_match('class5', expect_5
)
120 classes_must_match('class6', expect_6
)
122 test
.fail_test(failed
)
124 test
.up_to_date(options
=["--debug=explain"]+java_arguments
,
127 test
.run(arguments
= ['-c','.']+java_arguments
)
129 classes_must_not_exist('class1', expect_1
)
130 classes_must_not_exist('class2', expect_2
)
131 classes_must_not_exist('class3', expect_3
)
132 classes_must_not_exist('class4', expect_4
)
133 classes_must_not_exist('class5', expect_5
)
134 # This test case should pass, but doesn't.
135 # The expect_6 list contains the class files that the Java compiler
136 # actually creates, apparently because of the "private" instantiation
137 # of the "inner" class. Our parser doesn't currently detect this, so
138 # it doesn't know to remove that generated class file.
139 #classes_must_not_exist('class6', expect_6)
141 test
.fail_test(failed
)
147 # indent-tabs-mode:nil
149 # vim: set expandtab tabstop=4 shiftwidth=4: