[K/N] XCTest launcher for CompilerOutput's TEST_BUNDLE
This change adds a Native Obj-C launcher that implements XCTestCase and overrides defaultTestSuite property to provide XCTest with generated test suites and test cases. The defaultTestSuite method is essentially a starting point with runtime initialization. It requires a `Konan_create_testSuite()` method to be implemented in a Kotlin library that returns a list of XCTestCases. This launcher should be compiled as a TEST_BUNDLE to be used then with XCTest. This commit is a part of ^KT-58928 Co-authored-by: Alexander Shabalin <Alexander.Shabalin@jetbrains.com> Merge-request: KT-MR-12841 Merged-by: Pavel Punegov <Pavel.Punegov@jetbrains.com>
This commit is contained in:
committed by
Space Team
parent
d6acba1c33
commit
0d8960088e
+4
-1
@@ -93,11 +93,14 @@ private fun collectLlvmModules(generationState: NativeGenerationState, generated
|
|||||||
val additionalBitcodeFilesToLink = generationState.llvm.additionalProducedBitcodeFiles
|
val additionalBitcodeFilesToLink = generationState.llvm.additionalProducedBitcodeFiles
|
||||||
val exceptionsSupportNativeLibrary = listOf(config.exceptionsSupportNativeLibrary)
|
val exceptionsSupportNativeLibrary = listOf(config.exceptionsSupportNativeLibrary)
|
||||||
.takeIf { config.produce == CompilerOutputKind.DYNAMIC_CACHE }.orEmpty()
|
.takeIf { config.produce == CompilerOutputKind.DYNAMIC_CACHE }.orEmpty()
|
||||||
|
val xcTestRunnerNativeLibrary = listOf(config.xcTestLauncherNativeLibrary)
|
||||||
|
.takeIf { config.produce == CompilerOutputKind.TEST_BUNDLE }.orEmpty()
|
||||||
val additionalBitcodeFiles = nativeLibraries +
|
val additionalBitcodeFiles = nativeLibraries +
|
||||||
generatedBitcodeFiles +
|
generatedBitcodeFiles +
|
||||||
additionalBitcodeFilesToLink +
|
additionalBitcodeFilesToLink +
|
||||||
bitcodeLibraries +
|
bitcodeLibraries +
|
||||||
exceptionsSupportNativeLibrary
|
exceptionsSupportNativeLibrary +
|
||||||
|
xcTestRunnerNativeLibrary
|
||||||
|
|
||||||
val runtimeNativeLibraries = config.runtimeNativeLibraries
|
val runtimeNativeLibraries = config.runtimeNativeLibraries
|
||||||
|
|
||||||
|
|||||||
+3
@@ -405,6 +405,9 @@ class KonanConfig(val project: Project, val configuration: CompilerConfiguration
|
|||||||
internal val objCNativeLibrary: String =
|
internal val objCNativeLibrary: String =
|
||||||
File(distribution.defaultNatives(target)).child("objc.bc").absolutePath
|
File(distribution.defaultNatives(target)).child("objc.bc").absolutePath
|
||||||
|
|
||||||
|
internal val xcTestLauncherNativeLibrary: String =
|
||||||
|
File(distribution.defaultNatives(target)).child("xctest_launcher.bc").absolutePath
|
||||||
|
|
||||||
internal val exceptionsSupportNativeLibrary: String =
|
internal val exceptionsSupportNativeLibrary: String =
|
||||||
File(distribution.defaultNatives(target)).child("exceptionsSupport.bc").absolutePath
|
File(distribution.defaultNatives(target)).child("exceptionsSupport.bc").absolutePath
|
||||||
|
|
||||||
|
|||||||
@@ -360,6 +360,15 @@ bitcode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module("xctest_launcher") {
|
||||||
|
headersDirs.from(files("src/main/cpp"))
|
||||||
|
|
||||||
|
sourceSets {
|
||||||
|
main {}
|
||||||
|
}
|
||||||
|
onlyIf { target.family.isAppleFamily }
|
||||||
|
}
|
||||||
|
|
||||||
testsGroup("custom_alloc_runtime_tests") {
|
testsGroup("custom_alloc_runtime_tests") {
|
||||||
testedModules.addAll("custom_alloc")
|
testedModules.addAll("custom_alloc")
|
||||||
testSupportModules.addAll("main", "mm", "common_alloc", "common_gc", "common_gcScheduler", "manual_gcScheduler", "concurrent_ms_gc_custom", "objc")
|
testSupportModules.addAll("main", "mm", "common_alloc", "common_gc", "common_gcScheduler", "manual_gcScheduler", "concurrent_ms_gc_custom", "objc")
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#define RUNTIME_RUNTIME_H
|
#define RUNTIME_RUNTIME_H
|
||||||
|
|
||||||
#include "Porting.h"
|
#include "Porting.h"
|
||||||
|
#include "Memory.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2023 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* These are stub declarations from XCTest.framework needed for the launcher compilation.
|
||||||
|
* It makes possible to compile it without dependency on the framework, while the
|
||||||
|
* final build of the bundle should be done with a real XCTest.framework library.
|
||||||
|
*/
|
||||||
|
|
||||||
|
@interface XCTestCase
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface XCTestSuite
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface XCTestCase (XCTestSuiteExtensions)
|
||||||
|
@property (class, readonly) XCTestSuite *defaultTestSuite;
|
||||||
|
@end
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2023 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#import "Memory.h"
|
||||||
|
#import "ObjCExport.h"
|
||||||
|
#import "TestLauncher.h"
|
||||||
|
|
||||||
|
extern "C" OBJ_GETTER0(Konan_create_testSuite);
|
||||||
|
|
||||||
|
@interface XCTestLauncher : XCTestCase
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation XCTestLauncher
|
||||||
|
/**
|
||||||
|
* Test suites factory.
|
||||||
|
*
|
||||||
|
* This is a starting point for XCTest to get test suites with test cases.
|
||||||
|
* K/N dynamically adds test suites for Kotlin tests.
|
||||||
|
* See `setupXCTestSuite` Kotlin method.
|
||||||
|
*/
|
||||||
|
+ (id)defaultTestSuite {
|
||||||
|
kotlin::CalledFromNativeGuard guard;
|
||||||
|
ObjHolder holder;
|
||||||
|
return Kotlin_ObjCExport_refToObjC(Konan_create_testSuite(holder.slot()));
|
||||||
|
}
|
||||||
|
@end
|
||||||
Reference in New Issue
Block a user