Skip to content

Commit

Permalink
[#1939] Fix picocli-annotation-processing-tests failures on Java 16+
Browse files Browse the repository at this point in the history
rewrite tests to avoid Google `compiler-test` API that internally uses `com.sun.tools.javac.util.Context`

Closes #1939
  • Loading branch information
remkop committed Jan 27, 2023
1 parent 2151629 commit 2c1a60c
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 27 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Artifacts in this release are signed by Remko Popma (6601 E5C0 8DCC BB96).
* [#1910][#1917] DOC: Fix broken link to Zero Bug Commitment. Thanks to [Jiehong](https://github.com/Jiehong) for raising this and thanks to [Andreas Deininger](https://github.com/deining) for the pull request.
* [#1915] DOC: Improve default provider examples. Thanks to [David](https://github.com/DavidTheExplorer) for raising this.
* [#1918][#1920] DOC: Removed unused Travis CI badge and associated broken link from README. Thanks to [Andreas Deininger](https://github.com/deining) for raising this and the pull request.
* [#1939] BUILD: Fix `picocli-annotation-processing-tests` failures on Java 16+: rewrite tests to avoid Google `compiler-test` API that internally uses `com.sun.tools.javac.util.Context`.
* [#1887] DEP: Bump biz.aQute.bnd.gradle from 6.3.1 to 6.4.0
* [#1865] DEP: Bump ivy from 2.5.0 to 2.5.1
* [#1931] DEP: Bump springBootVersion from 2.7.5 to 3.0.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,67 +7,82 @@

import javax.tools.StandardLocation;

import java.io.IOException;

import static com.google.testing.compile.CompilationSubject.assertThat;
import static com.google.testing.compile.Compiler.javac;
import static org.junit.Assert.*;

public class AnnotatedCommandSourceGeneratorProcessorTest {

@Ignore
@Test
public void generate() {
public void generate() throws IOException {
AnnotatedCommandSourceGeneratorProcessor processor = new AnnotatedCommandSourceGeneratorProcessor();
Compilation compilation =
javac()
.withProcessors(processor)
.compile(JavaFileObjects.forResource(
"picocli/examples/subcommands/ParentCommandDemo.java"));
assertThat(compilation).succeeded();
assertThat(compilation)
.generatedSourceFile("GeneratedHelloWorld")
.hasSourceEquivalentTo(JavaFileObjects.forResource("GeneratedHelloWorld.java"));
// assertThat(compilation)
// .generatedSourceFile("GeneratedHelloWorld")
// .hasSourceEquivalentTo(JavaFileObjects.forResource("GeneratedHelloWorld.java"));
String generated1 = compilation.generatedFile(StandardLocation.SOURCE_OUTPUT, "GeneratedHelloWorld.java").get().getCharContent(false).toString();
String expected1 = JavaFileObjects.forResource("GeneratedHelloWorld.java").getCharContent(false).toString();
assertEquals(expected1.replaceAll("\\r?\\n", "\n"), generated1.replaceAll("\\r?\\n", "\n"));
}

@Test
public void generate1() {
public void generate1() throws IOException {
AnnotatedCommandSourceGeneratorProcessor processor = new AnnotatedCommandSourceGeneratorProcessor();
Compilation compilation =
javac()
.withProcessors(processor)
.compile(JavaFileObjects.forResource(
"picocli/codegen/aot/graalvm/Example.java"));
assertThat(compilation).succeeded();
assertThat(compilation)
.generatedFile(StandardLocation.SOURCE_OUTPUT, "generated/picocli/codegen/aot/graalvm/Example.java")
.hasSourceEquivalentTo(JavaFileObjects.forResource("generated/picocli/codegen/aot/graalvm/Example.java"));
// assertThat(compilation)
// .generatedFile(StandardLocation.SOURCE_OUTPUT, "generated/picocli/codegen/aot/graalvm/Example.java")
// .hasSourceEquivalentTo(JavaFileObjects.forResource("generated/picocli/codegen/aot/graalvm/Example.java"));
String generated1 = compilation.generatedFile(StandardLocation.SOURCE_OUTPUT, "generated/picocli/codegen/aot/graalvm/Example.java").get().getCharContent(false).toString();
String expected1 = JavaFileObjects.forResource("generated/picocli/codegen/aot/graalvm/Example.java").getCharContent(false).toString();
assertEquals(expected1.replaceAll("\\r?\\n", "\n"), generated1.replaceAll("\\r?\\n", "\n"));
}

//@Ignore("TODO field constant values")
@Test
public void generateNested() {
public void generateNested() throws IOException {
AnnotatedCommandSourceGeneratorProcessor processor = new AnnotatedCommandSourceGeneratorProcessor();
Compilation compilation =
javac()
.withProcessors(processor)
.compile(JavaFileObjects.forResource(
"picocli/examples/PopulateFlagsMain.java"));
assertThat(compilation).succeeded();
assertThat(compilation)
.generatedFile(StandardLocation.SOURCE_OUTPUT, "generated/picocli/examples/PopulateFlagsMain.java")
.hasSourceEquivalentTo(JavaFileObjects.forResource("generated/picocli/examples/PopulateFlagsMain.java"));
// assertThat(compilation)
// .generatedFile(StandardLocation.SOURCE_OUTPUT, "generated/picocli/examples/PopulateFlagsMain.java")
// .hasSourceEquivalentTo(JavaFileObjects.forResource("generated/picocli/examples/PopulateFlagsMain.java"));
String generated1 = compilation.generatedFile(StandardLocation.SOURCE_OUTPUT, "generated/picocli/examples/PopulateFlagsMain.java").get().getCharContent(false).toString();
String expected1 = JavaFileObjects.forResource("generated/picocli/examples/PopulateFlagsMain.java").getCharContent(false).toString();
assertEquals(expected1.replaceAll("\\r?\\n", "\n"), generated1.replaceAll("\\r?\\n", "\n"));
}

@Ignore
@Test
public void generateNested2() {
public void generateNested2() throws IOException {
AnnotatedCommandSourceGeneratorProcessor processor = new AnnotatedCommandSourceGeneratorProcessor();
Compilation compilation =
javac()
.withProcessors(processor)
.compile(JavaFileObjects.forResource(
"picocli/examples/subcommands/ParentCommandDemo.java"));
assertThat(compilation).succeeded();
assertThat(compilation)
.generatedFile(StandardLocation.SOURCE_OUTPUT, "generated/examples/subcommands/ParentCommandDemo.java")
.hasSourceEquivalentTo(JavaFileObjects.forResource("generated/examples/subcommands/ParentCommandDemo.java"));
// assertThat(compilation)
// .generatedFile(StandardLocation.SOURCE_OUTPUT, "generated/examples/subcommands/ParentCommandDemo.java")
// .hasSourceEquivalentTo(JavaFileObjects.forResource("generated/examples/subcommands/ParentCommandDemo.java"));
String generated1 = compilation.generatedFile(StandardLocation.SOURCE_OUTPUT, "generated/examples/subcommands/ParentCommandDemo.java").get().getCharContent(false).toString();
String expected1 = JavaFileObjects.forResource("generated/examples/subcommands/ParentCommandDemo.java").getCharContent(false).toString();
assertEquals(expected1.replaceAll("\\r?\\n", "\n"), generated1.replaceAll("\\r?\\n", "\n"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
import javax.annotation.processing.Processor;
import javax.tools.StandardLocation;

import java.io.IOException;

import static com.google.testing.compile.CompilationSubject.assertThat;
import static com.google.testing.compile.Compiler.javac;
import static org.junit.Assert.*;

public class Issue769Test {
@Test
Expand All @@ -24,7 +27,7 @@ public void testIssue769() {
}

@Test
public void testIssue769Details() {
public void testIssue769Details() throws IOException {
Processor processor = new AnnotatedCommandSourceGeneratorProcessor();
Compilation compilation =
javac()
Expand All @@ -33,12 +36,21 @@ public void testIssue769Details() {
"picocli/issue769/MyMixin.java"));

assertThat(compilation).succeeded();
assertThat(compilation)
.generatedFile(StandardLocation.SOURCE_OUTPUT, "generated/picocli/issue769/MyMixin.java")
.hasSourceEquivalentTo(JavaFileObjects.forResource("generated/picocli/issue769/MyMixin.java"));

assertThat(compilation)
.generatedFile(StandardLocation.SOURCE_OUTPUT, "generated/picocli/issue769/SubCommand.java")
.hasSourceEquivalentTo(JavaFileObjects.forResource("generated/picocli/issue769/SubCommand.java"));
// assertThat(compilation)
// .generatedFile(StandardLocation.SOURCE_OUTPUT, "generated/picocli/issue769/MyMixin.java")
// .hasSourceEquivalentTo(JavaFileObjects.forResource("generated/picocli/issue769/MyMixin.java"));

String generated1 = compilation.generatedFile(StandardLocation.SOURCE_OUTPUT, "generated/picocli/issue769/MyMixin.java").get().getCharContent(false).toString();
String expected1 = JavaFileObjects.forResource("generated/picocli/issue769/MyMixin.java").getCharContent(false).toString();
assertEquals(expected1.replaceAll("\\r?\\n", "\n"), generated1.replaceAll("\\r?\\n", "\n"));


// assertThat(compilation)
// .generatedFile(StandardLocation.SOURCE_OUTPUT, "generated/picocli/issue769/SubCommand.java")
// .hasSourceEquivalentTo(JavaFileObjects.forResource("generated/picocli/issue769/SubCommand.java"));
String generatedSub = compilation.generatedFile(StandardLocation.SOURCE_OUTPUT, "generated/picocli/issue769/SubCommand.java").get().getCharContent(false).toString();
String expectedSub = JavaFileObjects.forResource("generated/picocli/issue769/SubCommand.java").getCharContent(false).toString();
assertEquals(expectedSub.replaceAll("\\r?\\n", "\n"), generatedSub.replaceAll("\\r?\\n", "\n"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ private static class Options {
private boolean buffered;

@Option(names = "-o")
private boolean overwriteOutput; // TODO = true;
private boolean overwriteOutput;

@Option(names = "-v")
private boolean verbose;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@

@Command(name = "SubCommand")
class SubCommand {
@Mixin
MyMixin someMixin;
@Mixin MyMixin someMixin;
}

0 comments on commit 2c1a60c

Please sign in to comment.