[Patch] 8041793: javap misses newline after printing AnnotationDefault
Denis Istomin
istomin.den at gmail.com
Sun Jan 15 19:34:16 UTC 2017
Fixed test:
1. Using getOutputLines instead of getOutput
2. Using toolbox.Assert class with error message instead of throwing
simple "Error".
--
Denis Istomin
2017-01-14 7:50 GMT+05:00 Jonathan Gibbons <jonathan.gibbons at oracle.com>:
>
>
> On 01/13/2017 01:38 PM, Denis Istomin wrote:
>>
>> Hi,
>> Made patch for bug 8041793.
>>
>
> Hi Denis,
>
> The test will probably fail on Windows, because you are checking for the
> exact newline character "\n".
>
> There are two typical solutions to this general problem.
>
> 1. Take the string returned by the tool and normalize the newlines with code
> similar to
> out.replace(System.getProperty("line.separator"), "\n")
> The system property is also available as a constant within the ToolBox
> class.
>
> 2. Split the output into lines, perhaps by using the getOutputLines method
> instead of getOutput,
> and then compare the resulting list against an equivalent list for the
> expected output.
>
> Note there are occasions when it is important to verify that the exact
> platform line separator sequence
> is being used, and that will require different solutions.
>
>
> Your test is also somewhat terse, in that in the case of a problem, it just
> says "Error". We run thousands
> of tests every day on JDK builds, and when a test fails, it is helpful to
> have a test report something more.
> In this case, saying "Expected output not found" would be slightly better,
> and probably good enough.
> In cases where the expected output is bigger, it becomes more helpful to
> give more details about where
> the mismatch occurs. You don't need to provide a full diff (!), but at least
> an indication of the line number
> of the first mismatch would help focus the attention of the person who ends
> up having to examine why
> the test failed.
>
> -- Jon
-------------- next part --------------
# HG changeset patch
# User istomin
# Date 1484405746 -18000
# Sat Jan 14 19:55:46 2017 +0500
# Branch 8041793-javap-newline
# Node ID 1f932aa2b656c660c71b9e45c492606a8753f965
# Parent b6960e2da00806bb8a10c74dfdb73c2dac0f06bc
8041793: javap misses newline after printing AnnotationDefault
diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/javap/AttributeWriter.java b/src/jdk.jdeps/share/classes/com/sun/tools/javap/AttributeWriter.java
--- a/src/jdk.jdeps/share/classes/com/sun/tools/javap/AttributeWriter.java
+++ b/src/jdk.jdeps/share/classes/com/sun/tools/javap/AttributeWriter.java
@@ -164,6 +164,7 @@
print("default_value: ");
annotationWriter.write(attr.default_value);
indent(-1);
+ println();
return null;
}
diff --git a/test/tools/javap/typeAnnotations/AnnotationDefaultNewlineTest.java b/test/tools/javap/typeAnnotations/AnnotationDefaultNewlineTest.java
new file mode 100644
--- /dev/null
+++ b/test/tools/javap/typeAnnotations/AnnotationDefaultNewlineTest.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2013, 2016, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8041793
+ * @summary Verify that javap prints newline character after AnnotationDefault value
+ * @library /tools/lib
+ * @modules jdk.compiler/com.sun.tools.javac.api
+ * jdk.compiler/com.sun.tools.javac.main
+ * jdk.jdeps/com.sun.tools.javap
+ * @build toolbox.ToolBox toolbox.JavacTask toolbox.JavapTask toolbox.Assert
+ * @run main AnnotationDefaultNewlineTest
+ */
+
+import java.util.Collections;
+import java.util.List;
+
+import toolbox.Assert;
+import toolbox.JavacTask;
+import toolbox.JavapTask;
+import toolbox.Task;
+import toolbox.ToolBox;
+
+public class AnnotationDefaultNewlineTest {
+
+ private static final String TestSrc =
+ "public @interface AnnotationDefault { \n" +
+ "public abstract int value() default 1; \n" +
+ "}";
+
+ private static final String ExpectedSubstring =
+ " AnnotationDefault:\n" +
+ " default_value: I#7\n";
+
+ public static void main(String[] args) throws Exception {
+ ToolBox tb = new ToolBox();
+ new JavacTask(tb).sources(TestSrc).run();
+
+ List<String> res = new JavapTask(tb)
+ .options("-v")
+ .classes("AnnotationDefault.class")
+ .run()
+ .getOutputLines(Task.OutputKind.DIRECT);
+
+ List<String> goldenList = tb.split(ExpectedSubstring, "\n");
+ Boolean found = Collections.indexOfSubList(res, goldenList) > -1;
+
+ Assert.check(found, "expected output not found: " + ExpectedSubstring);
+ }
+}
More information about the compiler-dev
mailing list