Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: fa0dbd44f19cb10c26b1b1812243cdf0a7816a01 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
package org.eclipse.jdt.core.tests.compiler.regression;

import java.io.File;

import javax.lang.model.SourceVersion;

import org.eclipse.jdt.core.tests.util.Util;

import junit.framework.Test;

public class MultiReleaseJarTests extends AbstractBatchCompilerTest {

	static {
//		 TESTS_NAMES = new String[] { "test001" };
		// TESTS_NUMBERS = new int[] { 1 };
		// TESTS_RANGE = new int[] { 298, -1 };
	}

	private boolean isJRE10 = false;
	public MultiReleaseJarTests(String name) {
		super(name);
		try {
			SourceVersion valueOf = SourceVersion.valueOf("RELEASE_10");
			if (valueOf != null) this.isJRE10 = true;
		} catch(Exception e) {
			
		}
	}

	public static Test suite() {
		return buildMinimalComplianceTestSuite(testClass(), F_9);
	}

	public static Class<?> testClass() {
		return MultiReleaseJarTests.class;
	}
	public void test001() {
		String path = this.getCompilerTestsPluginDirectoryPath() + File.separator + "workspace" + File.separator + "multi.jar";
		String[] libs = new String[1];
		libs[0] = path;
		runNegativeTest(
			new String[] {
				"src/X.java",
				  "import a.b.c.MultiVersion1.Inner;\n" + 
				  "import p.q.r.MultiVersion2.Inner;\n" + 
				  "public class X {\n" + 
				  "}\n"},
			"\"" + OUTPUT_DIR +  File.separator + "src/X.java\"" +
			" -classpath " + path + " --release 8 ",
			"",
			"----------\n" + 
			"1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/X.java (at line 1)\n" + 
			"	import a.b.c.MultiVersion1.Inner;\n" + 
			"	       ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
			"The import a.b.c.MultiVersion1.Inner cannot be resolved\n" + 
			"----------\n" + 
			"2. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/X.java (at line 2)\n" + 
			"	import p.q.r.MultiVersion2.Inner;\n" + 
			"	       ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
			"The import p.q.r.MultiVersion2.Inner cannot be resolved\n" + 
			"----------\n" + 
			"2 problems (2 errors)\n",
			false
		   );
	}
	public void test002() {
		String path = this.getCompilerTestsPluginDirectoryPath() + File.separator + "workspace" + File.separator + "multi.jar";
		String[] libs = new String[1];
		libs[0] = path;
		runNegativeTest(
			new String[] {
				"src/X.java",
				  "import a.b.c.MultiVersion1.Inner;\n" + 
				  "import p.q.r.MultiVersion2.Inner;\n" + 
				  "public class X {\n" + 
				  "}\n"},
			"\"" + OUTPUT_DIR +  File.separator + "src/X.java\"" +
			" -classpath " + path + " --release 9 ",
			"",
			"----------\n" + 
			"1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/X.java (at line 1)\n" + 
			"	import a.b.c.MultiVersion1.Inner;\n" + 
			"	       ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
			"The type a.b.c.MultiVersion1.Inner is not visible\n" + 
			"----------\n" + 
			"1 problem (1 error)\n",
			false
		   );
	}
	public void test003() {
		String path = this.getCompilerTestsPluginDirectoryPath() + File.separator + "workspace" + File.separator + "multi.jar";
		String[] libs = new String[1];
		libs[0] = path;
		runConformTest(
			new String[] {
				"src/X.java",
				  "import p.q.r.MultiVersion3.Inner;\n" + 
				  "public class X {\n" +
				  "  Inner i = null;\n" +
				  "  p.q.r.MultiVersion2.Inner i2 = null;\n" +
				  "}\n"},
			"\"" + OUTPUT_DIR +  File.separator + "src/X.java\"" +
			" -classpath " + path + " --release 9 ",
			"",
			"",
			false
		   );
	}
	public void test004() {
		String path = this.getCompilerTestsPluginDirectoryPath() + File.separator + "workspace" + File.separator + "multi.jar";
		String[] libs = new String[1];
		libs[0] = path;
		runNegativeTest(
			new String[] {
				"src/X.java",
				  "import p.q.r.MultiVersion3.Inner;\n" + 
				  "import p.q.r.MultiVersion2.Inner;\n" +
				  "public class X {\n" +
				  "  Inner i = null;\n" +
				  "}\n"},
			"\"" + OUTPUT_DIR +  File.separator + "src/X.java\"" +
			" -classpath " + path + " --release 9 ",
			"",
			"----------\n" + 
			"1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/X.java (at line 2)\n" + 
			"	import p.q.r.MultiVersion2.Inner;\n" + 
			"	       ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
			"The import p.q.r.MultiVersion2.Inner collides with another import statement\n" + 
			"----------\n" + 
			"1 problem (1 error)\n",
			false
		   );
	}
	public void test005() {
		Util.flushDirectoryContent(new File(OUTPUT_DIR));
		String path = this.getCompilerTestsPluginDirectoryPath() + File.separator + "workspace" + File.separator + "multi.jar";
		String[] libs = new String[1];
		libs[0] = path;
		File directory = new File(OUTPUT_DIR +  File.separator + "src" + File.separator + "MyModule" );
		File out = new File(OUTPUT_DIR +  File.separator + "out" );
		if (!directory.exists()) {
			if (!directory.mkdirs()) {
				System.out.println("Could not create " + directory.toString());
				return;
			}
		}
		if (!out.exists()) {
			if (!out.mkdirs()) {
				System.out.println("Could not create " + directory.toString());
				return;
			}
		}
		runNegativeTest(
			new String[] {
				"src/MyModule/module-info.java",
				"module MyModule {\n" +
				"  requires Version9;\n" +
				"}",
				"src/MyModule/p/X.java",
				"package p;\n" +
				"public class X {\n" +
				"  java.sql.Connection con = null;\n" +
				"}\n"},
			"  -d \"" + out.toString() + "\" " +
			" --module-source-path \"" + directory.toString() +  "\" " +
			" \"" + OUTPUT_DIR +  File.separator + "src" + File.separator + "MyModule" + File.separator + "module-info.java\"" +
			" \"" + OUTPUT_DIR +  File.separator + "src" + File.separator + "MyModule" + File.separator + "p" + File.separator + "X.java\" "  +
			" --module-path " + path + " --release 9 ",
			"",
			"----------\n" + 
			"1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/MyModule/p/X.java (at line 3)\n" + 
			"	java.sql.Connection con = null;\n" + 
			"	^^^^^^^^^^^^^^^^^^^\n" + 
			"The type java.sql.Connection is not accessible\n" + 
			"----------\n" + 
			"1 problem (1 error)\n",
			false
		   );
	}
	public void test006() {
		if (!this.isJRE10) return;
		String path = this.getCompilerTestsPluginDirectoryPath() + File.separator + "workspace" + File.separator + "multi.jar";
		String[] libs = new String[1];
		libs[0] = path;
		File directory = new File(OUTPUT_DIR +  File.separator + "src" + File.separator + "MyModule" );
		File out = new File(OUTPUT_DIR +  File.separator + "out" );
		if (!directory.exists()) {
			if (!directory.mkdirs()) {
				System.out.println("Could not create " + directory.toString());
				return;
			}
		}
		if (!out.exists()) {
			if (!directory.mkdirs()) {
				System.out.println("Could not create " + directory.toString());
				return;
			}
		}
		runConformTest(
			new String[] {
				"src/MyModule/module-info.java",
				"module MyModule {\n" +
				"  requires Version10;\n" +
				"}",
				"src/MyModule/p/X.java",
				"package p;\n" +
				"public class X {\n" +
				"  java.sql.Connection con = null;\n" +
				"}\n"},
			"  -d \"" + out.toString() + "\" " +
			" --module-source-path \"" + directory.toString() +  "\" " +
			" \"" + OUTPUT_DIR +  File.separator + "src" + File.separator + "MyModule" + File.separator + "module-info.java\"" +
			" \"" + OUTPUT_DIR +  File.separator + "src" + File.separator + "MyModule" + File.separator + "p" + File.separator + "X.java\" "  +
			" --module-path " + path + " --release 10 ",
			"",
			"",
			false
		   );
	}
}

Back to the top