Created
October 10, 2023 13:23
-
-
Save sormuras/834e2f05b7d8784d70ad63e91b5e2d96 to your computer and use it in GitHub Desktop.
Cleanup conversion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Subject: [PATCH] Cleanup conversion | |
--- | |
Index: test/langtools/lib/combo/tools/javac/combo/ComboWatcher.java | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
diff --git a/test/langtools/lib/combo/tools/javac/combo/ComboWatcher.java b/test/langtools/lib/combo/tools/javac/combo/ComboWatcher.java | |
new file mode 100644 | |
--- /dev/null (revision 7b1af0140a6819bc7837dfa18a39420f9ac1c8b6) | |
+++ b/test/langtools/lib/combo/tools/javac/combo/ComboWatcher.java (revision 7b1af0140a6819bc7837dfa18a39420f9ac1c8b6) | |
@@ -0,0 +1,31 @@ | |
+package tools.javac.combo; | |
+ | |
+import java.util.Collections; | |
+import java.util.HashSet; | |
+import java.util.Set; | |
+ | |
+import org.junit.jupiter.api.extension.AfterAllCallback; | |
+import org.junit.jupiter.api.extension.ExtensionContext; | |
+import org.junit.jupiter.api.extension.TestWatcher; | |
+ | |
+public class ComboWatcher implements TestWatcher, AfterAllCallback { | |
+ private final Set<String> errors = Collections.synchronizedSet(new HashSet<>()); | |
+ | |
+ @Override | |
+ public void testFailed(ExtensionContext context, Throwable cause) { | |
+ if (context.getRequiredTestInstance() instanceof JavacTemplateTestBase instance) { | |
+ errors.addAll(instance.diags.errorKeys()); | |
+ if (instance instanceof CompilationTestCase) { | |
+ // Make sure offending template ends up in log file on failure | |
+ System.err.printf("Diagnostics: %s%nTemplate: %s%n", instance.diags.errorKeys(), | |
+ instance.sourceFiles.stream().map(SourceFile::template).toList()); | |
+ } | |
+ } | |
+ } | |
+ | |
+ @Override | |
+ public void afterAll(ExtensionContext extensionContext) { | |
+ if (errors.isEmpty()) return; | |
+ System.err.println("Errors found in tests: " + errors); | |
+ } | |
+} | |
Index: test/langtools/lib/combo/tools/javac/combo/CompilationTestCase.java | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
diff --git a/test/langtools/lib/combo/tools/javac/combo/CompilationTestCase.java b/test/langtools/lib/combo/tools/javac/combo/CompilationTestCase.java | |
--- a/test/langtools/lib/combo/tools/javac/combo/CompilationTestCase.java (revision 5f9f0f606f9318452017129d3325c819380c190f) | |
+++ b/test/langtools/lib/combo/tools/javac/combo/CompilationTestCase.java (revision 7b1af0140a6819bc7837dfa18a39420f9ac1c8b6) | |
@@ -31,17 +31,11 @@ | |
import javax.tools.Diagnostic; | |
-import org.junit.jupiter.api.AfterEach; | |
-import org.junit.jupiter.api.Test; | |
-import org.junit.jupiter.api.extension.ExtensionContext; | |
- | |
-import static java.util.stream.Collectors.toList; | |
- | |
/** | |
* Base class for negative and positive compilation tests. | |
*/ | |
public class CompilationTestCase extends JavacTemplateTestBase { | |
- private String[] compileOptions = new String[] { }; | |
+ private String[] compileOptions = new String[]{}; | |
private String defaultFileName = "Source.java"; | |
private String programShell = "#"; | |
@@ -71,7 +65,7 @@ | |
throw new AssertionError("unexpected negative value " + i); | |
} | |
if (i >= compileOptions.length) { | |
- compileOptions = new String[] {}; | |
+ compileOptions = new String[]{}; | |
} else { | |
compileOptions = Arrays.copyOf(compileOptions, compileOptions.length - i); | |
} | |
@@ -95,8 +89,7 @@ | |
File dir = null; | |
try { | |
dir = compile(generate); | |
- } | |
- catch (IOException e) { | |
+ } catch (IOException e) { | |
throw new RuntimeException(e); | |
} | |
postTest.run(); | |
Index: test/langtools/lib/combo/tools/javac/combo/JavacTemplateTestBase.java | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
diff --git a/test/langtools/lib/combo/tools/javac/combo/JavacTemplateTestBase.java b/test/langtools/lib/combo/tools/javac/combo/JavacTemplateTestBase.java | |
--- a/test/langtools/lib/combo/tools/javac/combo/JavacTemplateTestBase.java (revision 5f9f0f606f9318452017129d3325c819380c190f) | |
+++ b/test/langtools/lib/combo/tools/javac/combo/JavacTemplateTestBase.java (revision 7b1af0140a6819bc7837dfa18a39420f9ac1c8b6) | |
@@ -33,10 +33,8 @@ | |
import java.util.Arrays; | |
import java.util.Collections; | |
import java.util.HashMap; | |
-import java.util.HashSet; | |
import java.util.List; | |
import java.util.Map; | |
-import java.util.Set; | |
import java.util.concurrent.atomic.AtomicInteger; | |
import java.util.function.Consumer; | |
import javax.tools.Diagnostic; | |
@@ -48,18 +46,13 @@ | |
import javax.tools.ToolProvider; | |
import com.sun.source.util.JavacTask; | |
-import com.sun.tools.javac.util.Pair; | |
-import org.junit.jupiter.api.AfterEach; | |
import org.junit.jupiter.api.BeforeEach; | |
-import org.junit.jupiter.api.Test; | |
-import org.junit.jupiter.api.extension.ExtensionContext; | |
-import org.junit.jupiter.api.extension.TestWatcher; | |
-import org.junit.jupiter.api.extension.AfterTestExecutionCallback; | |
+import org.junit.jupiter.api.extension.ExtendWith; | |
import static org.junit.jupiter.api.Assertions.fail; | |
/** | |
- * Base class for template-driven TestNG javac tests that support on-the-fly | |
+ * Base class for template-driven JUnit javac tests that support on-the-fly | |
* source file generation, compilation, classloading, execution, and separate | |
* compilation. | |
* | |
@@ -71,15 +64,15 @@ | |
* | |
* @author Brian Goetz | |
*/ | |
-public abstract class JavacTemplateTestBase implements TestWatcher, AfterTestExecutionCallback { | |
- protected static final Set<String> suiteErrors = Collections.synchronizedSet(new HashSet<>()); | |
- protected static final AtomicInteger counter = new AtomicInteger(); | |
- protected static final File root = new File("gen"); | |
- protected static final File nullDir = new File("empty"); | |
+@ExtendWith(ComboWatcher.class) | |
+public abstract class JavacTemplateTestBase { | |
+ private static final AtomicInteger counter = new AtomicInteger(); | |
+ private static final File root = new File("gen"); | |
+ private static final File nullDir = new File("empty"); | |
protected final Map<String, Template> templates = new HashMap<>(); | |
protected final Diagnostics diags = new Diagnostics(); | |
- protected final List<Pair<String, String>> sourceFiles = new ArrayList<>(); | |
+ protected final List<SourceFile> sourceFiles = new ArrayList<>(); | |
protected final List<String> compileOptions = new ArrayList<>(); | |
protected final List<File> classpaths = new ArrayList<>(); | |
@@ -95,7 +88,7 @@ | |
/** Add a source file */ | |
protected void addSourceFile(String name, String template) { | |
- sourceFiles.add(new Pair<>(name, template)); | |
+ sourceFiles.add(new SourceFile(name, template)); | |
} | |
/** Add a File to the class path to be used when loading classes; File values | |
@@ -139,24 +132,6 @@ | |
resetClassPaths(); | |
} | |
- // After each test method, if the test failed, capture source files and diagnostics and put them in the log | |
- @Override | |
- public void testFailed(ExtensionContext context, Throwable cause) { | |
- } | |
- | |
- // After the suite is done, dump any errors to output | |
- @Override | |
- public void afterTestExecution(ExtensionContext context) { | |
- } | |
- | |
- /** | |
- * Get a description of this test case; since test cases may be combinatorially | |
- * generated, this should include all information needed to describe the test case | |
- */ | |
- protected String getTestCaseDescription() { | |
- return this.toString(); | |
- } | |
- | |
/** Assert that all previous calls to compile() succeeded */ | |
protected void assertCompileSucceeded() { | |
if (diags.errorsFound()) | |
@@ -244,9 +219,7 @@ | |
/** Compile all registered source files, optionally generating class files | |
* and returning a File describing the directory to which they were written */ | |
protected File compile(boolean generate) throws IOException { | |
- List<JavaFileObject> files = new ArrayList<>(); | |
- for (Pair<String, String> e : sourceFiles) | |
- files.add(new FileAdapter(e.fst, e.snd)); | |
+ var files = sourceFiles.stream().map(FileAdapter::new).toList(); | |
return compile(classpaths, files, generate); | |
} | |
@@ -254,13 +227,11 @@ | |
* for finding required classfiles, optionally generating class files | |
* and returning a File describing the directory to which they were written */ | |
protected File compile(List<File> classpaths, boolean generate) throws IOException { | |
- List<JavaFileObject> files = new ArrayList<>(); | |
- for (Pair<String, String> e : sourceFiles) | |
- files.add(new FileAdapter(e.fst, e.snd)); | |
+ var files = sourceFiles.stream().map(FileAdapter::new).toList(); | |
return compile(classpaths, files, generate); | |
} | |
- private File compile(List<File> classpaths, List<JavaFileObject> files, boolean generate) throws IOException { | |
+ private File compile(List<File> classpaths, List<? extends JavaFileObject> files, boolean generate) throws IOException { | |
JavaCompiler systemJavaCompiler = ToolProvider.getSystemJavaCompiler(); | |
try (StandardJavaFileManager fm = systemJavaCompiler.getStandardFileManager(null, null, null)) { | |
if (classpaths.size() > 0) | |
@@ -313,9 +284,9 @@ | |
private class FileAdapter extends SimpleJavaFileObject { | |
private final String templateString; | |
- FileAdapter(String filename, String templateString) { | |
- super(URI.create("myfo:/" + filename), Kind.SOURCE); | |
- this.templateString = templateString; | |
+ FileAdapter(SourceFile file) { | |
+ super(URI.create("myfo:/" + file.name()), Kind.SOURCE); | |
+ this.templateString = file.template(); | |
} | |
public CharSequence getCharContent(boolean ignoreEncodingErrors) { | |
Index: test/langtools/lib/combo/tools/javac/combo/CompilationDiagnosticPrinter.java | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
diff --git a/test/langtools/lib/combo/tools/javac/combo/CompilationDiagnosticPrinter.java b/test/langtools/lib/combo/tools/javac/combo/SourceFile.java | |
rename from test/langtools/lib/combo/tools/javac/combo/CompilationDiagnosticPrinter.java | |
rename to test/langtools/lib/combo/tools/javac/combo/SourceFile.java | |
--- a/test/langtools/lib/combo/tools/javac/combo/CompilationDiagnosticPrinter.java (revision 5f9f0f606f9318452017129d3325c819380c190f) | |
+++ b/test/langtools/lib/combo/tools/javac/combo/SourceFile.java (revision 7b1af0140a6819bc7837dfa18a39420f9ac1c8b6) | |
@@ -23,26 +23,4 @@ | |
package tools.javac.combo; | |
-import org.junit.jupiter.api.Test; | |
-import org.junit.jupiter.api.extension.ExtensionContext; | |
- | |
-import static java.util.stream.Collectors.toList; | |
- | |
-/** | |
- * Class for TestWatcher implementation. | |
- */ | |
-public class CompilationDiagnosticPrinter extends JavacTemplateTestBase { | |
- @Override | |
- public void testFailed(ExtensionContext context, Throwable cause) { | |
- // Make sure offending template ends up in log file on failure | |
- System.err.printf("Diagnostics: %s%nTemplate: %s%n", diags.errorKeys(), | |
- sourceFiles.stream().map(p -> p.snd).collect(toList())); | |
- } | |
- | |
- // After the suite is done, dump any errors to output | |
- @Override | |
- public void afterTestExecution(ExtensionContext context) { | |
- if (!suiteErrors.isEmpty()) | |
- System.err.println("Errors found in test suite: " + suiteErrors); | |
- } | |
-} | |
\ No newline at end of file | |
+public record SourceFile(String name, String template) {} | |
Index: test/langtools/lib/combo/tools/javac/combo/TemplateTest.java | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
diff --git a/test/langtools/lib/combo/tools/javac/combo/TemplateTest.java b/test/langtools/lib/combo/tools/javac/combo/TemplateTest.java | |
--- a/test/langtools/lib/combo/tools/javac/combo/TemplateTest.java (revision 5f9f0f606f9318452017129d3325c819380c190f) | |
+++ b/test/langtools/lib/combo/tools/javac/combo/TemplateTest.java (revision 7b1af0140a6819bc7837dfa18a39420f9ac1c8b6) | |
@@ -23,26 +23,26 @@ | |
package tools.javac.combo; | |
-import org.junit.jupiter.api.BeforeAll; | |
+import static org.junit.jupiter.api.Assertions.*; | |
+ | |
import org.junit.jupiter.api.Test; | |
+import org.junit.jupiter.api.BeforeEach; | |
import java.util.HashMap; | |
import java.util.Map; | |
-import static org.junit.jupiter.api.Assertions.assertEquals; | |
-import static org.junit.jupiter.api.Assertions.assertThrows; | |
/** | |
* TemplateTest | |
*/ | |
class TemplateTest { | |
- static Map<String, Template> vars = new HashMap<>(); | |
+ final Map<String, Template> vars = new HashMap<>(); | |
- @BeforeAll | |
- static void before() { vars.clear(); } | |
+ @BeforeEach | |
+ void before() { vars.clear(); } | |
private void assertTemplate(String expected, String template) { | |
String result = Template.expandTemplate(template, vars); | |
- assertEquals(result, expected, "for " + template); | |
+ assertEquals(expected, result, "for " + template); | |
} | |
private String dotIf(String s) { | |
Index: test/langtools/tools/javac/expswitch/ExpSwitchNestingTest.java | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
diff --git a/test/langtools/tools/javac/expswitch/ExpSwitchNestingTest.java b/test/langtools/tools/javac/expswitch/ExpSwitchNestingTest.java | |
--- a/test/langtools/tools/javac/expswitch/ExpSwitchNestingTest.java (revision 5f9f0f606f9318452017129d3325c819380c190f) | |
+++ b/test/langtools/tools/javac/expswitch/ExpSwitchNestingTest.java (revision 7b1af0140a6819bc7837dfa18a39420f9ac1c8b6) | |
@@ -21,16 +21,11 @@ | |
* questions. | |
*/ | |
-import java.io.IOException; | |
import java.util.List; | |
import org.junit.jupiter.api.Test; | |
-import org.junit.jupiter.api.extension.ExtendWith; | |
-import tools.javac.combo.*; | |
+import tools.javac.combo.CompilationTestCase; | |
-import static java.util.stream.Collectors.toList; | |
- | |
-@ExtendWith(CompilationDiagnosticPrinter.class) | |
class ExpSwitchNestingTest extends CompilationTestCase { | |
private static final String RUNNABLE = "Runnable r = () -> { # };"; | |
private static final String INT_FN = "java.util.function.IntSupplier r = () -> { # };"; | |
Index: test/langtools/tools/javac/lambda/bridge/template_tests/BridgeMethodsTemplateTest.java | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
diff --git a/test/langtools/tools/javac/lambda/bridge/template_tests/BridgeMethodsTemplateTest.java b/test/langtools/tools/javac/lambda/bridge/template_tests/BridgeMethodsTemplateTest.java | |
--- a/test/langtools/tools/javac/lambda/bridge/template_tests/BridgeMethodsTemplateTest.java (revision 5f9f0f606f9318452017129d3325c819380c190f) | |
+++ b/test/langtools/tools/javac/lambda/bridge/template_tests/BridgeMethodsTemplateTest.java (revision 7b1af0140a6819bc7837dfa18a39420f9ac1c8b6) | |
@@ -31,7 +31,6 @@ | |
* | |
* @author Brian Goetz | |
*/ | |
-@ExtendWith(CompilationDiagnosticPrinter.class) | |
class BridgeMethodsTemplateTest extends BridgeMethodTestCase { | |
/* | |
Index: test/langtools/tools/javac/lambda/methodReference/BoundUnboundSearchTest.java | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
diff --git a/test/langtools/tools/javac/lambda/methodReference/BoundUnboundSearchTest.java b/test/langtools/tools/javac/lambda/methodReference/BoundUnboundSearchTest.java | |
--- a/test/langtools/tools/javac/lambda/methodReference/BoundUnboundSearchTest.java (revision 5f9f0f606f9318452017129d3325c819380c190f) | |
+++ b/test/langtools/tools/javac/lambda/methodReference/BoundUnboundSearchTest.java (revision 7b1af0140a6819bc7837dfa18a39420f9ac1c8b6) | |
@@ -41,11 +41,8 @@ | |
import com.sun.tools.javac.util.JCDiagnostic; | |
import org.junit.jupiter.api.Test; | |
-import org.junit.jupiter.api.extension.ExtendWith; | |
import tools.javac.combo.CompilationTestCase; | |
-import tools.javac.combo.CompilationDiagnosticPrinter; | |
-@ExtendWith(CompilationDiagnosticPrinter.class) | |
class BoundUnboundSearchTest extends CompilationTestCase { | |
static final String TEMPLATE = | |
""" | |
Index: test/langtools/tools/javac/patterns/scope/ScopeTest.java | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
diff --git a/test/langtools/tools/javac/patterns/scope/ScopeTest.java b/test/langtools/tools/javac/patterns/scope/ScopeTest.java | |
--- a/test/langtools/tools/javac/patterns/scope/ScopeTest.java (revision 5f9f0f606f9318452017129d3325c819380c190f) | |
+++ b/test/langtools/tools/javac/patterns/scope/ScopeTest.java (revision 7b1af0140a6819bc7837dfa18a39420f9ac1c8b6) | |
@@ -23,17 +23,10 @@ | |
import java.io.IOException; | |
import java.util.Arrays; | |
-import java.util.List; | |
import java.util.stream.Collectors; | |
- | |
import org.junit.jupiter.api.Test; | |
-import org.junit.jupiter.api.extension.ExtensionContext; | |
-import org.junit.jupiter.api.extension.ExtendWith; | |
-import tools.javac.combo.*; | |
+import tools.javac.combo.JavacTemplateTestBase; | |
-import static java.util.stream.Collectors.toList; | |
- | |
-@ExtendWith(CompilationDiagnosticPrinter.class) | |
class ScopeTest extends JavacTemplateTestBase { | |
private static String st_block(String... statements) { | |
Index: test/langtools/tools/javac/records/LocalStaticDeclarations2.java | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
diff --git a/test/langtools/tools/javac/records/LocalStaticDeclarations2.java b/test/langtools/tools/javac/records/LocalStaticDeclarations2.java | |
--- a/test/langtools/tools/javac/records/LocalStaticDeclarations2.java (revision 5f9f0f606f9318452017129d3325c819380c190f) | |
+++ b/test/langtools/tools/javac/records/LocalStaticDeclarations2.java (revision 7b1af0140a6819bc7837dfa18a39420f9ac1c8b6) | |
@@ -33,11 +33,8 @@ | |
*/ | |
import org.junit.jupiter.api.Test; | |
-import org.junit.jupiter.api.extension.ExtendWith; | |
import tools.javac.combo.CompilationTestCase; | |
-import tools.javac.combo.CompilationDiagnosticPrinter; | |
-@ExtendWith(CompilationDiagnosticPrinter.class) | |
class LocalStaticDeclarations2 extends CompilationTestCase { | |
@Test | |
void testLocalStatic() { | |
Index: test/langtools/tools/javac/records/RecordCompilationTests.java | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
diff --git a/test/langtools/tools/javac/records/RecordCompilationTests.java b/test/langtools/tools/javac/records/RecordCompilationTests.java | |
--- a/test/langtools/tools/javac/records/RecordCompilationTests.java (revision 5f9f0f606f9318452017129d3325c819380c190f) | |
+++ b/test/langtools/tools/javac/records/RecordCompilationTests.java (revision 7b1af0140a6819bc7837dfa18a39420f9ac1c8b6) | |
@@ -1,5 +1,5 @@ | |
/* | |
- * Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved. | |
+ * Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved. | |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
* | |
* This code is free software; you can redistribute it and/or modify it | |
@@ -34,8 +34,8 @@ | |
* jdk.compiler/com.sun.tools.javac.util | |
* jdk.jdeps/com.sun.tools.classfile | |
* @build JavacTestingAbstractProcessor | |
- * @run testng/othervm -DuseAP=false RecordCompilationTests | |
- * @run testng/othervm -DuseAP=true RecordCompilationTests | |
+ * @run junit/othervm -DuseAP=false RecordCompilationTests | |
+ * @run junit/othervm -DuseAP=true RecordCompilationTests | |
*/ | |
import java.io.File; | |
@@ -97,11 +97,10 @@ | |
import com.sun.tools.javac.code.Symbol.VarSymbol; | |
import com.sun.tools.javac.util.JCDiagnostic; | |
-import org.testng.annotations.Test; | |
import tools.javac.combo.CompilationTestCase; | |
+import org.junit.jupiter.api.Test; | |
import static java.lang.annotation.ElementType.*; | |
-import static org.testng.Assert.assertEquals; | |
/** Records are the first feature which sports automatic injection of (declarative and type) annotations : from a | |
* given record component to one or more record members, if applicable. | |
@@ -115,8 +114,7 @@ | |
* method: testAnnos() | |
*/ | |
-@Test | |
-public class RecordCompilationTests extends CompilationTestCase { | |
+class RecordCompilationTests extends CompilationTestCase { | |
private static String[] OPTIONS_WITH_AP = {"-processor", SimplestAP.class.getName()}; | |
private static final List<String> BAD_COMPONENT_NAMES = List.of( | |
@@ -144,7 +142,8 @@ | |
System.out.println(useAP ? "running all tests using an annotation processor" : "running all tests without annotation processor"); | |
} | |
- public void testMalformedDeclarations() { | |
+ @Test | |
+ void testMalformedDeclarations() { | |
assertFail("compiler.err.premature.eof", "record R()"); | |
assertFail("compiler.err.expected", "record R();"); | |
assertFail("compiler.err.illegal.start.of.type", "record R(,) { }"); | |
@@ -166,7 +165,8 @@ | |
assertFail("compiler.err.instance.initializer.not.allowed.in.records", "record R(int i) { {} }"); | |
} | |
- public void testGoodDeclarations() { | |
+ @Test | |
+ void testGoodDeclarations() { | |
assertOK("public record R() { }"); | |
assertOK("record R() { }"); | |
assertOK("record R() implements java.io.Serializable, Runnable { public void run() { } }"); | |
@@ -196,7 +196,8 @@ | |
"""); | |
} | |
- public void testGoodMemberDeclarations() { | |
+ @Test | |
+ void testGoodMemberDeclarations() { | |
String template = "public record R(int x) {\n" | |
+ " public R(int x) { this.x = x; }\n" | |
+ " public int x() { return x; }\n" | |
@@ -207,12 +208,14 @@ | |
assertOK(template); | |
} | |
- public void testBadComponentNames() { | |
+ @Test | |
+ void testBadComponentNames() { | |
for (String s : BAD_COMPONENT_NAMES) | |
assertFail("compiler.err.illegal.record.component.name", "record R(int #) { } ", s); | |
} | |
- public void testRestrictedIdentifiers() { | |
+ @Test | |
+ void testRestrictedIdentifiers() { | |
for (String s : List.of("interface record { void m(); }", | |
"@interface record { }", | |
"class record { }", | |
@@ -231,7 +234,8 @@ | |
} | |
} | |
- public void testValidMembers() { | |
+ @Test | |
+ void testValidMembers() { | |
for (String s : List.of("record X(int j) { }", | |
"interface I { }", | |
"static { }", | |
@@ -242,12 +246,14 @@ | |
} | |
} | |
- public void testCyclic() { | |
+ @Test | |
+ void testCyclic() { | |
// Cyclic records are OK, but cyclic inline records would not be | |
assertOK("record R(R r) { }"); | |
} | |
- public void testBadExtends() { | |
+ @Test | |
+ void testBadExtends() { | |
assertFail("compiler.err.expected", "record R(int x) extends Object { }"); | |
assertFail("compiler.err.expected", "record R(int x) {}\n" | |
+ "record R2(int x) extends R { }"); | |
@@ -255,7 +261,8 @@ | |
+ "class C extends R { }"); | |
} | |
- public void testNoExtendRecord() { | |
+ @Test | |
+ void testNoExtendRecord() { | |
assertFail("compiler.err.invalid.supertype.record", | |
""" | |
class R extends Record { | |
@@ -267,7 +274,8 @@ | |
); | |
} | |
- public void testFieldDeclarations() { | |
+ @Test | |
+ void testFieldDeclarations() { | |
// static fields are OK | |
assertOK("public record R(int x) {\n" + | |
" static int I = 1;\n" + | |
@@ -295,7 +303,8 @@ | |
"}"); | |
} | |
- public void testAccessorRedeclaration() { | |
+ @Test | |
+ void testAccessorRedeclaration() { | |
assertOK("public record R(int x) {\n" + | |
" public int x() { return x; };" + | |
"}"); | |
@@ -351,7 +360,8 @@ | |
"}"); | |
} | |
- public void testConstructorRedeclaration() { | |
+ @Test | |
+ void testConstructorRedeclaration() { | |
for (String goodCtor : List.of( | |
"public R(int x) { this(x, 0); }", | |
"public R(int x, int y) { this.x = x; this.y = y; }", | |
@@ -442,7 +452,8 @@ | |
"public R(int a) { super(); this.a = a; }"); | |
} | |
- public void testAnnotationCriteria() { | |
+ @Test | |
+ void testAnnotationCriteria() { | |
String imports = "import java.lang.annotation.*;\n"; | |
String template = "@Target({ # }) @interface A {}\n"; | |
EnumMap<ElementType, String> annotations = new EnumMap<>(ElementType.class); | |
@@ -451,7 +462,7 @@ | |
EnumSet<ElementType> goodSet = EnumSet.of(RECORD_COMPONENT, FIELD, METHOD, PARAMETER, TYPE_USE); | |
EnumSet<ElementType> badSet = EnumSet.of(CONSTRUCTOR, PACKAGE, TYPE, LOCAL_VARIABLE, ANNOTATION_TYPE, TYPE_PARAMETER, MODULE); | |
- assertEquals(goodSet.size() + badSet.size(), values().length); | |
+ Assert.check(goodSet.size() + badSet.size() == values().length); | |
String A_GOOD = template.replace("#", | |
goodSet.stream().map(ElementType::name).map(s -> "ElementType." + s).collect(Collectors.joining(","))); | |
String A_BAD = template.replace("#", | |
@@ -475,7 +486,8 @@ | |
// TODO: OK to redeclare with or without same annos | |
} | |
- public void testNestedRecords() { | |
+ @Test | |
+ void testNestedRecords() { | |
String template = "class R { \n" + | |
" # record RR(int a) { }\n" + | |
"}"; | |
@@ -493,7 +505,8 @@ | |
assertOK("record R(int x) { # }", s); | |
} | |
- public void testDuplicatedMember() { | |
+ @Test | |
+ void testDuplicatedMember() { | |
String template | |
= " record R(int i) {\n" + | |
" public int i() { return i; }\n" + | |
@@ -502,7 +515,8 @@ | |
assertFail("compiler.err.already.defined", template); | |
} | |
- public void testStaticLocals() { | |
+ @Test | |
+ void testStaticLocals() { | |
// static locals can't capture local variables, instance fields or type variables | |
for (String s : List.of( | |
"record RR(int x) { public int x() { return y; }};", | |
@@ -592,7 +606,8 @@ | |
assertOK("class R { void m() { final record RR(int x) { }; } }"); | |
} | |
- public void testStaticDefinitionsInInnerClasses() { | |
+ @Test | |
+ void testStaticDefinitionsInInnerClasses() { | |
// static defs in inner classes can't capture instance fields or type variables | |
for (String s : List.of( | |
""" | |
@@ -1058,7 +1073,8 @@ | |
} | |
} | |
- public void testReturnInCanonical_Compact() { | |
+ @Test | |
+ void testReturnInCanonical_Compact() { | |
assertFail("compiler.err.invalid.canonical.constructor.in.record", "record R(int x) { # }", | |
"public R { return; }"); | |
assertFail("compiler.err.invalid.canonical.constructor.in.record", "record R(int x) { # }", | |
@@ -1067,7 +1083,8 @@ | |
assertOK("record R(int x) { public R { Runnable r = () -> { return; };} }"); | |
} | |
- public void testArgumentsAreNotFinalInCompact() { | |
+ @Test | |
+ void testArgumentsAreNotFinalInCompact() { | |
assertOK( | |
""" | |
record R(int x) { | |
@@ -1078,14 +1095,16 @@ | |
"""); | |
} | |
- public void testNoNativeMethods() { | |
+ @Test | |
+ void testNoNativeMethods() { | |
assertFail("compiler.err.mod.not.allowed.here", "record R(int x) { # }", | |
"public native R {}"); | |
assertFail("compiler.err.mod.not.allowed.here", "record R(int x) { # }", | |
"public native void m();"); | |
} | |
- public void testRecordsInsideInner() { | |
+ @Test | |
+ void testRecordsInsideInner() { | |
assertOK( | |
""" | |
class Outer { | |
@@ -1126,7 +1145,8 @@ | |
"""); | |
} | |
- public void testAnnoInsideLocalOrAnonymous() { | |
+ @Test | |
+ void testAnnoInsideLocalOrAnonymous() { | |
assertFail("compiler.err.annotation.decl.not.allowed.here", | |
""" | |
class Outer { | |
@@ -1230,7 +1250,8 @@ | |
"""); | |
} | |
- public void testReceiverParameter() { | |
+ @Test | |
+ void testReceiverParameter() { | |
assertFail("compiler.err.receiver.parameter.not.applicable.constructor.toplevel.class", | |
""" | |
record R(int i) { | |
@@ -1258,7 +1279,8 @@ | |
"""); | |
} | |
- public void testOnlyOneFieldRef() throws Exception { | |
+ @Test | |
+ void testOnlyOneFieldRef() throws Exception { | |
for (String source : List.of( | |
"record R(int recordComponent) {}", | |
""" | |
@@ -1309,7 +1331,8 @@ | |
// check that fields are initialized in a canonical constructor in the same declaration order as the corresponding | |
// record component | |
- public void testCheckInitializationOrderInCompactConstructor() throws Exception { | |
+ @Test | |
+ void testCheckInitializationOrderInCompactConstructor() throws Exception { | |
int putField1 = -1; | |
int putField2 = -1; | |
File dir = assertOK(true, "record R(int i, String s) { R {} }"); | |
@@ -1347,7 +1370,8 @@ | |
} | |
} | |
- public void testAcceptRecordId() { | |
+ @Test | |
+ void testAcceptRecordId() { | |
String[] previousOptions = getCompileOptions(); | |
try { | |
String[] testOptions = {}; | |
@@ -1364,7 +1388,8 @@ | |
} | |
} | |
- public void testMultipleAnnosInRecord() throws Exception { | |
+ @Test | |
+ void testMultipleAnnosInRecord() throws Exception { | |
String[] previousOptions = getCompileOptions(); | |
try { | |
@@ -1405,7 +1430,8 @@ | |
} | |
} | |
- public void testAnnos() throws Exception { | |
+ @Test | |
+ void testAnnos() throws Exception { | |
String[] previousOptions = getCompileOptions(); | |
try { | |
String srcTemplate = | |
@@ -1568,7 +1594,8 @@ | |
// JDK-8292159: TYPE_USE annotations on generic type arguments | |
// of record components discarded | |
- public void testOnlyTypeAnnotationsOnComponentField() throws Exception { | |
+ @Test | |
+ void testOnlyTypeAnnotationsOnComponentField() throws Exception { | |
String code = | |
""" | |
import java.lang.annotation.*; | |
@@ -1783,7 +1810,8 @@ | |
} | |
} | |
- public void testMethodsInheritedFromRecordArePublicAndFinal() throws Exception { | |
+ @Test | |
+ void testMethodsInheritedFromRecordArePublicAndFinal() throws Exception { | |
int numberOfFieldRefs = 0; | |
File dir = assertOK(true, "record R() {}"); | |
for (final File fileEntry : dir.listFiles()) { | |
@@ -1802,7 +1830,8 @@ | |
private static final List<String> ACCESSIBILITY = List.of( | |
"public", "protected", "", "private"); | |
- public void testCanonicalAccessibility() throws Exception { | |
+ @Test | |
+ void testCanonicalAccessibility() throws Exception { | |
// accessibility of canonical can't be stronger than that of the record type | |
for (String a1 : ACCESSIBILITY) { | |
for (String a2 : ACCESSIBILITY) { | |
@@ -1853,7 +1882,8 @@ | |
} | |
} | |
- public void testSameArity() { | |
+ @Test | |
+ void testSameArity() { | |
for (String source : List.of( | |
""" | |
record R(int... args) { | |
@@ -1927,7 +1957,8 @@ | |
} | |
} | |
- public void testSafeVararsAnno() { | |
+ @Test | |
+ void testSafeVararsAnno() { | |
assertFail("compiler.err.annotation.type.not.applicable", | |
""" | |
@SafeVarargs | |
@@ -1989,7 +2020,8 @@ | |
); | |
} | |
- public void testOverrideAtAccessor() { | |
+ @Test | |
+ void testOverrideAtAccessor() { | |
assertOK( | |
""" | |
record R(int i) { | |
@@ -2027,7 +2059,8 @@ | |
); | |
} | |
- public void testNoAssigmentInsideCompactRecord() { | |
+ @Test | |
+ void testNoAssigmentInsideCompactRecord() { | |
assertFail("compiler.err.cant.assign.val.to.var", | |
""" | |
record R(int i) { | |
@@ -2048,7 +2081,8 @@ | |
); | |
} | |
- public void testNoNPEStaticAnnotatedFields() { | |
+ @Test | |
+ void testNoNPEStaticAnnotatedFields() { | |
assertOK( | |
""" | |
import java.lang.annotation.Native; | |
@@ -2081,7 +2115,8 @@ | |
); | |
} | |
- public void testDoNotAllowCStyleArraySyntaxForRecComponents() { | |
+ @Test | |
+ void testDoNotAllowCStyleArraySyntaxForRecComponents() { | |
assertFail("compiler.err.record.component.and.old.array.syntax", | |
""" | |
record R(int i[]) {} | |
@@ -2099,7 +2134,8 @@ | |
); | |
} | |
- public void testNoWarningForSerializableRecords() { | |
+ @Test | |
+ void testNoWarningForSerializableRecords() { | |
if (!useAP) { | |
// dont execute this test when the default annotation processor is on as it will fail due to | |
// spurious warnings | |
@@ -2114,7 +2150,8 @@ | |
} | |
} | |
- public void testAnnotationsOnVarargsRecComp() { | |
+ @Test | |
+ void testAnnotationsOnVarargsRecComp() { | |
assertOK( | |
""" | |
import java.lang.annotation.*; | |
@@ -2149,7 +2186,8 @@ | |
); | |
} | |
- public void testSaveVarargsAnno() { | |
+ @Test | |
+ void testSaveVarargsAnno() { | |
// the compiler would generate an erronous accessor | |
assertFail("compiler.err.varargs.invalid.trustme.anno", | |
""" | |
Index: test/langtools/tools/javac/sealed/SealedCompilationTests.java | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
diff --git a/test/langtools/tools/javac/sealed/SealedCompilationTests.java b/test/langtools/tools/javac/sealed/SealedCompilationTests.java | |
--- a/test/langtools/tools/javac/sealed/SealedCompilationTests.java (revision 5f9f0f606f9318452017129d3325c819380c190f) | |
+++ b/test/langtools/tools/javac/sealed/SealedCompilationTests.java (revision 7b1af0140a6819bc7837dfa18a39420f9ac1c8b6) | |
@@ -37,16 +37,10 @@ | |
* @run junit/othervm -DuseAP=true SealedCompilationTests | |
*/ | |
-import java.lang.constant.ClassDesc; | |
- | |
-import java.io.File; | |
- | |
import java.io.IOException; | |
import java.nio.file.Files; | |
import java.nio.file.Path; | |
import java.nio.file.Paths; | |
- | |
-import java.util.ArrayList; | |
import java.util.List; | |
import java.util.Set; | |
import java.util.stream.Collectors; | |
@@ -54,15 +48,13 @@ | |
import javax.annotation.processing.AbstractProcessor; | |
import javax.annotation.processing.RoundEnvironment; | |
import javax.annotation.processing.SupportedAnnotationTypes; | |
- | |
import javax.lang.model.element.TypeElement; | |
import javax.lang.model.SourceVersion; | |
import com.sun.tools.javac.util.Assert; | |
import org.junit.jupiter.api.Test; | |
-import org.junit.jupiter.api.extension.ExtendWith; | |
-import tools.javac.combo.*; | |
+import tools.javac.combo.CompilationTestCase; | |
import toolbox.ToolBox; | |
import toolbox.JavacTask; | |
@@ -71,7 +63,6 @@ | |
import static org.junit.jupiter.api.Assertions.fail; | |
-@ExtendWith(CompilationDiagnosticPrinter.class) | |
class SealedCompilationTests extends CompilationTestCase { | |
ToolBox tb = new ToolBox(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment