From 1abb430f156b0bca1bdc9c68a76fe5a9befdc91c Mon Sep 17 00:00:00 2001 From: Ilya Matveev Date: Fri, 8 Sep 2017 17:14:55 +0300 Subject: [PATCH] REVERTME: Workaround a bug with inner classes --- .../src/main/kotlin/konan/test/TestSuite.kt | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/runtime/src/main/kotlin/konan/test/TestSuite.kt b/runtime/src/main/kotlin/konan/test/TestSuite.kt index 1420d106554..d54e3848c03 100644 --- a/runtime/src/main/kotlin/konan/test/TestSuite.kt +++ b/runtime/src/main/kotlin/konan/test/TestSuite.kt @@ -20,12 +20,13 @@ enum class FunctionKind { abstract class AbstractTestSuite>(override val name: String): TestSuite { override fun toString(): String = name - inner class BasicTestCase(override val name: String, val testFunction: F): TestCase { + // TODO: Make inner and remove the type param when the bug is fixed. + open class BasicTestCase>(override val name: String, val testFunction: F): TestCase { override fun toString(): String = name } - private val _testCases = mutableMapOf() - override val testCases: Map + private val _testCases = mutableMapOf>() + override val testCases: Map> get() = _testCases private val specialFunctions = mutableMapOf>() @@ -39,9 +40,9 @@ abstract class AbstractTestSuite>(override val name: String): val beforeClass: Collection get() = specialFunctions.getFunctions(FunctionKind.BEFORE_CLASS) val afterClass: Collection get() = specialFunctions.getFunctions(FunctionKind.AFTER_CLASS) - protected fun registerTestCase(testCase: BasicTestCase) = _testCases.put(testCase.name, testCase) - protected fun registerTestCases(testCases: Collection) = testCases.forEach { registerTestCase(it) } - protected fun registerTestCases(vararg testCases: BasicTestCase) = registerTestCases(testCases.toList()) + protected fun registerTestCase(testCase: BasicTestCase) = _testCases.put(testCase.name, testCase) + protected fun registerTestCases(testCases: Collection>) = testCases.forEach { registerTestCase(it) } + protected fun registerTestCases(vararg testCases: BasicTestCase) = registerTestCases(testCases.toList()) protected fun registerFunction(type: FunctionKind, function: F) = specialFunctions.getFunctions(type).add(function) @@ -49,7 +50,7 @@ abstract class AbstractTestSuite>(override val name: String): protected abstract fun doBeforeClass() protected abstract fun doAfterClass() - protected abstract fun doTest(testCase: BasicTestCase) + protected abstract fun doTest(testCase: BasicTestCase) override fun run(listener: TestListener) { doBeforeClass() @@ -70,13 +71,15 @@ abstract class AbstractTestSuite>(override val name: String): abstract class TestClass(name: String): AbstractTestSuite Unit>(name) { + class TestClassCase(name: String, testFunction: T.() -> Unit): BasicTestCase Unit>(name, testFunction) + abstract fun createInstance(): T // TODO: What about companions? override fun doBeforeClass() {} // = beforeClass.forEach { createInstance().it() } override fun doAfterClass() {} // = afterClass.forEach { createInstance().it() } - override fun doTest(testCase: BasicTestCase) { + override fun doTest(testCase: BasicTestCase Unit>) { val instance = createInstance() val testFunction = testCase.testFunction before.forEach { instance.it() } @@ -86,10 +89,13 @@ abstract class TestClass(name: String): AbstractTestSuite Unit>(name) } class TopLevelTestSuite(name: String): AbstractTestSuite<() -> Unit>(name) { + + class TopLevelTestCase(name: String, testFunction: () -> Unit): BasicTestCase<() -> Unit>(name, testFunction) + override fun doBeforeClass() = beforeClass.forEach { it() } override fun doAfterClass() = afterClass.forEach { it() } - override fun doTest(testCase: BasicTestCase) { + override fun doTest(testCase: BasicTestCase<() -> Unit>) { before.forEach { it() } testCase.testFunction() after.forEach { it() }