Skip to content
This repository has been archived by the owner on Aug 27, 2022. It is now read-only.

Commit

Permalink
8235339: test TargetAnnoCombo.java is failing after new target RECORD…
Browse files Browse the repository at this point in the history
…_COMPONENT was added

Reviewed-by: darcy
  • Loading branch information
Vicente Romero committed Mar 14, 2020
1 parent b019469 commit f819e41
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 38 deletions.
Expand Up @@ -157,6 +157,9 @@ protected Check(Context context) {
enforceMandatoryWarnings, "sunapi", null);

deferredLintHandler = DeferredLintHandler.instance(context);

allowRecords = (!preview.isPreview(Feature.RECORDS) || preview.isEnabled()) &&
Feature.RECORDS.allowedInSource(source);
}

/** Character for synthetic names
Expand Down Expand Up @@ -188,6 +191,10 @@ protected Check(Context context) {
*/
private DeferredLintHandler deferredLintHandler;

/** Are records allowed
*/
private final boolean allowRecords;

/* *************************************************************************
* Errors and Warnings
**************************************************************************/
Expand Down Expand Up @@ -3164,7 +3171,9 @@ private Set<Name> getDefaultTargetSet() {
targets.add(names.ANNOTATION_TYPE);
targets.add(names.CONSTRUCTOR);
targets.add(names.FIELD);
targets.add(names.RECORD_COMPONENT);
if (allowRecords) {
targets.add(names.RECORD_COMPONENT);
}
targets.add(names.LOCAL_VARIABLE);
targets.add(names.METHOD);
targets.add(names.PACKAGE);
Expand Down
3 changes: 1 addition & 2 deletions test/langtools/ProblemList.txt
@@ -1,6 +1,6 @@
###########################################################################
#
# Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2015, 2020, 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
Expand Down Expand Up @@ -55,7 +55,6 @@ tools/javac/warnings/suppress/TypeAnnotations.java
tools/javac/modules/SourceInSymlinkTest.java 8180263 windows-all fails when run on a subst drive
tools/javac/importscope/T8193717.java 8203925 generic-all the test requires too much memory
tools/javac/options/BCPOrSystemNotSpecified.java 8231179 windows-all fails when creating a test bootclasspath
tools/javac/annotations/repeatingAnnotations/combo/TargetAnnoCombo.java 8235339 generic-all fails after new annotation target RECORD_COMPONENT was introduced

###########################################################################
#
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2020, 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
Expand Down Expand Up @@ -96,6 +96,10 @@ public static boolean compileCode(String className, String contents,
static File destDir = new File(System.getProperty("user.dir"));

public static boolean compileCode(DiagnosticCollector<JavaFileObject> diagnostics, Iterable<? extends JavaFileObject> files) {
return compileCode(diagnostics, files, null);
}

public static boolean compileCode(DiagnosticCollector<JavaFileObject> diagnostics, Iterable<? extends JavaFileObject> files, Iterable<String> options) {
boolean ok = false;
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
if (compiler == null) {
Expand All @@ -105,7 +109,7 @@ public static boolean compileCode(DiagnosticCollector<JavaFileObject> diagnostic
try (StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null)) {
// Assuming filesCount can maximum be 2 and if true, one file is package-info.java
if (isPkgInfoPresent(files)) {
JavacTask task = (JavacTask) compiler.getTask(null, fm, diagnostics, null, null, files);
JavacTask task = (JavacTask) compiler.getTask(null, fm, diagnostics, options, null, files);
try {
fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(destDir));
task.generate();
Expand All @@ -120,7 +124,7 @@ public static boolean compileCode(DiagnosticCollector<JavaFileObject> diagnostic
}
ok = (err == 0);
} else {
CompilationTask task = compiler.getTask(null, null, diagnostics, null, null, files);
CompilationTask task = compiler.getTask(null, null, diagnostics, options, null, files);
ok = task.call();
}
return ok;
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2020, 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
Expand Down Expand Up @@ -66,7 +66,7 @@ public class TargetAnnoCombo {
final static Set<ElementType> empty = EnumSet.noneOf(ElementType.class);

// [TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR, LOCAL_VARIABLE, ANNOTATION_TYPE,
// PACKAGE, TYPE_PARAMETER, TYPE_USE]
// PACKAGE, TYPE_PARAMETER, TYPE_USE, RECORD_COMPONENT]
final static Set<ElementType> allTargets = EnumSet.allOf(ElementType.class);

// [TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR, LOCAL_VARIABLE, ANNOTATION_TYPE,
Expand All @@ -93,16 +93,22 @@ private class TestCase {
private Set<ElementType> baseAnnotations;
private Set<ElementType> containerAnnotations;
private IgnoreKind ignore;
java.util.List<String> options;

public TestCase(Set<ElementType> baseAnnotations, Set<ElementType> containerAnnotations) {
this(baseAnnotations, containerAnnotations, IgnoreKind.RUN);
this(baseAnnotations, containerAnnotations, IgnoreKind.RUN, null);
}

public TestCase(Set<ElementType> baseAnnotations, Set<ElementType> containerAnnotations, List<String> options) {
this(baseAnnotations, containerAnnotations, IgnoreKind.RUN, options);
}

public TestCase(Set<ElementType> baseAnnotations, Set<ElementType> containerAnnotations,
IgnoreKind ignoreKind) {
IgnoreKind ignoreKind, java.util.List<String> options) {
this.baseAnnotations = baseAnnotations;
this.containerAnnotations = containerAnnotations;
this.ignore = ignoreKind;
this.options = options;
}

public Set getBaseAnnotations() {
Expand Down Expand Up @@ -198,6 +204,12 @@ public static void main(String args[]) throws Exception {
}
}

// options to be passed if all targets, including RECORD_COMPONENTS, are to be considered
List<String> previewOptions = List.of(
"--enable-preview",
"-source", Integer.toString(Runtime.version().feature())
);

private void generate() {
// Adding test cases to run.
testCases.addAll(Arrays.asList(
Expand Down Expand Up @@ -257,7 +269,7 @@ private void generate() {
// No container against jdk7 targets plus one or both of TYPE_USE, TYPE_PARAMETER
new TestCase(plus(jdk7, TYPE_USE), noSet),
new TestCase(plus(jdk7, TYPE_PARAMETER), noSet),
new TestCase(allTargets, noSet),
new TestCase(allTargets, noSet, previewOptions),
// Empty container target against any lone target.
new TestCase(plus(empty, TYPE), empty),
new TestCase(plus(empty, PARAMETER), empty),
Expand All @@ -270,34 +282,34 @@ private void generate() {
new TestCase(plus(empty, TYPE_USE), empty),
new TestCase(plus(empty, TYPE_PARAMETER), empty),
// All base targets against all container targets.
new TestCase(allTargets, allTargets),
new TestCase(allTargets, allTargets, previewOptions),
// All base targets against all but one container targets.
new TestCase(allTargets, less(allTargets, TYPE)),
new TestCase(allTargets, less(allTargets, PARAMETER)),
new TestCase(allTargets, less(allTargets, PACKAGE)),
new TestCase(allTargets, less(allTargets, METHOD)),
new TestCase(allTargets, less(allTargets, LOCAL_VARIABLE)),
new TestCase(allTargets, less(allTargets, FIELD)),
new TestCase(allTargets, less(allTargets, CONSTRUCTOR)),
new TestCase(allTargets, less(allTargets, ANNOTATION_TYPE)),
new TestCase(allTargets, less(allTargets, TYPE_USE)),
new TestCase(allTargets, less(allTargets, TYPE_PARAMETER)),
new TestCase(allTargets, less(allTargets, TYPE), previewOptions),
new TestCase(allTargets, less(allTargets, PARAMETER), previewOptions),
new TestCase(allTargets, less(allTargets, PACKAGE), previewOptions),
new TestCase(allTargets, less(allTargets, METHOD), previewOptions),
new TestCase(allTargets, less(allTargets, LOCAL_VARIABLE), previewOptions),
new TestCase(allTargets, less(allTargets, FIELD), previewOptions),
new TestCase(allTargets, less(allTargets, CONSTRUCTOR), previewOptions),
new TestCase(allTargets, less(allTargets, ANNOTATION_TYPE), previewOptions),
new TestCase(allTargets, less(allTargets, TYPE_USE), previewOptions),
new TestCase(allTargets, less(allTargets, TYPE_PARAMETER), previewOptions),
// All container targets against all but one base targets.
new TestCase(less(allTargets, TYPE), allTargets),
new TestCase(less(allTargets, PARAMETER), allTargets),
new TestCase(less(allTargets, PACKAGE), allTargets),
new TestCase(less(allTargets, METHOD), allTargets),
new TestCase(less(allTargets, LOCAL_VARIABLE), allTargets),
new TestCase(less(allTargets, FIELD), allTargets),
new TestCase(less(allTargets, CONSTRUCTOR), allTargets),
new TestCase(less(allTargets, ANNOTATION_TYPE), allTargets),
new TestCase(less(allTargets, TYPE_USE), allTargets),
new TestCase(less(allTargets, TYPE_PARAMETER), allTargets)));
new TestCase(less(allTargets, TYPE), allTargets, previewOptions),
new TestCase(less(allTargets, PARAMETER), allTargets, previewOptions),
new TestCase(less(allTargets, PACKAGE), allTargets, previewOptions),
new TestCase(less(allTargets, METHOD), allTargets, previewOptions),
new TestCase(less(allTargets, LOCAL_VARIABLE), allTargets, previewOptions),
new TestCase(less(allTargets, FIELD), allTargets, previewOptions),
new TestCase(less(allTargets, CONSTRUCTOR), allTargets, previewOptions),
new TestCase(less(allTargets, ANNOTATION_TYPE), allTargets, previewOptions),
new TestCase(less(allTargets, TYPE_USE), allTargets, previewOptions),
new TestCase(less(allTargets, TYPE_PARAMETER), allTargets, previewOptions)));
// Generates 100 test cases for any lone base target contained in Set
// allTargets against any lone container target.
for (ElementType b : allTargets) {
for (ElementType c : allTargets) {
testCases.add(new TestCase(plus(empty, b), plus(empty, c)));
testCases.add(new TestCase(plus(empty, b), plus(empty, c), previewOptions));
}
}
}
Expand Down Expand Up @@ -325,7 +337,7 @@ private void executeTestCase(TestCase testCase, int index) {
boolean shouldCompile = testCase.isValidSubSet();
Iterable<? extends JavaFileObject> files = getFileList(className, testCase, shouldCompile);
// Get result of compiling test src file(s).
boolean result = getCompileResult(className, shouldCompile, files);
boolean result = getCompileResult(className, shouldCompile, files, testCase.options);
// List test src code if test fails.
if (!result) {
System.out.println("FAIL: Test " + index);
Expand Down Expand Up @@ -420,11 +432,11 @@ private Iterable<? extends JavaFileObject> getFileList(String className,

// Compile the test source file(s) and return test result.
private boolean getCompileResult(String className, boolean shouldCompile,
Iterable<? extends JavaFileObject> files) {
Iterable<? extends JavaFileObject> files, Iterable<String> options) {

DiagnosticCollector<JavaFileObject> diagnostics =
new DiagnosticCollector<JavaFileObject>();
Helper.compileCode(diagnostics, files);
Helper.compileCode(diagnostics, files, options);
// Test case pass or fail.
boolean ok = false;
String errMesg = "";
Expand All @@ -440,8 +452,13 @@ private boolean getCompileResult(String className, boolean shouldCompile,
} else {
if (shouldCompile) {
// did not compile.
errMesg = "Test failed, did not compile.";
ok = false;
List<Diagnostic<? extends JavaFileObject>> allDiagnostics = diagnostics.getDiagnostics();
if (allDiagnostics.stream().noneMatch(d -> d.getKind() == javax.tools.Diagnostic.Kind.ERROR)) {
ok = true;
} else {
errMesg = "Test failed, compiled unexpectedly.";
ok = false;
}
} else {
// Error in compilation as expected.
String expectedErrKey = "compiler.err.invalid.repeatable."
Expand Down

0 comments on commit f819e41

Please sign in to comment.