mirror of
https://github.com/yonaskolb/XcodeGen.git
synced 2024-10-26 14:01:24 +03:00
Allow to override test macroExpansions
This commit is contained in:
parent
2a367acb0f
commit
ce5d015351
@ -218,6 +218,7 @@ public struct Scheme: Equatable {
|
||||
public var captureScreenshotsAutomatically: Bool
|
||||
public var deleteScreenshotsWhenEachTestSucceeds: Bool
|
||||
public var testPlans: [TestPlan]
|
||||
public var macroExpansion: String?
|
||||
|
||||
public struct TestTarget: Equatable, ExpressibleByStringLiteral {
|
||||
|
||||
@ -284,7 +285,8 @@ public struct Scheme: Equatable {
|
||||
debugEnabled: Bool = debugEnabledDefault,
|
||||
customLLDBInit: String? = nil,
|
||||
captureScreenshotsAutomatically: Bool = captureScreenshotsAutomaticallyDefault,
|
||||
deleteScreenshotsWhenEachTestSucceeds: Bool = deleteScreenshotsWhenEachTestSucceedsDefault
|
||||
deleteScreenshotsWhenEachTestSucceeds: Bool = deleteScreenshotsWhenEachTestSucceedsDefault,
|
||||
macroExpansion: String? = nil
|
||||
) {
|
||||
self.config = config
|
||||
self.gatherCoverageData = gatherCoverageData
|
||||
@ -302,6 +304,7 @@ public struct Scheme: Equatable {
|
||||
self.customLLDBInit = customLLDBInit
|
||||
self.captureScreenshotsAutomatically = captureScreenshotsAutomatically
|
||||
self.deleteScreenshotsWhenEachTestSucceeds = deleteScreenshotsWhenEachTestSucceeds
|
||||
self.macroExpansion = macroExpansion
|
||||
}
|
||||
|
||||
public var shouldUseLaunchSchemeArgsEnv: Bool {
|
||||
@ -616,6 +619,7 @@ extension Scheme.Test: JSONObjectConvertible {
|
||||
customLLDBInit = jsonDictionary.json(atKeyPath: "customLLDBInit")
|
||||
captureScreenshotsAutomatically = jsonDictionary.json(atKeyPath: "captureScreenshotsAutomatically") ?? Scheme.Test.captureScreenshotsAutomaticallyDefault
|
||||
deleteScreenshotsWhenEachTestSucceeds = jsonDictionary.json(atKeyPath: "deleteScreenshotsWhenEachTestSucceeds") ?? Scheme.Test.deleteScreenshotsWhenEachTestSucceedsDefault
|
||||
macroExpansion = jsonDictionary.json(atKeyPath: "macroExpansion")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -228,6 +228,10 @@ public class SchemeGenerator {
|
||||
let buildableReference = buildActionEntries.first(where: { $0.buildableReference.blueprintName == schemeTarget?.name })?.buildableReference ?? buildActionEntries.first!.buildableReference
|
||||
let runnables = makeProductRunnables(for: schemeTarget, buildableReference: buildableReference)
|
||||
|
||||
let testMacroExpansion: XCScheme.BuildableReference = buildActionEntries.first(
|
||||
where: { $0.buildableReference.blueprintName == scheme.test?.macroExpansion }
|
||||
)?.buildableReference ?? buildableReference
|
||||
|
||||
let buildAction = XCScheme.BuildAction(
|
||||
buildActionEntries: buildActionEntries,
|
||||
preActions: scheme.build.preActions.map(getExecutionAction),
|
||||
@ -284,7 +288,7 @@ public class SchemeGenerator {
|
||||
|
||||
let testAction = XCScheme.TestAction(
|
||||
buildConfiguration: scheme.test?.config ?? defaultDebugConfig.name,
|
||||
macroExpansion: buildableReference,
|
||||
macroExpansion: testMacroExpansion,
|
||||
testables: testables,
|
||||
testPlans: testPlans.isEmpty ? nil : testPlans,
|
||||
preActions: scheme.test?.preActions.map(getExecutionAction) ?? [],
|
||||
|
@ -476,6 +476,41 @@ class SchemeGeneratorTests: XCTestCase {
|
||||
let xcodeProject = try project.generateXcodeProject()
|
||||
|
||||
let xcscheme = try unwrap(xcodeProject.sharedData?.schemes.first)
|
||||
try expect(xcscheme.testAction?.macroExpansion?.buildableName) == "MyApp.app"
|
||||
try expect(xcscheme.launchAction?.macroExpansion?.buildableName) == "MyApp.app"
|
||||
}
|
||||
|
||||
$0.it("allows to override test macroExpansion") {
|
||||
let app = Target(
|
||||
name: "MyApp",
|
||||
type: .application,
|
||||
platform: .iOS,
|
||||
dependencies: [Dependency(type: .target, reference: "MyAppExtension", embed: false)]
|
||||
)
|
||||
|
||||
let `extension` = Target(
|
||||
name: "MyAppExtension",
|
||||
type: .appExtension,
|
||||
platform: .iOS
|
||||
)
|
||||
let appTarget = Scheme.BuildTarget(target: .local(app.name), buildTypes: [.running])
|
||||
let extensionTarget = Scheme.BuildTarget(target: .local(`extension`.name), buildTypes: [.running])
|
||||
|
||||
let scheme = Scheme(
|
||||
name: "TestScheme",
|
||||
build: Scheme.Build(targets: [appTarget, extensionTarget]),
|
||||
run: Scheme.Run(config: "Debug", macroExpansion: "MyApp"),
|
||||
test: .init(macroExpansion: "MyAppExtension")
|
||||
)
|
||||
let project = Project(
|
||||
name: "test",
|
||||
targets: [app, `extension`],
|
||||
schemes: [scheme]
|
||||
)
|
||||
let xcodeProject = try project.generateXcodeProject()
|
||||
|
||||
let xcscheme = try unwrap(xcodeProject.sharedData?.schemes.first)
|
||||
try expect(xcscheme.testAction?.macroExpansion?.buildableName) == "MyAppExtension.appex"
|
||||
try expect(xcscheme.launchAction?.macroExpansion?.buildableName) == "MyApp.app"
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user