[Wasm] Add compiler support for the kotlin.test library
This commit is contained in:
committed by
TeamCityServer
parent
7943298240
commit
bede039c08
+5
@@ -41,6 +41,11 @@ interface JsCommonBackendContext : CommonBackendContext {
|
||||
|
||||
val es6mode: Boolean
|
||||
get() = false
|
||||
|
||||
val suiteFun: IrSimpleFunctionSymbol?
|
||||
val testFun: IrSimpleFunctionSymbol?
|
||||
|
||||
fun createTestContainerFun(module: IrModuleFragment): IrSimpleFunction
|
||||
}
|
||||
|
||||
// TODO: investigate if it could be removed
|
||||
|
||||
@@ -123,7 +123,7 @@ class JsIrBackendContext(
|
||||
|
||||
private val testContainerFuns = mutableMapOf<IrModuleFragment, IrSimpleFunction>()
|
||||
|
||||
fun createTestContainerFun(module: IrModuleFragment): IrSimpleFunction {
|
||||
override fun createTestContainerFun(module: IrModuleFragment): IrSimpleFunction {
|
||||
return testContainerFuns.getOrPut(module) {
|
||||
val file = syntheticFile("tests", module)
|
||||
irFactory.addFunction(file) {
|
||||
@@ -325,8 +325,8 @@ class JsIrBackendContext(
|
||||
val throwISEsymbol = symbolTable.referenceSimpleFunction(getFunctions(kotlinPackageFqn.child(Name.identifier("THROW_ISE"))).single())
|
||||
val throwIAEsymbol = symbolTable.referenceSimpleFunction(getFunctions(kotlinPackageFqn.child(Name.identifier("THROW_IAE"))).single())
|
||||
|
||||
val suiteFun = getFunctions(FqName("kotlin.test.suite")).singleOrNull()?.let { symbolTable.referenceSimpleFunction(it) }
|
||||
val testFun = getFunctions(FqName("kotlin.test.test")).singleOrNull()?.let { symbolTable.referenceSimpleFunction(it) }
|
||||
override val suiteFun = getFunctions(FqName("kotlin.test.suite")).singleOrNull()?.let { symbolTable.referenceSimpleFunction(it) }
|
||||
override val testFun = getFunctions(FqName("kotlin.test.test")).singleOrNull()?.let { symbolTable.referenceSimpleFunction(it) }
|
||||
|
||||
val primitiveClassProperties by lazy2 {
|
||||
primitiveClassesObject.owner.declarations.filterIsInstance<IrProperty>()
|
||||
|
||||
+4
-3
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||
import org.jetbrains.kotlin.ir.backend.js.JsCommonBackendContext
|
||||
import org.jetbrains.kotlin.ir.backend.js.JsIrBackendContext
|
||||
import org.jetbrains.kotlin.ir.backend.js.ir.JsIrBuilder
|
||||
import org.jetbrains.kotlin.ir.builders.declarations.buildFun
|
||||
@@ -26,7 +27,7 @@ import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
fun generateTests(context: JsIrBackendContext, moduleFragment: IrModuleFragment) {
|
||||
fun generateTests(context: JsCommonBackendContext, moduleFragment: IrModuleFragment) {
|
||||
val generator = TestGenerator(context) { context.createTestContainerFun(moduleFragment) }
|
||||
|
||||
moduleFragment.files.toList().forEach {
|
||||
@@ -34,7 +35,7 @@ fun generateTests(context: JsIrBackendContext, moduleFragment: IrModuleFragment)
|
||||
}
|
||||
}
|
||||
|
||||
class TestGenerator(val context: JsIrBackendContext, val testContainerFactory: () -> IrSimpleFunction) : FileLoweringPass {
|
||||
class TestGenerator(val context: JsCommonBackendContext, val testContainerFactory: () -> IrSimpleFunction) : FileLoweringPass {
|
||||
|
||||
override fun lower(irFile: IrFile) {
|
||||
irFile.declarations.forEach {
|
||||
@@ -61,7 +62,7 @@ class TestGenerator(val context: JsIrBackendContext, val testContainerFactory: (
|
||||
|
||||
val function = context.irFactory.buildFun {
|
||||
this.name = Name.identifier("$name test fun")
|
||||
this.returnType = context.irBuiltIns.anyNType
|
||||
this.returnType = if (this@createInvocation == context.suiteFun!!) context.irBuiltIns.unitType else context.irBuiltIns.anyNType
|
||||
this.origin = JsIrBuilder.SYNTHESIZED_DECLARATION
|
||||
}
|
||||
function.parent = parentFunction
|
||||
|
||||
Reference in New Issue
Block a user