rnpy
11/19/2018, 7:00 AMcompile-testing
library? (https://github.com/google/compile-testing)
currently I'm testing generated sources with a few regex, but that's really not optimal 😕Uzi Landsmann
11/19/2018, 7:18 AMrnpy
11/19/2018, 7:20 AMcompile-testing
when generating Java you can write tests like this:
Compilation compilation =
javac()
.withProcessors(new MyAnnotationProcessor())
.compile(JavaFileObjects.forResource("HelloWorld.java"));
assertThat(compilation).succeeded();
assertThat(compilation)
.generatedSourceFile("GeneratedHelloWorld")
.hasSourceEquivalentTo(JavaFileObjects.forResource("GeneratedHelloWorld.java"));
Or for errors:
JavaFileObject helloWorld = JavaFileObjects.forResource("HelloWorld.java");
Compilation compilation =
javac()
.withProcessors(new NoHelloWorld())
.compile(helloWorld);
assertThat(compilation).failed();
assertThat(compilation)
.hadErrorContaining("No types named HelloWorld!")
.inFile(helloWorld)
.onLine(23)
.atColumn(5);
compile-testing
to compile the code in my tests (writing the sources I compile in my tests in Java), but the processor generate Kotlin code, so I can use some features like error cases, but I can't use any java-specific things like generatedSourceFile
or hasSourceEquivalentTo
(both only handle Java stuff), instead I redirect the output and test it myself (with a few regexp)Uzi Landsmann
11/19/2018, 7:56 AM