Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate UI Test Target Attributes #221

Merged
merged 7 commits into from
Jan 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's interesting that this could change across configs. I wonder how Xcode deals with this. This is probably fine though

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering about that too.
Xcode doesnt let you specify this on a per configuration basis.
Meaning it adds the TEST_TARGET_NAME setting to all configurations.
and then (i assume) generates the target-attributes.

.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