Skip to content

Commit

Permalink
Merge pull request #221 from anreitersimon/feature/target-attributes
Browse files Browse the repository at this point in the history
Generate UI Test Target Attributes
  • Loading branch information
yonaskolb authored Jan 10, 2018
2 parents 7a485f2 + 7b50a1f commit a9c5696
Show file tree
Hide file tree
Showing 7 changed files with 308 additions and 5 deletions.
41 changes: 40 additions & 1 deletion Sources/XcodeGenKit/PBXProjGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,10 @@ public class PBXProjGenerator {

sortGroups(group: mainGroup)

let projectAttributes: [String: Any] = ["LastUpgradeCheck": spec.xcodeVersion].merged(spec.attributes)
let projectAttributes: [String: Any] = ["LastUpgradeCheck": spec.xcodeVersion]
.merged(spec.attributes)
.merged(self.generateTargetAttributes() ?? [:])

let root = PBXProject(
name: spec.name,
reference: proj.rootObject,
Expand All @@ -173,6 +176,42 @@ public class PBXProjGenerator {

return proj
}

func generateTargetAttributes() -> [String: Any]? {


var targetAttributes: [String: Any] = [:]

// look up TEST_TARGET_NAME build setting
func testTargetName(_ target: PBXTarget) -> String? {
guard let configurationList = target.buildConfigurationList else { return nil }
guard let buildConfigurationReferences = self.proj.objects.configurationLists[configurationList]?.buildConfigurations else { return nil }

let configs = buildConfigurationReferences
.flatMap { ref in self.proj.objects.buildConfigurations[ref] }

return configs
.flatMap { $0.buildSettings["TEST_TARGET_NAME"] as? String }
.first
}

let uiTestTargets = self.proj.objects.nativeTargets.values
.filter { $0.productType == .uiTestBundle }

for uiTestTarget in uiTestTargets {
guard let name = testTargetName(uiTestTarget) else { continue }
guard let target = self.proj.objects.targets(named: name).first else { continue }

targetAttributes[uiTestTarget.reference] = [ "TestTargetID": target.reference]
}

guard !targetAttributes.isEmpty else { return nil }

return [
"TargetAttributes": targetAttributes
]

}

func sortGroups(group: PBXGroup) {
// sort children
Expand Down
22 changes: 22 additions & 0 deletions Tests/Fixtures/TestProject/App_iOS_UITests/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import XCTest

class TestProjectUITests: XCTestCase {

override func setUp() {
super.setUp()
// Put setup code here. This method is called before the invocation of each test method in the class.
}

override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
super.tearDown()
}

func testExample() {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
}

func testPerformanceExample() {
// This is an example of a performance test case.
measure {
// Put the code you want to measure the time of here.
}
}
}
Loading

0 comments on commit a9c5696

Please sign in to comment.