8379799: Upstream redundant diffs fixed in Valhalla - langtool tests 1

Reviewed-by: vromero
This commit is contained in:
Chen Liang 2026-03-12 17:58:06 +00:00
parent ebcfd7d623
commit a6f7089798
11 changed files with 45 additions and 16 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2026, 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
@ -112,6 +112,10 @@ public class CompilationTestCase extends JavacTemplateTestBase {
assertCompile(expandMarkers(constructs), () -> assertCompileSucceededWithWarning(warning), false);
}
protected void assertOKWithWarning(String warning, int numberOfTimes, String... constructs) {
assertCompile(expandMarkers(constructs), () -> assertCompileSucceededWithWarning(warning, numberOfTimes), false);
}
protected void assertFail(String expectedDiag, String... constructs) {
assertCompile(expandMarkers(constructs), () -> assertCompileFailed(expectedDiag), false);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2026, 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
@ -84,6 +84,12 @@ public class Diagnostics implements javax.tools.DiagnosticListener<JavaFileObjec
.anyMatch(d -> d.getCode().equals(key));
}
public boolean containsWarningKey(String key, int numberOfWarnings) {
return diags.stream()
.filter(d -> d.getKind() == Diagnostic.Kind.WARNING || d.getKind() == Diagnostic.Kind.MANDATORY_WARNING)
.filter(d -> d.getCode().equals(key)).count() == numberOfWarnings;
}
/** Get the error keys */
public List<String> errorKeys() {
return diags.stream()

View File

@ -154,6 +154,14 @@ public abstract class JavacTemplateTestBase {
}
}
protected void assertCompileSucceededWithWarning(String warning, int numberOfWarnings) {
if (diags.errorsFound())
fail("Expected successful compilation");
if (!diags.containsWarningKey(warning, numberOfWarnings)) {
fail(String.format("Expected compilation warning with %s, found %s", warning, diags.keys()));
}
}
/**
* If the provided boolean is true, assert all previous compiles succeeded,
* otherwise assert that a compile failed.

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2026, 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
@ -71,7 +71,7 @@ public class BridgeShouldHaveNoInteriorAnnotationsTest
};
// Expected output can't be directly encoded into NestedLambdasCastedTest !!!
// Expected output can't be directly encoded into BridgeShouldHaveNoInteriorAnnotationsTest !!!
static class OutputExpectedOnceHolder {
public String[] outputs = {
"0: #120(): CAST, offset=1, type_index=0, location=[TYPE_ARGUMENT(0)]",

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2026, 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
@ -45,12 +45,22 @@ import java.util.*;
/**
* Check invariants for a set of examples.
*
* READ THIS IF THIS TEST FAILS AFTER ADDING A NEW KEY TO 'compiler.properties':
* The 'examples' subdirectory contains a number of examples which provoke
* the reporting of most of the compiler message keys.
*
* -- each example should exactly declare the keys that will be generated when
* it is run.
* -- this is done by the "// key:"-comment in each fine.
* -- together, the examples should cover the set of resource keys in the
* compiler.properties bundle. A list of exceptions may be given in the
* not-yet.txt file. Entries on the not-yet.txt list should not be
* covered by examples.
* -- some keys are only reported by the compiler when specific options are
* supplied. For the purposes of this test, this can be specified by a
* comment e.g. like this: "// options: -Xlint:empty"
*
* When new keys are added to the resource bundle, it is strongly recommended
* that corresponding new examples be added here, if at all practical, instead
* of simply and lazily being added to the not-yet.txt list.

View File

@ -670,6 +670,7 @@ public class SourceLauncherTest extends TestRunner {
tb.writeJavaFiles(base, "public class Main { public static void main(String... args) {}}");
String log = new JavaTask(tb)
.vmOptions("--source", "21")
.includeStandardOptions(false) // Do not inherit --enable-preview
.className(base.resolve("Main.java").toString())
.run(Task.Expect.SUCCESS)
.getOutput(Task.OutputKind.STDERR);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2026, 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
@ -237,4 +237,4 @@ public class BreakAndLoops extends ComboInstance<BreakAndLoops> {
return code;
}
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2026, 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
@ -44,6 +44,8 @@ import java.nio.file.Paths;
import java.util.List;
public class PreviewAutoSuppress extends TestRunner {
// Major version number (e.g. '27').
private static final String FEATURE_VERSION = String.valueOf(Runtime.version().feature());
protected ToolBox tb;
@ -83,7 +85,7 @@ public class PreviewAutoSuppress extends TestRunner {
List<String> log = new JavacTask(tb, Task.Mode.CMDLINE)
.outdir(classes)
.options("--enable-preview",
"-source", String.valueOf(Runtime.version().feature()),
"-source", FEATURE_VERSION,
"-Xlint:preview",
"-XDforcePreview",
"-XDrawDiagnostics")
@ -182,7 +184,7 @@ public class PreviewAutoSuppress extends TestRunner {
"--add-exports", "java.base/preview.api=ALL-UNNAMED",
"--enable-preview",
"-Xlint:preview",
"-source", String.valueOf(Runtime.version().feature()),
"-source", FEATURE_VERSION,
"-XDrawDiagnostics")
.files(tb.findJavaFiles(testSrc))
.run()

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2026, 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
@ -31,7 +31,6 @@
* @run main RecordReading
*/
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2026, 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
@ -138,4 +138,4 @@ public class ClassBlockExits extends ComboInstance<ClassBlockExits> {
return code;
}
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2026, 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
@ -105,4 +105,3 @@ public class T4975569 {
protected class Prot { }
private class Priv { int i; }
}