Skip to content

Commit

Permalink
[WIP] fix some tests
Browse files Browse the repository at this point in the history
Signed-off-by: David Thompson <davthomp@redhat.com>
  • Loading branch information
datho7561 committed Oct 27, 2023
1 parent 356d6df commit baa7215
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,31 @@ public void runComplianceParserTest(
this.runNegativeTest(testFiles, expected18ProblemLog);
}
}
public void runComplianceParserTest(
String[] testFiles,
String expected13ProblemLog,
String expected14ProblemLog,
String expected15ProblemLog,
String expected16ProblemLog,
String expected17ProblemLog,
String expected18ProblemLog,
String expected21ProblemLog){
if (this.complianceLevel == ClassFileConstants.JDK1_3) {
this.runNegativeTest(testFiles, expected13ProblemLog);
} else if(this.complianceLevel == ClassFileConstants.JDK1_4) {
this.runNegativeTest(testFiles, expected14ProblemLog);
} else if(this.complianceLevel == ClassFileConstants.JDK1_5) {
this.runNegativeTest(testFiles, expected15ProblemLog);
} else if(this.complianceLevel == ClassFileConstants.JDK1_6) {
this.runNegativeTest(testFiles, expected16ProblemLog);
} else if (this.complianceLevel == ClassFileConstants.JDK1_7) {
this.runNegativeTest(testFiles, expected17ProblemLog);
} else if(this.complianceLevel < ClassFileConstants.JDK21) {
this.runNegativeTest(testFiles, expected18ProblemLog);
} else {
this.runNegativeTest(testFiles, expected21ProblemLog);
}
}
public void test0001() {
String[] testFiles = new String[] {
"X.java",
Expand Down Expand Up @@ -3288,6 +3313,43 @@ public void testBug399781() {
" ^\n" +
"The parameter _ is hiding a field from type X\n" +
"----------\n";
String expected21ProblemLog =
"----------\n"
+ "1. ERROR in X.java (at line 2)\n"
+ " int _;\n"
+ " ^\n"
+ "Unnamed Patterns and Variables is a preview feature and disabled by default. Use --enable-preview to enable\n"
+ "----------\n"
+ "2. ERROR in X.java (at line 4)\n"
+ " int _ = 3;\n"
+ " ^\n"
+ "Unnamed Patterns and Variables is a preview feature and disabled by default. Use --enable-preview to enable\n"
+ "----------\n"
+ "3. WARNING in X.java (at line 4)\n"
+ " int _ = 3;\n"
+ " ^\n"
+ "The local variable _ is hiding a field from type X\n"
+ "----------\n"
+ "4. ERROR in X.java (at line 8)\n"
+ " void goo(int _) {}\n"
+ " ^\n"
+ "Unnamed Patterns and Variables is a preview feature and disabled by default. Use --enable-preview to enable\n"
+ "----------\n"
+ "5. WARNING in X.java (at line 8)\n"
+ " void goo(int _) {}\n"
+ " ^\n"
+ "The parameter _ is hiding a field from type X\n"
+ "----------\n"
+ "6. ERROR in X.java (at line 11)\n"
+ " } catch (Exception _) {\n"
+ " ^\n"
+ "Unnamed Patterns and Variables is a preview feature and disabled by default. Use --enable-preview to enable\n"
+ "----------\n"
+ "7. WARNING in X.java (at line 11)\n"
+ " } catch (Exception _) {\n"
+ " ^\n"
+ "The parameter _ is hiding a field from type X\n"
+ "----------\n";

runComplianceParserTest(
testFiles,
Expand All @@ -3296,7 +3358,8 @@ public void testBug399781() {
expected13ProblemLog,
expected13ProblemLog,
expected13ProblemLog,
expectedProblemLog
expectedProblemLog,
expected21ProblemLog
);
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406846: [1.8] compiler NPE for method reference/lambda code compiled with < 1.8 compliance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7382,8 +7382,28 @@ public void testUnderScoreParameter() {
" }\n" +
"}\n"
};
if (this.complianceLevel >= ClassFileConstants.JDK21 && this.enablePreview) {
this.runNegativeTest(testContent, "");
if (this.complianceLevel >= ClassFileConstants.JDK21) {
if (this.enablePreview) {
this.runNegativeTest(testContent, "");
} else {
this.runNegativeTest(testContent, //
"----------\n"
+ "1. ERROR in X.java (at line 6)\n"
+ " F f = (int _) -> {\n"
+ " ^\n"
+ "Unnamed Patterns and Variables is a preview feature and disabled by default. Use --enable-preview to enable\n"
+ "----------\n"
+ "2. ERROR in X.java (at line 8)\n"
+ " F f2 = _ -> {};\n"
+ " ^\n"
+ "Unnamed Patterns and Variables is a preview feature and disabled by default. Use --enable-preview to enable\n"
+ "----------\n"
+ "3. ERROR in X.java (at line 8)\n"
+ " F f2 = _ -> {};\n"
+ " ^\n"
+ "Unnamed Patterns and Variables is a preview feature and disabled by default. Use --enable-preview to enable\n"
+ "----------\n");
}
return;
}
String level = this.complianceLevel >= ClassFileConstants.JDK9 ? "ERROR" : "WARNING";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4248,6 +4248,9 @@ && isIndirectlyInsideFieldInitialization()) { // enum initializers indeed need m
case TokenNameCOLON_COLON:
this.inReferenceExpression = true;
break;
case TokenNameUnderscore:
super.consumeToken(this.currentToken);
break;
case TokenNameIdentifier:
if (this.inReferenceExpression)
break;
Expand Down

0 comments on commit baa7215

Please sign in to comment.