added release.txt blurb. Fixed spelling typo in Defaults.xml
[scons.git] / test / Java / Java-1.8.py
blob4e54208423e26a4ffc71ea35622376c4141b61d2
1 #!/usr/bin/env python
3 # MIT License
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.
26 """
27 Test Java compilation with a live Java 1.8 "javac" compiler.
28 """
30 import os
31 import sys
33 import TestSCons
35 _python_ = TestSCons._python_
37 test = TestSCons.TestSCons()
38 test.dir_fixture('java_version_image')
40 version = '1.8'
41 where_javac, java_version = test.java_where_javac(version)
42 javac_path=os.path.dirname(where_javac)
44 if ' ' in javac_path:
45 javac_path ='"%s"'%javac_path
46 java_arguments=["--javac_path=%s"%javac_path,"--java_version=%s"%version]
48 test.run(arguments = ['.']+java_arguments)
50 expect_1 = [
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'),
56 expect_2 = [
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'),
62 expect_3 = [
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'),
75 expect_4 = [
76 test.workpath('class4', 'NestedExample$1$1.class'),
77 test.workpath('class4', 'NestedExample$1.class'),
78 test.workpath('class4', 'NestedExample.class'),
81 expect_5 = [
82 test.workpath('class5', 'Foo.class'),
83 test.workpath('class5', 'TestSCons.class'),
86 expect_6 = [
87 test.workpath('class6', 'test$1.class'),
88 test.workpath('class6', 'test$inner.class'),
89 test.workpath('class6', 'test.class'),
92 failed = None
94 def classes_must_match(dir, expect):
95 global failed
96 got = test.java_get_class_files(test.workpath(dir))
97 if expect != got:
98 sys.stderr.write("Expected the following class files in '%s':\n" % dir)
99 for c in expect:
100 sys.stderr.write(' %s\n' % c)
101 sys.stderr.write("Got the following class files in '%s':\n" % dir)
102 for c in got:
103 sys.stderr.write(' %s\n' % c)
104 failed = 1
106 def classes_must_not_exist(dir, expect):
107 global failed
108 present = [path for path in expect if os.path.exists(path)]
109 if present:
110 sys.stderr.write("Found the following unexpected class files in '%s' after cleaning:\n" % dir)
111 for c in present:
112 sys.stderr.write(' %s\n' % c)
113 failed = 1
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,
125 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)
143 test.pass_test()
145 # Local Variables:
146 # tab-width:4
147 # indent-tabs-mode:nil
148 # End:
149 # vim: set expandtab tabstop=4 shiftwidth=4: