changeset 9571:08cc0b3ce6cf

Updates to combo test framework from review of JDK-8015322
author briangoetz
date Thu, 29 Aug 2013 17:57:06 -0400
parents 69df9f78220f
children 843be828477e
files combo-tests/tests/tools/javac/combo/BridgeMethodTestCase.java combo-tests/tests/tools/javac/combo/Diagnostics.java combo-tests/tests/tools/javac/combo/JavacTemplateTestBase.java combo-tests/tests/tools/javac/combo/Template.java
diffstat 4 files changed, 48 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/combo-tests/tests/tools/javac/combo/BridgeMethodTestCase.java	Thu Aug 29 14:49:06 2013 -0700
+++ b/combo-tests/tests/tools/javac/combo/BridgeMethodTestCase.java	Thu Aug 29 17:57:06 2013 -0400
@@ -102,7 +102,14 @@
         compileSpec(spec, false);
     }
 
-    protected void compileSpec(String spec, boolean debug) throws IOException {
+    /**
+     * Compile all the classes in a class spec, and assert that there were compilation errors.
+     */
+    protected void compileSpec(String spec, String... errorKeys) throws IOException {
+        compileSpec(spec, false, errorKeys);
+    }
+
+    protected void compileSpec(String spec, boolean debug, String... errorKeys) throws IOException {
         ClassModel cm = new Parser(spec).parseClassModel();
         for (int i = 0; i <= cm.maxIndex() ; i++) {
             if (debug) System.out.println(indexClass(i));
@@ -114,7 +121,10 @@
         }
         compileDirs.add(compile(true));
         resetSourceFiles();
-        assertCompileSucceeded();
+        if (errorKeys.length == 0)
+            assertCompileSucceeded();
+        else
+            assertCompileErrors(errorKeys);
     }
 
     /**
--- a/combo-tests/tests/tools/javac/combo/Diagnostics.java	Thu Aug 29 14:49:06 2013 -0700
+++ b/combo-tests/tests/tools/javac/combo/Diagnostics.java	Thu Aug 29 17:57:06 2013 -0400
@@ -29,6 +29,8 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import static java.util.stream.Collectors.toList;
+
 /**
 * A container for compiler diagnostics, separated into errors and warnings,
  * used by JavacTemplateTestBase.
@@ -37,42 +39,46 @@
 */
 public class Diagnostics implements javax.tools.DiagnosticListener<JavaFileObject> {
 
-    protected List<String> errors = new ArrayList<>();
-    protected List<String> warnings = new ArrayList<>();
+    protected List<Diagnostic<? extends JavaFileObject>> diags = new ArrayList<>();
+    protected boolean foundErrors = false;
 
     public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
-        switch (diagnostic.getKind()) {
-            case ERROR:
-                errors.add(diagnostic.getCode());
-                break;
-
-            case WARNING:
-            case MANDATORY_WARNING:
-                warnings.add(diagnostic.getCode());
-                break;
-        }
+        diags.add(diagnostic);
+        foundErrors = foundErrors || diagnostic.getKind() == Diagnostic.Kind.ERROR;
     }
 
     /** Were there any errors found? */
     public boolean errorsFound() {
-        return !errors.isEmpty();
+        return foundErrors;
     }
 
-    /** How many errors were found? */
-    public int getErrorCount() {
-        return errors.size();
+    /** Get all diagnostic keys */
+    public List<String> keys() {
+        return diags.stream()
+                    .map(Diagnostic::getCode)
+                    .collect(toList());
+    }
+
+    /** Do the diagnostics contain the specified error key? */
+    public boolean containsErrorKey(String key) {
+        return diags.stream()
+                    .filter(d -> d.getKind() == Diagnostic.Kind.ERROR)
+                    .anyMatch(d -> d.getCode().equals(key));
     }
 
     /** Get the error keys */
-    public List<String> errors() {
-        return errors;
+    public List<String> errorKeys() {
+        return diags.stream()
+                    .filter(d -> d.getKind() == Diagnostic.Kind.ERROR)
+                    .map(Diagnostic::getCode)
+                    .collect(toList());
     }
 
-    public String toString() { return errors.toString(); }
+    public String toString() { return keys().toString(); }
 
     /** Clear all diagnostic state */
     public void reset() {
-        errors.clear();
-        warnings.clear();
+        diags.clear();
+        foundErrors = false;
     }
 }
--- a/combo-tests/tests/tools/javac/combo/JavacTemplateTestBase.java	Thu Aug 29 14:49:06 2013 -0700
+++ b/combo-tests/tests/tools/javac/combo/JavacTemplateTestBase.java	Thu Aug 29 17:57:06 2013 -0400
@@ -145,14 +145,14 @@
     @AfterMethod
     public void copyErrors(ITestResult result) {
         if (!result.isSuccess()) {
-            suiteErrors.addAll(diags.errors());
+            suiteErrors.addAll(diags.errorKeys());
 
             List<Object> list = new ArrayList<>();
             Collections.addAll(list, result.getParameters());
             list.add("Test case: " + getTestCaseDescription());
             for (Pair<String, Template> e : sourceFiles)
                 list.add("Source file " + e.fst + ": " + e.snd);
-            if (diags.getErrorCount() != 0)
+            if (diags.errorsFound())
                 list.add("Compile diagnostics: " + diags.toString());
             result.setParameters(list.toArray(new Object[list.size()]));
         }
@@ -207,7 +207,7 @@
         if (!diags.errorsFound())
             fail("Expected failed compilation");
         for (String k : keys)
-            if (!diags.errors().contains(k))
+            if (!diags.containsErrorKey(k))
                 fail("Expected compilation error " + k);
     }
 
--- a/combo-tests/tests/tools/javac/combo/Template.java	Thu Aug 29 14:49:06 2013 -0700
+++ b/combo-tests/tests/tools/javac/combo/Template.java	Thu Aug 29 17:57:06 2013 -0400
@@ -25,7 +25,6 @@
 package tools.javac.combo;
 
 import java.util.Map;
-import java.util.Objects;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -41,6 +40,12 @@
     }
 
     public static class Behavior {
+        /* Looks for expandable keys.  An expandable key can take the form:
+         *   #{MAJOR}
+         *   #{MAJOR.MINOR}
+         *   where MAJOR can be IDENTIFIER or IDENTIFIER[NUMERIC_INDEX]
+         *   and MINOR can be an identifier
+         */
         private static final Pattern pattern = Pattern.compile("#\\{([A-Z_][A-Z0-9_]*(?:\\[\\d+\\])?)(?:\\.([A-Z0-9_]*))?\\}");
 
         public static String expandTemplate(String template, final Map<String, Template> vars) {