[JS TESTS] Rewrite js ir tests using new test infrastructure

This commit is contained in:
Ivan Kylchik
2021-10-25 18:22:33 +03:00
parent 0e4cf05d3e
commit c59098df2f
29 changed files with 9789 additions and 3981 deletions
@@ -0,0 +1,53 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.test.services
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
import org.jetbrains.kotlin.library.KotlinLibrary
class JsLibraryProvider(private val testServices: TestServices) : TestService {
private val descriptorToLibrary = mutableMapOf<ModuleDescriptor, KotlinLibrary>()
private val stdlibPathToDescriptor = mutableMapOf<String, ModuleDescriptorImpl>()
fun getDescriptorByPath(path: String): ModuleDescriptorImpl {
return stdlibPathToDescriptor[path] ?: testServices.assertions.fail {
"There is no library with path $path"
}
}
fun setDescriptorAndLibraryByName(name: String, descriptor: ModuleDescriptorImpl, library: KotlinLibrary) {
stdlibPathToDescriptor[name] = descriptor
descriptorToLibrary[descriptor] = library
}
fun getCompiledLibraryByDescriptor(descriptor: ModuleDescriptor): KotlinLibrary {
return descriptorToLibrary[descriptor] ?: testServices.assertions.fail {
"There is no library for descriptor ${descriptor.name}"
}
}
fun getPathByDescriptor(descriptor: ModuleDescriptor): String {
return stdlibPathToDescriptor.entries.single { it.value == descriptor }.key
}
fun getDescriptorByCompiledLibrary(library: KotlinLibrary): ModuleDescriptor {
return descriptorToLibrary.filterValues { it == library }.keys.singleOrNull() ?: testServices.assertions.fail {
"There is no descriptor for library ${library.libraryName}"
}
}
fun getOrCreateStdlibByPath(path: String, create: (String) -> Pair<ModuleDescriptorImpl, KotlinLibrary>): ModuleDescriptorImpl {
return stdlibPathToDescriptor.getOrPut(path) {
create(path).let {
descriptorToLibrary += it
it.first
}
}
}
}
val TestServices.jsLibraryProvider: JsLibraryProvider by TestServices.testServiceAccessor()
@@ -103,3 +103,6 @@ val TestFile.isJavaFile: Boolean
val TestFile.isJsFile: Boolean
get() = name.endsWith(".js")
val TestFile.isMjsFile: Boolean
get() = name.endsWith(".mjs")