Skip to content

Commit

Permalink
Extract a test helper in ProcessingIntegrationTest
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 664848121
  • Loading branch information
cushon authored and Javac Team committed Aug 19, 2024
1 parent 1ed4779 commit 0aefc1d
Showing 1 changed file with 31 additions and 142 deletions.
173 changes: 31 additions & 142 deletions javatests/com/google/turbine/processing/ProcessingIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import com.google.turbine.binder.Binder;
import com.google.turbine.binder.Binder.BindingResult;
import com.google.turbine.binder.ClassPathBinder;
import com.google.turbine.binder.Processing;
import com.google.turbine.binder.Processing.ProcessorInfo;
import com.google.turbine.binder.sym.ClassSymbol;
import com.google.turbine.diag.SourceFile;
Expand All @@ -61,6 +60,7 @@
import java.util.jar.JarOutputStream;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.ProcessingEnvironment;
import javax.annotation.processing.Processor;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.lang.model.SourceVersion;
Expand Down Expand Up @@ -107,20 +107,7 @@ public void crash() throws IOException {
"@Deprecated",
"class Test extends NoSuch {",
"}");
TurbineError e =
assertThrows(
TurbineError.class,
() ->
Binder.bind(
units,
ClassPathBinder.bindClasspath(ImmutableList.of()),
Processing.ProcessorInfo.create(
ImmutableList.of(new CrashingProcessor()),
getClass().getClassLoader(),
ImmutableMap.of(),
SourceVersion.latestSupported()),
TestClassPaths.TURBINE_BOOTCLASSPATH,
Optional.empty()));
TurbineError e = runProcessors(units, new CrashingProcessor());
ImmutableList<String> messages =
e.diagnostics().stream().map(TurbineDiagnostic::message).collect(toImmutableList());
assertThat(messages).hasSize(2);
Expand Down Expand Up @@ -167,20 +154,7 @@ public void warnings() throws IOException {
"@Deprecated",
"class Test {",
"}");
TurbineError e =
assertThrows(
TurbineError.class,
() ->
Binder.bind(
units,
ClassPathBinder.bindClasspath(ImmutableList.of()),
Processing.ProcessorInfo.create(
ImmutableList.of(new WarningProcessor()),
getClass().getClassLoader(),
ImmutableMap.of(),
SourceVersion.latestSupported()),
TestClassPaths.TURBINE_BOOTCLASSPATH,
Optional.empty()));
TurbineError e = runProcessors(units, new WarningProcessor());
ImmutableList<String> diags =
e.diagnostics().stream().map(d -> d.message()).collect(toImmutableList());
assertThat(diags).hasSize(2);
Expand Down Expand Up @@ -410,20 +384,7 @@ public void errorsAndFinalRound() throws IOException {
"@Deprecated",
"class Test {",
"}");
TurbineError e =
assertThrows(
TurbineError.class,
() ->
Binder.bind(
units,
ClassPathBinder.bindClasspath(ImmutableList.of()),
Processing.ProcessorInfo.create(
ImmutableList.of(new ErrorProcessor(), new FinalRoundErrorProcessor()),
getClass().getClassLoader(),
ImmutableMap.of(),
SourceVersion.latestSupported()),
TestClassPaths.TURBINE_BOOTCLASSPATH,
Optional.empty()));
TurbineError e = runProcessors(units, new ErrorProcessor(), new FinalRoundErrorProcessor());
ImmutableList<String> diags =
e.diagnostics().stream().map(d -> d.message()).collect(toImmutableList());
assertThat(diags)
Expand Down Expand Up @@ -463,20 +424,7 @@ public void superType() throws IOException {
"@Deprecated",
"class T extends S {",
"}");
TurbineError e =
assertThrows(
TurbineError.class,
() ->
Binder.bind(
units,
ClassPathBinder.bindClasspath(ImmutableList.of()),
Processing.ProcessorInfo.create(
ImmutableList.of(new SuperTypeProcessor()),
getClass().getClassLoader(),
ImmutableMap.of(),
SourceVersion.latestSupported()),
TestClassPaths.TURBINE_BOOTCLASSPATH,
Optional.empty()));
TurbineError e = runProcessors(units, new SuperTypeProcessor());
ImmutableList<String> diags =
e.diagnostics().stream().map(d -> d.message()).collect(toImmutableList());
assertThat(diags).containsExactly("could not resolve S", "S [S]").inOrder();
Expand Down Expand Up @@ -558,20 +506,7 @@ public void qualifiedErrorType() throws IOException {
"=== T.java ===", //
"class T extends G.I {",
"}");
TurbineError e =
assertThrows(
TurbineError.class,
() ->
Binder.bind(
units,
ClassPathBinder.bindClasspath(ImmutableList.of()),
ProcessorInfo.create(
ImmutableList.of(new GenerateQualifiedProcessor()),
getClass().getClassLoader(),
ImmutableMap.of(),
SourceVersion.latestSupported()),
TestClassPaths.TURBINE_BOOTCLASSPATH,
Optional.empty()));
TurbineError e = runProcessors(units, new GenerateQualifiedProcessor());
assertThat(
e.diagnostics().stream()
.filter(d -> d.severity().equals(Diagnostic.Kind.NOTE))
Expand Down Expand Up @@ -609,20 +544,7 @@ public void badElementValue() throws IOException {
parseUnit(
"=== T.java ===", //
"@Deprecated(noSuch = 42) class T {}");
TurbineError e =
assertThrows(
TurbineError.class,
() ->
Binder.bind(
units,
ClassPathBinder.bindClasspath(ImmutableList.of()),
ProcessorInfo.create(
ImmutableList.of(new ElementValueInspector()),
getClass().getClassLoader(),
ImmutableMap.of(),
SourceVersion.latestSupported()),
TestClassPaths.TURBINE_BOOTCLASSPATH,
Optional.empty()));
TurbineError e = runProcessors(units, new ElementValueInspector());
assertThat(
e.diagnostics().stream()
.filter(d -> d.severity().equals(Diagnostic.Kind.ERROR))
Expand Down Expand Up @@ -665,20 +587,7 @@ public void recordProcessing() throws IOException {
parseUnit(
"=== R.java ===", //
"record R<T>(@Deprecated T x, int... y) {}");
TurbineError e =
assertThrows(
TurbineError.class,
() ->
Binder.bind(
units,
ClassPathBinder.bindClasspath(ImmutableList.of()),
ProcessorInfo.create(
ImmutableList.of(new RecordProcessor()),
getClass().getClassLoader(),
ImmutableMap.of(),
SourceVersion.latestSupported()),
TestClassPaths.TURBINE_BOOTCLASSPATH,
Optional.empty()));
TurbineError e = runProcessors(units, new RecordProcessor());
assertThat(
e.diagnostics().stream()
.filter(d -> d.severity().equals(Diagnostic.Kind.ERROR))
Expand All @@ -703,21 +612,11 @@ public void missingElementValue() {
"import java.lang.annotation.Retention;",
"@Retention() @interface T {}");
TurbineError e =
assertThrows(
TurbineError.class,
() ->
Binder.bind(
units,
ClassPathBinder.bindClasspath(ImmutableList.of()),
ProcessorInfo.create(
// missing annotation arguments are not a recoverable error, annotation
// processing shouldn't happen
ImmutableList.of(new CrashingProcessor()),
getClass().getClassLoader(),
ImmutableMap.of(),
SourceVersion.latestSupported()),
TestClassPaths.TURBINE_BOOTCLASSPATH,
Optional.empty()));
runProcessors(
units,
// missing annotation arguments are not a recoverable error, annotation processing
// shouldn't happen
new CrashingProcessor());
assertThat(e.diagnostics().stream().map(d -> d.message()))
.containsExactly("missing required annotation argument: value");
}
Expand Down Expand Up @@ -796,20 +695,7 @@ public void bound() {
" return super.f(list);",
" }",
"}");
TurbineError e =
assertThrows(
TurbineError.class,
() ->
Binder.bind(
units,
ClassPathBinder.bindClasspath(ImmutableList.of()),
ProcessorInfo.create(
ImmutableList.of(new AllMethodsProcessor()),
getClass().getClassLoader(),
ImmutableMap.of(),
SourceVersion.latestSupported()),
TestClassPaths.TURBINE_BOOTCLASSPATH,
Optional.empty()));
TurbineError e = runProcessors(units, new AllMethodsProcessor());
assertThat(e.diagnostics().stream().map(d -> d.message()))
.containsExactly(
"A#f<U>(java.util.List<U>)U <: B#f<U>(java.util.List<U>)U ? false",
Expand Down Expand Up @@ -855,20 +741,7 @@ public void uriProcessing() throws IOException {
parseUnit(
"=== T.java ===", //
"class T {}");
TurbineError e =
assertThrows(
TurbineError.class,
() ->
Binder.bind(
units,
ClassPathBinder.bindClasspath(ImmutableList.of()),
ProcessorInfo.create(
ImmutableList.of(new URIProcessor()),
getClass().getClassLoader(),
ImmutableMap.of(),
SourceVersion.latestSupported()),
TestClassPaths.TURBINE_BOOTCLASSPATH,
Optional.empty()));
TurbineError e = runProcessors(units, new URIProcessor());
assertThat(
e.diagnostics().stream()
.filter(d -> d.severity().equals(Diagnostic.Kind.ERROR))
Expand Down Expand Up @@ -945,4 +818,20 @@ public void missingAnnotationType() throws IOException {
log.diagnostics().stream().map(TurbineDiagnostic::message).collect(toImmutableList());
assertThat(messages).containsExactly("A(ERROR)");
}

private TurbineError runProcessors(ImmutableList<Tree.CompUnit> units, Processor... processors) {
return assertThrows(
TurbineError.class,
() ->
Binder.bind(
units,
ClassPathBinder.bindClasspath(ImmutableList.of()),
ProcessorInfo.create(
ImmutableList.copyOf(processors),
getClass().getClassLoader(),
ImmutableMap.of(),
SourceVersion.latestSupported()),
TestClassPaths.TURBINE_BOOTCLASSPATH,
Optional.empty()));
}
}

0 comments on commit 0aefc1d

Please sign in to comment.