diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/TestProcessor.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/TestProcessor.kt index 5033e1d01e4..2bcae4b64ca 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/TestProcessor.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/TestProcessor.kt @@ -591,6 +591,22 @@ internal class TestProcessor (val context: Context) { private fun createTestSuites(irFile: IrFile, annotationCollector: AnnotationCollector) { val statements = mutableListOf() + // There is no specified order on fake override functions, so to ensure all the tests are run deterministically, + // sort the fake override functions by name. + for (testClass in annotationCollector.testClasses.values) { + val functions = testClass.functions.toList() + testClass.functions.clear() + val fakeOverrideFunctions = mutableListOf() + for (function in functions) { + if (function.function.isFakeOverride) + fakeOverrideFunctions.add(function) + else + testClass.functions.add(function) + } + fakeOverrideFunctions.sortBy { it.functionName } + testClass.functions.addAll(fakeOverrideFunctions) + } + annotationCollector.testClasses.filter { it.value.functions.any { it.kind == FunctionKind.TEST } }.forEach { (_, testClass) ->