Skip to content

Commit 082b57d

Browse files
authored
Merge pull request #643 from kylerokita/build-settings-fix
[Xcodeproj] Fix Build Settings Plist
2 parents 5c432b0 + 40aee1d commit 082b57d

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

Sources/Xcodeproj/XcodeProjectModelSerialization.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,8 @@ extension Xcode.BuildSettingsTable.BuildSettings {
339339
/// applies to classes. Creating a property list representation is totally
340340
/// independent of that serialization infrastructure (though it might well
341341
/// be invoked during of serialization of actual model objects).
342-
fileprivate func asPropertyList() -> PropertyList {
342+
// FIXME: Internal only for unit testing.
343+
func asPropertyList() -> PropertyList {
343344
// Borderline hacky, but the main thing is that adding or changing a
344345
// build setting does not require any changes to the property list
345346
// representation code. Using a handcoded serializer might be more

Tests/XcodeprojTests/XcodeProjectModelSerializationTests.swift

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,57 @@ class XcodeProjectModelSerializationTests: XCTestCase {
7575
XCTAssertEqual(projectClassName, "PBXProject")
7676
}
7777

78+
func testBuildSettingsSerialization() {
79+
80+
// Create build settings.
81+
var buildSettings = Xcode.BuildSettingsTable.BuildSettings()
82+
83+
let productNameValue = "$(TARGET_NAME:c99extidentifier)"
84+
buildSettings.PRODUCT_NAME = productNameValue
85+
86+
let otherSwiftFlagValues = ["$(inherited)", "-DXcode"]
87+
buildSettings.OTHER_SWIFT_FLAGS = otherSwiftFlagValues
88+
89+
// Serialize it to a property list.
90+
let plist = buildSettings.asPropertyList()
91+
92+
// Assert things about plist
93+
guard case let .dictionary(buildSettingsDict) = plist else {
94+
XCTFail("build settings plist must be a dictionary")
95+
return
96+
}
97+
98+
guard
99+
let productNamePlist = buildSettingsDict["PRODUCT_NAME"],
100+
let otherSwiftFlagsPlist = buildSettingsDict["OTHER_SWIFT_FLAGS"]
101+
else {
102+
XCTFail("build settings plist must contain PRODUCT_NAME and OTHER_SWIFT_FLAGS")
103+
return
104+
}
105+
106+
guard case let .string(productName) = productNamePlist else {
107+
XCTFail("productName plist must be a string")
108+
return
109+
}
110+
XCTAssertEqual(productName, productNameValue)
111+
112+
guard case let .array(otherSwiftFlagsPlists) = otherSwiftFlagsPlist else {
113+
XCTFail("otherSwiftFlags plist must be an array")
114+
return
115+
}
116+
117+
let otherSwiftFlags = otherSwiftFlagsPlists.flatMap { flagPlist -> String? in
118+
guard case let .string(flag) = flagPlist else {
119+
XCTFail("otherSwiftFlag plist must be string")
120+
return nil
121+
}
122+
return flag
123+
}
124+
XCTAssertEqual(otherSwiftFlags, otherSwiftFlagValues)
125+
}
126+
78127
static var allTests = [
79-
("testBasicProjectCreation", testBasicProjectSerialization),
128+
("testBasicProjectSerialization", testBasicProjectSerialization),
129+
("testBuildSettingsSerialization", testBuildSettingsSerialization),
80130
]
81131
}

0 commit comments

Comments
 (0)