[gradle] clear test filters when launching specific test/package IDEA-218613

Gradle build script may define own filters, `includeTestsMatching` invocation appends new pattern to list of filters, and Gradle will invoke all test matching _any_ filter. IDEA should reset list of filters before appending own ones.

GitOrigin-RevId: cfa86464f7ab2c1ea33d9646994bae28c82d96f1
This commit is contained in:
Nikita Skvortsov
2019-07-30 17:04:01 +03:00
committed by intellij-monorepo-bot
parent 4352ee62e3
commit f6900ff4bc
2 changed files with 55 additions and 13 deletions
@@ -1,4 +1,3 @@
import com.intellij.openapi.externalSystem.model.ExternalSystemException
import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId
import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListenerAdapter
import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskType
@@ -6,17 +5,14 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Pair
import com.intellij.testFramework.RunAll
import com.intellij.util.ThrowableRunnable
import org.assertj.core.api.Assertions
import org.assertj.core.api.Assertions.*
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.assertThatThrownBy
import org.jetbrains.plugins.gradle.GradleManager
import org.jetbrains.plugins.gradle.execution.test.runner.GradleTestsExecutionConsoleManager
import org.jetbrains.plugins.gradle.importing.GradleBuildScriptBuilderEx
import org.jetbrains.plugins.gradle.importing.GradleImportingTestCase
import org.jetbrains.plugins.gradle.importing.withMavenCentral
import org.jetbrains.plugins.gradle.service.execution.GradleExecutionHelper
import org.jetbrains.plugins.gradle.service.task.GradleTaskManager
import org.jetbrains.plugins.gradle.util.GradleConstants
import org.junit.Assert.*
import org.junit.Test
open class GradleJavaTestEventsIntegrationTest: GradleImportingTestCase() {
@@ -31,8 +27,8 @@ open class GradleJavaTestEventsIntegrationTest: GradleImportingTestCase() {
createProjectSubFile("src/test/java/my/pack/AClassTest.java",
"package my.pack;\n" +
"import org.junit.Test;" +
"import static org.junit.Assert.*;" +
"import org.junit.Test;\n" +
"import static org.junit.Assert.*;\n" +
"public class AClassTest {\n" +
" @Test\n" +
" public void testSuccess() {\n" +
@@ -44,19 +40,33 @@ open class GradleJavaTestEventsIntegrationTest: GradleImportingTestCase() {
" }\n" +
"}");
createProjectSubFile("src/test/java/my/otherpack/AClassTest.java",
"package my.otherpack;\n" +
"import my.pack.AClass;\n" +
"import org.junit.Test;\n" +
"import static org.junit.Assert.*;\n" +
"public class AClassTest {\n" +
" @Test\n" +
" public void testSuccess() {\n" +
" assertEquals(42, new AClass().method());\n" +
" }\n" +
"}");
importProject(
GradleBuildScriptBuilderEx()
.withMavenCentral()
.applyPlugin("'java'")
.addPostfix("dependencies {",
" testCompile 'junit:junit:4.12'",
"}")
"}",
"test { filter { includeTestsMatching 'my.pack.*' } }")
.generate()
)
RunAll().append(
ThrowableRunnable<Throwable> { `call test task produces test events`() },
ThrowableRunnable<Throwable> { `call build task does not produce test events`() }
ThrowableRunnable<Throwable> { `call build task does not produce test events`() },
ThrowableRunnable<Throwable> { `call task for specific test overrides existing filters`() }
).run()
}
@@ -85,8 +95,9 @@ open class GradleJavaTestEventsIntegrationTest: GradleImportingTestCase() {
assertThat(eventLog)
.contains(
"<descriptor name='testFail' className='my.pack.AClassTest' /><ijLogEol/>",
"<descriptor name='testSuccess' className='my.pack.AClassTest' /><ijLogEol/>"
)
"<descriptor name='testSuccess' className='my.pack.AClassTest' /><ijLogEol/>")
.doesNotContain(
"<descriptor name='testSuccess' className='my.otherpack.AClassTest' /><ijLogEol/>")
}
private fun `call build task does not produce test events`() {
@@ -112,4 +123,34 @@ open class GradleJavaTestEventsIntegrationTest: GradleImportingTestCase() {
assertThat(eventLog).noneMatch { it.contains("<ijLogEol/>") }
}
private fun `call task for specific test overrides existing filters`() {
val taskId = ExternalSystemTaskId.create(GradleConstants.SYSTEM_ID, ExternalSystemTaskType.EXECUTE_TASK, myProject)
val eventLog = mutableListOf<String>()
val testListener = object : ExternalSystemTaskNotificationListenerAdapter() {
override fun onTaskOutput(id: ExternalSystemTaskId, text: String, stdOut: Boolean) {
eventLog.add(text.trim('\r', '\n', ' '))
}
};
val settings = GradleManager()
.executionSettingsProvider
.`fun`(Pair.create<Project, String>(myProject, projectPath))
.apply {
putUserData(GradleConstants.RUN_TASK_AS_TEST, true);
withArguments("--tests","my.otherpack.*")
}
GradleTaskManager().executeTasks(taskId,
listOf(":cleanTest", ":test"),
projectPath,
settings,
null,
testListener);
assertThat(eventLog)
.contains("<descriptor name='testSuccess' className='my.otherpack.AClassTest' /><ijLogEol/>")
.doesNotContain("<descriptor name='testFail' className='my.pack.AClassTest' /><ijLogEol/>",
"<descriptor name='testSuccess' className='my.pack.AClassTest' /><ijLogEol/>")
}
}
@@ -1,4 +1,4 @@
import org.gradle.util.*
import org.gradle.util.GradleVersion
String[] ijTestIncludes = ${TEST_NAME_INCLUDES}
boolean ijTestFilteringSupported = GradleVersion.current().compareTo(GradleVersion.version("1.10"))>=0
@@ -40,6 +40,7 @@ gradle.taskGraph.beforeTask { Task task ->
try {
if(ijTestIncludes != ['*'] && ijTestFilteringSupported) {
task.filter {
setIncludePatterns(new String[0])
ijTestIncludes.each(){ includeTestsMatching "${it}" }
}
}