From 5dff5028f1d0de46bd5f77886c52d39d9f0a1e4d Mon Sep 17 00:00:00 2001 From: Daniil Ovchinnikov Date: Tue, 16 Jan 2024 21:21:40 +0100 Subject: [PATCH] move `ProgressReporterTest` closer to the implementation GitOrigin-RevId: 262bfe17271fcdd7678de8b6f558e6e77084bb83 --- .idea/modules.xml | 1 + .../intellij.platform.tests.iml | 1 + .../progress/CoroutineToIndicatorTest.kt | 3 +- .../progress/RunBlockingCancellableTest.kt | 3 +- .../intellij.platform.util.progress.tests.iml | 18 ++++++++ .../progress/tests}/ProgressReporterTest.kt | 41 ++----------------- platform/util/progress/tests/test-util.kt | 41 +++++++++++++++++++ 7 files changed, 69 insertions(+), 39 deletions(-) create mode 100644 platform/util/progress/intellij.platform.util.progress.tests.iml rename platform/{platform-tests/testSrc/com/intellij/openapi/progress => util/progress/tests}/ProgressReporterTest.kt (94%) create mode 100644 platform/util/progress/tests/test-util.kt diff --git a/.idea/modules.xml b/.idea/modules.xml index 67404bd7ed16..d1fe0dd30b39 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -1076,6 +1076,7 @@ + diff --git a/platform/platform-tests/intellij.platform.tests.iml b/platform/platform-tests/intellij.platform.tests.iml index c2f309171025..cb653dc97bb3 100644 --- a/platform/platform-tests/intellij.platform.tests.iml +++ b/platform/platform-tests/intellij.platform.tests.iml @@ -90,5 +90,6 @@ + \ No newline at end of file diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/progress/CoroutineToIndicatorTest.kt b/platform/platform-tests/testSrc/com/intellij/openapi/progress/CoroutineToIndicatorTest.kt index 974180b34971..72336de3df84 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/progress/CoroutineToIndicatorTest.kt +++ b/platform/platform-tests/testSrc/com/intellij/openapi/progress/CoroutineToIndicatorTest.kt @@ -1,10 +1,11 @@ -// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.openapi.progress import com.intellij.openapi.application.ModalityState import com.intellij.openapi.application.asContextElement import com.intellij.openapi.application.impl.ModalityStateEx import com.intellij.platform.util.progress.impl.ProgressState +import com.intellij.platform.util.progress.progressReporterTest import com.intellij.platform.util.progress.withRawProgressReporter import com.intellij.testFramework.common.timeoutRunBlocking import kotlinx.coroutines.CancellationException diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/progress/RunBlockingCancellableTest.kt b/platform/platform-tests/testSrc/com/intellij/openapi/progress/RunBlockingCancellableTest.kt index ce3bf82215a7..2870be159085 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/progress/RunBlockingCancellableTest.kt +++ b/platform/platform-tests/testSrc/com/intellij/openapi/progress/RunBlockingCancellableTest.kt @@ -1,10 +1,11 @@ -// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.openapi.progress import com.intellij.concurrency.currentThreadContextOrNull import com.intellij.openapi.application.impl.ModalityStateEx import com.intellij.platform.util.progress.impl.ProgressState import com.intellij.platform.util.progress.progressReporter +import com.intellij.platform.util.progress.progressReporterTest import com.intellij.platform.util.progress.rawProgressReporter import com.intellij.platform.util.progress.withRawProgressReporter import com.intellij.testFramework.common.timeoutRunBlocking diff --git a/platform/util/progress/intellij.platform.util.progress.tests.iml b/platform/util/progress/intellij.platform.util.progress.tests.iml new file mode 100644 index 000000000000..12e8349c1d4f --- /dev/null +++ b/platform/util/progress/intellij.platform.util.progress.tests.iml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/progress/ProgressReporterTest.kt b/platform/util/progress/tests/ProgressReporterTest.kt similarity index 94% rename from platform/platform-tests/testSrc/com/intellij/openapi/progress/ProgressReporterTest.kt rename to platform/util/progress/tests/ProgressReporterTest.kt index 050de22254b3..ce841f170b09 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/progress/ProgressReporterTest.kt +++ b/platform/util/progress/tests/ProgressReporterTest.kt @@ -1,24 +1,11 @@ -// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. -package com.intellij.openapi.progress +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package com.intellij.platform.util.progress -import com.intellij.platform.util.progress.asContextElement -import com.intellij.platform.util.progress.durationStep import com.intellij.platform.util.progress.impl.ACCEPTABLE_FRACTION_OVERFLOW import com.intellij.platform.util.progress.impl.ProgressState -import com.intellij.platform.util.progress.impl.TextDetailsProgressReporter -import com.intellij.platform.util.progress.indeterminateStep -import com.intellij.platform.util.progress.itemDuration -import com.intellij.platform.util.progress.progressReporter -import com.intellij.platform.util.progress.progressStep -import com.intellij.platform.util.progress.rawProgressReporter -import com.intellij.platform.util.progress.withRawProgressReporter -import com.intellij.testFramework.UsefulTestCase.assertOrderedEquals -import com.intellij.testFramework.common.timeoutRunBlocking -import com.intellij.util.containers.ContainerUtil -import com.intellij.util.containers.init -import com.intellij.util.containers.tail import kotlinx.coroutines.* -import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.Assertions.fail import org.junit.jupiter.api.Test class ProgressReporterTest { @@ -803,23 +790,3 @@ class ProgressReporterTest { } } } - -internal fun progressReporterTest( - vararg expectedUpdates: ProgressState, - action: suspend CoroutineScope.() -> Unit, -) = timeoutRunBlocking { - val actualUpdates = ContainerUtil.createConcurrentList() - val progressReporter = TextDetailsProgressReporter(this) - val collector = launch(Dispatchers.Unconfined + CoroutineName("state collector")) { - progressReporter.progressState.collect { state -> - actualUpdates.add(state) - } - } - withContext(progressReporter.asContextElement(), action) - progressReporter.close() - progressReporter.awaitCompletion() - collector.cancelAndJoin() - assertEquals(ProgressState(null, null, -1.0), actualUpdates.first()) - assertEquals(ProgressState(null, null, 1.0), actualUpdates.last()) - assertOrderedEquals(actualUpdates.toList().init().tail(), expectedUpdates.toList()) -} diff --git a/platform/util/progress/tests/test-util.kt b/platform/util/progress/tests/test-util.kt new file mode 100644 index 000000000000..a310e35c74d3 --- /dev/null +++ b/platform/util/progress/tests/test-util.kt @@ -0,0 +1,41 @@ +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package com.intellij.platform.util.progress + +import com.intellij.platform.util.progress.impl.ProgressState +import com.intellij.platform.util.progress.impl.TextDetailsProgressReporter +import com.intellij.testFramework.TestLoggerFactory +import com.intellij.testFramework.UsefulTestCase.assertOrderedEquals +import com.intellij.testFramework.common.timeoutRunBlocking +import com.intellij.util.containers.ContainerUtil +import com.intellij.util.containers.init +import com.intellij.util.containers.tail +import kotlinx.coroutines.* +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.assertThrows + +fun progressReporterTest( + vararg expectedUpdates: ProgressState, + action: suspend CoroutineScope.() -> Unit, +) = timeoutRunBlocking { + val actualUpdates = ContainerUtil.createConcurrentList() + val progressReporter = TextDetailsProgressReporter(this) + val collector = launch(Dispatchers.Unconfined + CoroutineName("state collector")) { + progressReporter.progressState.collect { state -> + actualUpdates.add(state) + } + } + withContext(progressReporter.asContextElement(), action) + progressReporter.close() + progressReporter.awaitCompletion() + collector.cancelAndJoin() + assertEquals(ProgressState(null, null, -1.0), actualUpdates.first()) + assertEquals(ProgressState(null, null, 1.0), actualUpdates.last()) + assertOrderedEquals(actualUpdates.toList().init().tail(), expectedUpdates.toList()) +} + +internal inline fun assertLogThrows(executable: () -> Unit): T { + return assertThrows { + val loggerError = assertThrows(executable) + throw requireNotNull(loggerError.cause) + } +}