[Test] Add debug names to unnamed test disposables
- This helps to track down disposables which are never disposed, and reduces confusion when printing disposables in general (the names will now be meaningful, instead of endless lists of "newDisposable" and "TestDisposable"). ^KT-64099
This commit is contained in:
committed by
Space Team
parent
bba5447b12
commit
32fe29b8cc
+1
-1
@@ -36,7 +36,7 @@ internal fun makeCompiledModule(generationState: GenerationState) =
|
||||
inline fun <T> withMessageCollectorAndDisposable(
|
||||
script: SourceCode? = null,
|
||||
parentMessageCollector: MessageCollector? = null,
|
||||
disposable: Disposable = Disposer.newDisposable(),
|
||||
disposable: Disposable = Disposer.newDisposable("Default disposable for scripting compiler"),
|
||||
disposeOnSuccess: Boolean = true,
|
||||
body: (ScriptDiagnosticsMessageCollector, Disposable) -> ResultWithDiagnostics<T>
|
||||
): ResultWithDiagnostics<T> {
|
||||
|
||||
+6
-1
@@ -36,7 +36,12 @@ open class GenericReplCompiler(
|
||||
scriptDefinition: KotlinScriptDefinition,
|
||||
compilerConfiguration: CompilerConfiguration,
|
||||
messageCollector: MessageCollector
|
||||
) : this(Disposer.newDisposable(), scriptDefinition, compilerConfiguration, messageCollector)
|
||||
) : this(
|
||||
Disposer.newDisposable("Default disposable for ${GenericReplCompiler::class.simpleName}"),
|
||||
scriptDefinition,
|
||||
compilerConfiguration,
|
||||
messageCollector
|
||||
)
|
||||
|
||||
private val checker =
|
||||
GenericReplChecker(
|
||||
|
||||
+9
-1
@@ -59,7 +59,15 @@ class FirScriptDefinitionProviderService(
|
||||
val makeConfigurationProvider = configurationProvider?.let { { it } }
|
||||
?: {
|
||||
// TODO: check if memory can leak in MockProject (probably not too important, since currently the providers are set externaly in important cases)
|
||||
CliScriptDependenciesProvider(MockProject(null, Disposer.newDisposable()))
|
||||
CliScriptDependenciesProvider(
|
||||
MockProject(
|
||||
null,
|
||||
Disposer.newDisposable(
|
||||
"Disposable for project of ${CliScriptDependenciesProvider::class.simpleName} created by" +
|
||||
" ${FirScriptDefinitionProviderService::class.simpleName}"
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
return Factory { session -> FirScriptDefinitionProviderService(session, makeDefinitionsProvider, makeConfigurationProvider) }
|
||||
|
||||
+4
-2
@@ -271,7 +271,7 @@ internal fun <R> withTempDir(keyName: String = "tmp", body: (File) -> R): R {
|
||||
}
|
||||
|
||||
internal fun <R> withDisposable(body: (Disposable) -> R) {
|
||||
val disposable = Disposer.newDisposable()
|
||||
val disposable = Disposer.newDisposable("Disposable for scripting compiler tests")
|
||||
try {
|
||||
body(disposable)
|
||||
} finally {
|
||||
@@ -279,7 +279,7 @@ internal fun <R> withDisposable(body: (Disposable) -> R) {
|
||||
}
|
||||
}
|
||||
|
||||
class TestDisposable : Disposable {
|
||||
class TestDisposable(val debugName: String) : Disposable {
|
||||
@Volatile
|
||||
var isDisposed = false
|
||||
private set
|
||||
@@ -287,6 +287,8 @@ class TestDisposable : Disposable {
|
||||
override fun dispose() {
|
||||
isDisposed = true
|
||||
}
|
||||
|
||||
override fun toString(): String = debugName
|
||||
}
|
||||
|
||||
fun CompilerConfiguration.updateWithBaseCompilerArguments() {
|
||||
|
||||
+2
-1
@@ -28,7 +28,8 @@ private const val testDataPath = "plugins/scripting/scripting-compiler/testData/
|
||||
|
||||
class CollectScriptCompilationDependenciesTest : TestCase() {
|
||||
|
||||
protected val testRootDisposable: Disposable = TestDisposable()
|
||||
protected val testRootDisposable: Disposable =
|
||||
TestDisposable("${CollectScriptCompilationDependenciesTest::class.simpleName}.testRootDisposable")
|
||||
|
||||
fun testCascadeImport() {
|
||||
runTest("imp_imp_leaf.req1.kts", listOf("imp_leaf.req1.kts", "leaf.req1.kts"))
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@ import kotlin.script.experimental.util.filterByAnnotationType
|
||||
private const val testDataPath = "plugins/scripting/scripting-compiler/testData/compiler/compileTimeFibonacci"
|
||||
|
||||
class CompileTimeFibonacciTest : TestCase() {
|
||||
private val testRootDisposable: Disposable = TestDisposable()
|
||||
private val testRootDisposable: Disposable = TestDisposable("${CompileTimeFibonacciTest::class.simpleName}.testRootDisposable")
|
||||
|
||||
fun testFibonacciWithSupportedNumbersImplementsTheCorrectConstants() {
|
||||
val outputLines = runScript("supported.fib.kts")
|
||||
|
||||
+1
-1
@@ -40,7 +40,7 @@ private annotation class TestAnnotation(vararg val options: String)
|
||||
private annotation class AnnotationWithVarArgAndArray(vararg val options: String, val moreOptions: Array<String>)
|
||||
|
||||
class ConstructAnnotationTest : TestCase() {
|
||||
private val testRootDisposable: Disposable = TestDisposable()
|
||||
private val testRootDisposable: Disposable = TestDisposable("${ConstructAnnotationTest::class.simpleName}.testRootDisposable")
|
||||
|
||||
fun testAnnotationEmptyVarArg() {
|
||||
val annotations = annotations("TestAnnotationEmptyVarArg.kts", TestAnnotation::class)
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ private const val testDataPath = "plugins/scripting/scripting-compiler/testData/
|
||||
|
||||
class ScriptCliCompilationTest : TestCase() {
|
||||
|
||||
protected val testRootDisposable: Disposable = TestDisposable()
|
||||
protected val testRootDisposable: Disposable = TestDisposable("${ScriptCliCompilationTest::class.simpleName}.testRootDisposable")
|
||||
|
||||
fun testPrerequisites() {
|
||||
Assert.assertTrue(thisClasspath.isNotEmpty())
|
||||
|
||||
+1
-1
@@ -362,7 +362,7 @@ class ScriptTemplateTest : TestCase() {
|
||||
messageCollector: MessageCollector,
|
||||
includeKotlinRuntime: Boolean
|
||||
): Class<*>? {
|
||||
val rootDisposable = Disposer.newDisposable()
|
||||
val rootDisposable = Disposer.newDisposable("Disposable for ${ScriptTemplateTest::class.simpleName}")
|
||||
try {
|
||||
val additionalClasspath = System.getProperty("kotlin.test.script.classpath")?.split(File.pathSeparator)
|
||||
?.mapNotNull { File(it).takeIf { file -> file.exists() } }.orEmpty().toTypedArray()
|
||||
|
||||
+1
-1
@@ -116,7 +116,7 @@ class ScriptTest : TestCase() {
|
||||
if (suppressOutput) MessageCollector.NONE
|
||||
else PrintingMessageCollector(System.err, MessageRenderer.PLAIN_FULL_PATHS, false)
|
||||
|
||||
val rootDisposable = Disposer.newDisposable()
|
||||
val rootDisposable = Disposer.newDisposable("Disposable for ${ScriptTest::class.simpleName}")
|
||||
try {
|
||||
val configuration = KotlinTestUtils.newConfiguration(ConfigurationKind.ALL, TestJdkKind.FULL_JDK)
|
||||
configuration.updateWithBaseCompilerArguments()
|
||||
|
||||
Reference in New Issue
Block a user