Closed natros closed 1 year ago
Thanks for this. I'll take a look a bit later and try getting a fix out today at some point. Do you happen to have the Gradle build script you were using, just to help me replicate this?
@natros thanks. Got it running on my PC and I can reproduce the issue too.
Really strange that it is not occurring during the build process for this repository.
I haven't got much experience using Gradle. I can use it if I need to but I tend to prefer Maven just because I have more exposure to it. Do you happen to know if Gradle does anything significantly different to maven-surefire as part of their test invocation process? If you don't, that is fine, I can have a look into it.
I think the issue is possibly just that we don't need to use @TestTemplate
though, so I'll have a fiddle around with this locally and try to find a fix. I'll drop a response once I get somewhere with it!
As a side note, I did notice a little mistake in the snippet you are trying to compile. It looks like I made this mistake when writing the README (which I updated a little earlier today to be correct). The correct test case you'll want to use is:
package demo;
import static io.github.ascopes.jct.assertions.JctAssertions.assertThatCompilation;
import io.github.ascopes.jct.compilers.JctCompiler;
import io.github.ascopes.jct.junit.JavacCompilerTest;
import io.github.ascopes.jct.junit.JctExtension;
import io.github.ascopes.jct.junit.Managed;
import io.github.ascopes.jct.workspaces.Workspace;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.extension.ExtendWith;
@DisplayName("Example tests")
@ExtendWith(JctExtension.class)
class ExampleTest {
@Managed Workspace workspace;
@DisplayName("I can compile a Hello World application")
@JavacCompilerTest
void canCompileHelloWorld(JctCompiler compiler) {
// Given
workspace
.createSourcePathPackage()
.createFile("org/example/Message.java")
.withContents(
"""
package org.example;
import lombok.Data;
import lombok.NonNull;
@Data
public class Message {
private final String content;
public static void main(String[] args) {
Message message = new Message("Hello, World!");
System.out.println(message);
}
}
""");
// When
var compilation = compiler.compile(workspace);
// Then
assertThatCompilation(compilation).isSuccessfulWithoutWarnings();
assertThatCompilation(compilation)
.classOutputPackages()
.fileExists("com/example/Message.class")
.isNotEmptyFile();
}
}
The difference is just that the content
field needs to be marked as final
otherwise Lombok will not enforce that it is part of a constructor.
Think this is going to take a bit more work. It looks like Gradle is not handling the meta-annotations for @ParameterizedTest
in the same way that Maven is doing in Maven Surefire, which is a fairly big pain as it means I need to implement parameterized test resolution from scratch.
My (semi-unfortunate) assumption was that Gradle would make use of the same APIs that Maven did for invocations of JUnit tests.
I don't think I am going to be able to get this working today, but I will try to get it done as soon as possible. I am working all week this week and then I am away for a week so I won't have access to a PC, but I will put this at the top of my priority list.
For now, the workaround is to avoid the JUnit integration and use the JctCompilers.newPlatformCompiler
API directly.
Thanks for taking the time to report this :-)
If this is the case, it will involve:
there is a missing dependency in gradle
testImplementation("org.junit.jupiter:junit-jupiter-params:5.9.3")
that in your pom file is optional
<dependency>
<!-- Used to provide convenience annotations -->
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<optional>true</optional>
</dependency>
there is no need for big changes
Oh, interesting, I totally missed that!
Does that fix your issue on your side?
If it does, do you want to submit a fix from your side? If not, I can take a look at updating it from my side when I am next at a PC.
It works, but I had to make a few adjustments. 👍
.fileExists("com/example/Message.class")
to .fileExists("org/example/Message.class")
Thanks. Lombok here was just an example of how it pulls through existing annotation processors on the classpath. But yeah, that package name definitely needs fixing. Good spot
I understand the intent. But the first thing anyone does is copy&paste the example to see it working. It's frustrating when that doesn't happen.
Will update the example. Thanks for the feedback!
I forgot to mention this last week as I had other non-work related stuff going on, but if you have any additional feedback or suggestions, please feel free to open a discussion or ticket!
Junit 5.9.3