-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for additional test-to-main directory mappings #11142
Conversation
Here is a reproducer: https://github.com/roguexz/quarkus-sample
|
cc @glefloch |
Gentlemen .. any suggestions regarding this proposal? |
One reason I hesitated to comment last week was that I wanted to check how far we can go with the workspace discovery in Gradle. I suspect we can discover the sources w/o the externally configured environment variable which if we add now we'll have to support later (at least for some time). |
Yes I agree with @aloubyansky, I think we can discover using the Gradle tooling API. |
Let me try this out. I think I had reviewed this code earlier, but let me see what I can do with it. There is always the catch of identifying a sourceSet that should be included as part of the test sources. |
@glefloch what's the status of this? |
As suggested by @aloubyansky we should by able to do that using the quarkus model instead of having to set an environment variable. |
I was tied up with other activities. Just rebased my code. Let me see if I can send a different test sources directory depending on the task being executed. |
87e2d73
to
b49c99f
Compare
@@ -99,6 +100,20 @@ | |||
File.separator + "test-classes", | |||
File.separator + "classes"); | |||
//endregion | |||
|
|||
String mappings = System.getenv("ADDITIONAL_TEST_TO_MAIN_MAPPINGS"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@glefloch Based on my analysis, if we want to keep the code impact to a minimum, then I will need to do the following,
- Identify the test sources and serialize it as part of the plugin (via the tooling API)
- Read that information in this class and associate the test-to-main mapping so that
isInTestDir
returns true
If this approach sounds good, then I can serialize it as part of the QuarkusPluginExtension.beforeTest() method.
Apart from the Gradle extension, is there any additional place that needs to be modified?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, actually, we are already scanning workspace here:
quarkus/devtools/gradle/src/main/java/io/quarkus/gradle/builder/QuarkusModelBuilder.java
Line 126 in 77b772c
private WorkspaceModule getWorkspaceModule(Project project, LaunchMode mode) { |
If you can add those source set here, you will be able to get them through the model used :
quarkus/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtension.java
Line 199 in 77b772c
BuildToolHelper.enableGradleAppModel(projectRoot, "TEST", QuarkusModelHelper.TEST_REQUIRED_TASKS); |
@glefloch - looks like your comment and my code push happened at the same time. I am looking at the codepaths that you mentioned and am a little lost. According to what I understand from the code in Additionally, with this approach we will end up adding all test source locations upfront, similar to what is being done right now in So, I have the logic .. I need some guidance to identify the correct approach for pushing this mapping to the test helper. |
@glefloch Should we take this conversation to Zulip? |
@glefloch & I discussed this issue. Guillaume said that he would look at why |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's ok until we figure out how to properly integrate the workspace model into the junit5 extension. Do you think you could add a test for this issue? Thanks @roguexz
devtools/gradle/src/main/java/io/quarkus/gradle/QuarkusPluginExtension.java
Outdated
Show resolved
Hide resolved
test-framework/common/src/main/java/io/quarkus/test/common/PathTestHelper.java
Outdated
Show resolved
Hide resolved
Incorporating the feedback and updating the PR (with functional-tests) |
devtools/gradle/build.gradle
Outdated
@@ -27,6 +27,17 @@ repositories { | |||
mavenCentral() | |||
} | |||
|
|||
sourceSets { | |||
// Functional Tests | |||
funcTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am verifying the capability as a functional test.
devtools/gradle/build.gradle
Outdated
systemProperty 'org.gradle.testkit.dir', file("${buildDir}/tmp/test-kit") | ||
} | ||
|
||
check.dependsOn functionalTest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The build
task depends on the check
task. So, mvn clean install
will in-turn trigger the functional tests
/* | ||
* Functional tests for this module. | ||
*/ | ||
task functionalTest(type: Test, description: 'Functional tests', dependsOn: [processResources, classes]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies for the name confusion. Here is what's happening.
mvn clean install
--executes--> gradle functionalTest
--runs-> AdditionalSourceSetsTest
--executes--> a Gradle build using this build file
--executes--> this task (which happens to be named as "functionalTest")
@aloubyansky @glefloch Do let me know if you have a different approach for the tests. |
@roguexz for this kind of feature, we usually create an integration test in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I commented the PR before starting a review. Your looks good. We used to have issues with test requiring the gradle plugin to be installed.
Can you move it to integration-test/gradle
module?
devtools/gradle/src/funcTest/resources/additional-source-sets/build.gradle
Outdated
Show resolved
Hide resolved
@glefloch Here are the tests that I ran,
I am assuming that the CI process should take care of verifying the overall sanity of this PR. |
devtools/gradle/src/main/java/io/quarkus/gradle/QuarkusPluginExtension.java
Outdated
Show resolved
Hide resolved
@roguexz Looks good, thanks! Could you please squash the commits and perhaps review the suggestion from @ebramirez? |
Sure thing. Will do that shortly |
Done.
|
* Determine test output directory based on the task * Raise an exception if the mapping data is invalid. * Include a functional-test for verifying the plugin behavior
It is common practice for Gradle projects to have more than one source set as part of the project setup. For example,
Currently Quarkus's
PathTestHelper
does not allow developers to include Quarkus tests in to any of these other locations. This commit proposes a change which will allow supplying the additional source sets to the Quarkus test framework.Once approved, the subsequent change would be to the Gradle plugin where we can determine the various source sets and supply them as environment variables.
E.g.,
Sample
build.gradle
snippet.