Skip to content

Commit

Permalink
Further test cleanup for issues reported by Stephan
Browse files Browse the repository at this point in the history
  • Loading branch information
iloveeclipse committed Jul 22, 2024
1 parent 71c64bf commit c94a550
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 369 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.tests.util.Util;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;

/**
* Basic tests of {@link JavaCore#getGeneratedResources(IRegion, boolean)}.
Expand Down Expand Up @@ -399,174 +398,6 @@ public void test005() throws JavaModelException {
env.removeProject(projectPath);
}

//https://bugs.eclipse.org/bugs/show_bug.cgi?id=6584
public void test006() throws JavaModelException {
IPath projectPath = null;
try {
projectPath = env.addProject("Project", CompilerOptions.getFirstSupportedJavaVersion()); //$NON-NLS-1$
} catch (RuntimeException e) {
// no 1.5 VM or above is available
return;
}
env.addExternalJars(projectPath, Util.getJavaClassLibs());
fullBuild(projectPath);

// remove old package fragment root so that names don't collide
env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$

IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$
env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$

env.addClass(root, "a", "Anon", //$NON-NLS-1$ //$NON-NLS-2$
"package a;\n" +
"\n" +
"public class Anon {\n" +
"\n" +
" Anon() {\n" +
" Object o1 = new Object() {\n" +
" public String toString() {\n" +
" return \"1\"; // a/Anon$3 in 1.5, a/Anon$11 in 1.4\n" +
" }\n" +
" };\n" +
" Object o2 = new Object() {\n" +
" public String toString() {\n" +
" return \"2\"; // a/Anon$4 in 1.5, a/Anon$12 in 1.4\n" +
" }\n" +
" };\n" +
" }\n" +
"\n" +
" void hello() {\n" +
" Object o3 = new Object() {\n" +
" public String toString() {\n" +
" return \"3\"; // a/Anon$5 in 1.5, a/Anon$13 in 1.4\n" +
" }\n" +
" };\n" +
" Object o4 = new Object() {\n" +
" public String toString() {\n" +
" return \"4\"; // a/Anon$6 in 1.5, a/Anon$14 in 1.4\n" +
" }\n" +
" };\n" +
" }\n" +
"\n" +
" static void hello2() {\n" +
" Object o5 = new Object() {\n" +
" public String toString() {\n" +
" return \"5\"; // a/Anon$7 in 1.5, a/Anon$15 in 1.4\n" +
" }\n" +
" };\n" +
" Object o6 = new Object() {\n" +
" public String toString() {\n" +
" return \"6\"; // a/Anon$8 in 1.5, a/Anon$16 in 1.4\n" +
" }\n" +
" };\n" +
" }\n" +
"\n" +
" static {\n" +
" Object o7 = new Object() {\n" +
" public String toString() {\n" +
" return \"7\"; // a/Anon$1 in 1.5, a/Anon$1 in 1.4\n" +
" }\n" +
" };\n" +
"\n" +
" Object o8 = new Object() {\n" +
" public String toString() {\n" +
" return \"8\"; // a/Anon$2 in 1.5, a/Anon$2 in 1.4\n" +
" }\n" +
" };\n" +
" }\n" +
"\n" +
" static class Anon2 {\n" +
" // it\'s an object init block which has different prio as constructor!\n" +
" {\n" +
" Object o1 = new Object() {\n" +
" public String toString() {\n" +
" return \"1\"; // a/Anon$Anon2$1 in 1.5, a/Anon$3 in 1.4\n" +
" }\n" +
" };\n" +
" Object o2 = new Object() {\n" +
" public String toString() {\n" +
" return \"2\"; // a/Anon$Anon2$2 in 1.5, a/Anon$4 in 1.4\n" +
" }\n" +
" };\n" +
" }\n" +
"\n" +
" void hello() {\n" +
" Object o3 = new Object() {\n" +
" public String toString() {\n" +
" return \"3\"; // a/Anon$Anon2$5 in 1.5, a/Anon$7 in 1.4\n" +
" }\n" +
" };\n" +
" Object o4 = new Object() {\n" +
" public String toString() {\n" +
" return \"4\"; // a/Anon$Anon2$6 in 1.5, a/Anon$8 in 1.4\n" +
" }\n" +
" };\n" +
" }\n" +
"\n" +
" static void hello2() {\n" +
" Object o5 = new Object() {\n" +
" public String toString() {\n" +
" return \"5\"; // a/Anon$Anon2$7 in 1.5, a/Anon$9 in 1.4\n" +
" }\n" +
" };\n" +
" Object o6 = new Object() {\n" +
" public String toString() {\n" +
" return \"6\"; // a/Anon$Anon2$8 in 1.5, a/Anon$10 in 1.4\n" +
" }\n" +
" };\n" +
" }\n" +
"\n" +
" static {\n" +
" Object o7 = new Object() {\n" +
" public String toString() {\n" +
" return \"7\"; // a/Anon$Anon2$3 in 1.5, a/Anon$5 in 1.4\n" +
" }\n" +
" };\n" +
"\n" +
" Object o8 = new Object() {\n" +
" public String toString() {\n" +
" return \"8\"; // a/Anon$Anon2$4 in 1.5, a/Anon$6 in 1.4\n" +
" }\n" +
" };\n" +
" }\n" +
" }\n" +
"}");

incrementalBuild(projectPath);

IJavaProject project = env.getJavaProject(projectPath);
IPackageFragmentRoot root2 = project.getPackageFragmentRoot(project.getProject().getWorkspace().getRoot().findMember(root.makeAbsolute()));
IPackageFragment packageFragment = root2.getPackageFragment("a");//$NON-NLS-1$
ICompilationUnit compilationUnit = packageFragment.getCompilationUnit("Anon.java");//$NON-NLS-1$
IRegion region = JavaCore.newRegion();
region.add(compilationUnit);
IResource[] resources = JavaCore.getGeneratedResources(region, false);
assertEquals("Wrong size", 18, resources.length);//$NON-NLS-1$
Arrays.sort(resources, COMPARATOR);
String actualOutput = getResourceOuput(resources);
String expectedOutput =
"/Project/bin/a/Anon.class\n" +
"/Project/bin/a/Anon$1.class\n" +
"/Project/bin/a/Anon$2.class\n" +
"/Project/bin/a/Anon$3.class\n" +
"/Project/bin/a/Anon$4.class\n" +
"/Project/bin/a/Anon$5.class\n" +
"/Project/bin/a/Anon$6.class\n" +
"/Project/bin/a/Anon$7.class\n" +
"/Project/bin/a/Anon$8.class\n" +
"/Project/bin/a/Anon$Anon2.class\n" +
"/Project/bin/a/Anon$Anon2$1.class\n" +
"/Project/bin/a/Anon$Anon2$2.class\n" +
"/Project/bin/a/Anon$Anon2$3.class\n" +
"/Project/bin/a/Anon$Anon2$4.class\n" +
"/Project/bin/a/Anon$Anon2$5.class\n" +
"/Project/bin/a/Anon$Anon2$6.class\n" +
"/Project/bin/a/Anon$Anon2$7.class\n" +
"/Project/bin/a/Anon$Anon2$8.class\n";
assertEquals("Wrong names", Util.convertToIndependantLineDelimiter(expectedOutput), actualOutput);
env.removeProject(projectPath);
}

private String getResourceOuput(IResource[] resources) {
StringWriter stringWriter = new StringWriter();
PrintWriter writer = new PrintWriter(stringWriter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import org.eclipse.jdt.core.ToolFactory;
import org.eclipse.jdt.core.tests.util.Util;
import org.eclipse.jdt.core.util.ClassFileBytesDisassembler;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;

@SuppressWarnings({ "unchecked", "rawtypes" })
public class ArrayTest extends AbstractRegressionTest {
Expand Down Expand Up @@ -247,10 +245,6 @@ public void test010() {
}
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148807 - variation
public void test011() throws Exception {
if (new CompilerOptions(getCompilerOptions()).complianceLevel < ClassFileConstants.JDK1_5) {
// there is a bug on 1.4 VMs which make them fail verification (see 148807)
return;
}
this.runConformTest(
new String[] {
"X.java",
Expand Down Expand Up @@ -311,10 +305,6 @@ public void test011() throws Exception {
}
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148807 - variation
public void test012() throws Exception {
if (new CompilerOptions(getCompilerOptions()).complianceLevel < ClassFileConstants.JDK1_5) {
// there is a bug on 1.4 VMs which make them fail verification (see 148807)
return;
}
this.runConformTest(
new String[] {
"X.java",
Expand Down Expand Up @@ -407,12 +397,8 @@ public void test013() {
// Check return type of array#clone()
public void test014() throws Exception {
Map optionsMap = getCompilerOptions();
CompilerOptions options = new CompilerOptions(optionsMap);
if (options.complianceLevel > ClassFileConstants.JDK1_4) {
// check that #clone() return type is changed ONLY from -source 1.5 only (independant from compliance level)
optionsMap.put(CompilerOptions.OPTION_Source, CompilerOptions.getFirstSupportedJavaVersion());
}
this.runNegativeTest(
// check that #clone() return type is changed ONLY from -source 1.5 only (independant from compliance level)
this.runConformTest(
new String[] {
"X.java",
"public class X {\n" +
Expand All @@ -422,16 +408,11 @@ public void test014() throws Exception {
"}\n",
},
"",
null,
true,
optionsMap);
}
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=247307 - variation
//Check return type of array#clone()
public void test015() throws Exception {
if ( new CompilerOptions(getCompilerOptions()).sourceLevel < ClassFileConstants.JDK1_5) {
return;
}
this.runConformTest(
new String[] {
"X.java",
Expand Down Expand Up @@ -464,18 +445,8 @@ public void test016() throws Exception {
"\n",
ClassFileBytesDisassembler.DETAILED);

String expectedOutput = new CompilerOptions(getCompilerOptions()).sourceLevel <= ClassFileConstants.JDK1_4
? " // Method descriptor #15 ([J)V\n" +
" // Stack: 1, Locals: 3\n" +
" void foo(long[] longs) throws java.lang.Exception;\n" +
" 0 aload_1 [longs]\n" +
" 1 invokevirtual java.lang.Object.clone() : java.lang.Object [19]\n" +
" 4 astore_2 [other]\n" +
" 5 return\n" +
" Line numbers:\n" +
" [pc: 0, line: 3]\n" +
" [pc: 5, line: 4]\n"
: " // Method descriptor #15 ([J)V\n" +
String expectedOutput =
" // Method descriptor #15 ([J)V\n" +
" // Stack: 1, Locals: 3\n" +
" void foo(long[] longs) throws java.lang.Exception;\n" +
" 0 aload_1 [longs]\n" +
Expand All @@ -500,11 +471,7 @@ public void test016() throws Exception {
//Check constant pool declaring class of array#clone()
public void test017() throws Exception {
Map optionsMap = getCompilerOptions();
CompilerOptions options = new CompilerOptions(optionsMap);
if (options.complianceLevel > ClassFileConstants.JDK1_4) {
// check that #clone() return type is changed ONLY from -source 1.5 only (independant from compliance level)
optionsMap.put(CompilerOptions.OPTION_Source, CompilerOptions.getFirstSupportedJavaVersion());
}
// check that #clone() return type is changed ONLY from -source 1.5 only (independant from compliance level)
this.runConformTest(
new String[] {
"X.java",
Expand Down Expand Up @@ -551,8 +518,6 @@ public void test017() throws Exception {

// https://bugs.eclipse.org/331872 - [compiler] NPE in Scope.createArrayType when attempting qualified access from type parameter
public void test018() throws Exception {
if (this.complianceLevel < ClassFileConstants.JDK1_5)
return;
this.runNegativeTest(
new String[] {
"X.java",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -681,10 +681,10 @@ public void test012(){
" -13 -13.0 use 13 compliance (-source 13 -target 13)\n" +
" -14 -14.0 use 14 compliance (-source 14 -target 14)\n" +
getVersionOptions() +
" -source <version> set source level: 1.8, 9 to "+ CompilerOptions.getLatestVersion() +"\n" +
" (or 8.0, 9.0, etc)\n" +
" -target <version> set classfile target: 1.8, 9 to "+ CompilerOptions.getLatestVersion() +"\n" +
" (or 8.0, 9.0, etc)\n" +
" -source <version> set source level: 1.8, 1.9, 10 to "+ CompilerOptions.getLatestVersion() +"\n" +
" (or 8, 8.0, etc)\n" +
" -target <version> set classfile target: 1.8, 1.9, 10 to "+ CompilerOptions.getLatestVersion() +"\n" +
" (or 8, 8.0, etc)\n" +
" --enable-preview enable support for preview features of the\n" +
" latest Java release\n" +
" \n" +
Expand Down Expand Up @@ -11276,7 +11276,7 @@ public void testInferenceIn14Project(){
new File(lib1Path).delete();
}
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=328775 - Compiler fails to warn about invalid cast in 1.8 mode.
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=328775 - Compiler fails to warn about invalid cast in 1.4 mode.
public void testInferenceIn15Project(){ // ensure 1.8 complains too
String currentWorkingDirectoryPath = System.getProperty("user.dir");
if (currentWorkingDirectoryPath == null) {
Expand Down Expand Up @@ -11327,62 +11327,7 @@ public void testInferenceIn15Project(){ // ensure 1.8 complains too
new File(lib1Path).delete();
}
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=186565 Test interaction between 1.8 and 1.8 class files
public void test186565(){
String outputDirName = OUTPUT_DIR + File.separator + "d",
metaInfDirName = outputDirName + File.separator + "META-INF",
jarFileName = outputDirName + File.separator + "classB15.jar";
this.runConformTest(
new String[] {
"d/B.java",
"public class B<T> extends A<T> {\n" +
"}",
"d/A.java",
"public class A<T> {\n" +
"}",
},
"\"" + outputDirName + "\""
+ " -1.8 -g -preserveAllLocals"
+ " -d \"" + outputDirName + "\"",
"",
"",
true /* flush output directory */);
File outputDirectory = new File(outputDirName);
File metaInfDirectory = new File(metaInfDirName);
metaInfDirectory.mkdirs();
try {
Util.createFile(metaInfDirName + File.separator + "MANIFEST.MF",
"Manifest-Version: 1.0\n" +
"Class-Path: ../d/classB15.jar\n");
} catch (IOException e) {
fail("could not create manifest file");
}
Util.delete(outputDirName + File.separator + "A.class");
Util.delete(outputDirName + File.separator + "A.java");
try {
Util.zip(outputDirectory, jarFileName);
} catch (IOException e) {
fail("could not create jar file");
}
Util.delete(outputDirName + File.separator + "B.class");
Util.delete(outputDirName + File.separator + "B.java");
this.runConformTest(
new String[] {
"d/A.java",
"public class A {\n" +
"}",
"d/C.java",
"public class C extends B<String> {\n" +
"}",
},
"\"" + outputDirName + "\""
+ " -1.8 -g -preserveAllLocals"
+ " -cp \"" + jarFileName + "\""
+ " -d \"" + OUTPUT_DIR + "\"",
"",
"",
false /* do not flush output directory */);
}

// https://bugs.eclipse.org/bugs/show_bug.cgi?id=330347 - Test retention of bridge methods.
public void testBridgeMethodRetention(){
String currentWorkingDirectoryPath = System.getProperty("user.dir");
Expand Down Expand Up @@ -13251,7 +13196,7 @@ public void testUnusedObjectAllocation() {
}
public void testBug573153() {
String output = MAIN.bind("configure.source", "10");
String template = "source level should be in '1.8','9'...'22' (or '5.0'..'22.0'): 10";
String template = "source level should be in '1.8','9'...'22' (or '8.0'..'22.0'): 10";
template = template.replace("22", CompilerOptions.getLatestVersion());
assertEquals("configure.source is not updated", template, output);

Expand Down
Loading

0 comments on commit c94a550

Please sign in to comment.