Skip to content

Commit b81dee1

Browse files
committed
Added tests for Xcode project updates
1 parent b7cb4cf commit b81dee1

6 files changed

Lines changed: 99 additions & 10 deletions

File tree

Fixtures/SynchronizedRootGroups/SynchronizedRootGroups.xcodeproj/project.pbxproj

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
archiveVersion = 1;
44
classes = {
55
};
6-
objectVersion = 73;
6+
objectVersion = 77;
77
objects = {
88

99
/* Begin PBXCopyFilesBuildPhase section */
@@ -23,7 +23,7 @@
2323
/* End PBXFileReference section */
2424

2525
/* Begin PBXFileSystemSynchronizedBuildFileExceptionSet section */
26-
6CF05BA32C53F97F00EF267F /* PBXFileSystemSynchronizedBuildFileExceptionSet */ = {
26+
6CF05BA32C53F97F00EF267F /* Exceptions for "SynchronizedRootGroups" folder in "SynchronizedRootGroups" target */ = {
2727
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
2828
membershipExceptions = (
2929
Exception/Exception.swift,
@@ -33,7 +33,7 @@
3333
/* End PBXFileSystemSynchronizedBuildFileExceptionSet section */
3434

3535
/* Begin PBXFileSystemSynchronizedGroupBuildPhaseMembershipExceptionSet section */
36-
F841A9D12D63B00A00059ED6 /* PBXFileSystemSynchronizedGroupBuildPhaseMembershipExceptionSet */ = {
36+
F841A9D12D63B00A00059ED6 /* Exceptions for "SynchronizedRootGroups" folder in "Copy Files" phase from "SynchronizedRootGroups" target */ = {
3737
isa = PBXFileSystemSynchronizedGroupBuildPhaseMembershipExceptionSet;
3838
attributesByRelativePath = {
3939
XPCService.xpc = (
@@ -48,7 +48,15 @@
4848
/* End PBXFileSystemSynchronizedGroupBuildPhaseMembershipExceptionSet section */
4949

5050
/* Begin PBXFileSystemSynchronizedRootGroup section */
51-
6CF05B9D2C53F64800EF267F /* SynchronizedRootGroups */ = {isa = PBXFileSystemSynchronizedRootGroup; exceptions = (6CF05BA32C53F97F00EF267F /* PBXFileSystemSynchronizedBuildFileExceptionSet */, F841A9D12D63B00A00059ED6 /* PBXFileSystemSynchronizedGroupBuildPhaseMembershipExceptionSet */, ); explicitFileTypes = {}; explicitFolders = (); path = SynchronizedRootGroups; sourceTree = "<group>"; };
51+
6CF05B9D2C53F64800EF267F /* SynchronizedRootGroups */ = {
52+
isa = PBXFileSystemSynchronizedRootGroup;
53+
exceptions = (
54+
6CF05BA32C53F97F00EF267F /* Exceptions for "SynchronizedRootGroups" folder in "SynchronizedRootGroups" target */,
55+
F841A9D12D63B00A00059ED6 /* Exceptions for "SynchronizedRootGroups" folder in "Copy Files" phase from "SynchronizedRootGroups" target */,
56+
);
57+
path = SynchronizedRootGroups;
58+
sourceTree = "<group>";
59+
};
5260
/* End PBXFileSystemSynchronizedRootGroup section */
5361

5462
/* Begin PBXFrameworksBuildPhase section */
@@ -138,7 +146,7 @@
138146
Base,
139147
);
140148
mainGroup = 6CF05B822C53F5F200EF267F;
141-
preferredProjectObjectVersion = 60;
149+
preferredProjectObjectVersion = 77;
142150
productRefGroup = 6CF05B8D2C53F5F200EF267F /* Products */;
143151
projectDirPath = "";
144152
projectRoot = "";
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleIdentifier</key>
6+
<string>com.example.XPCService</string>
7+
<key>CFBundleInfoDictionaryVersion</key>
8+
<string>6.0</string>
9+
<key>CFBundleName</key>
10+
<string>XPCService</string>
11+
<key>CFBundlePackageType</key>
12+
<string>XPC!</string>
13+
<key>XPCService</key>
14+
<dict>
15+
<key>ServiceType</key>
16+
<string>Application</string>
17+
</dict>
18+
</dict>
19+
</plist>

Sources/XcodeProj/Objects/Files/PBXFileSystemSynchronizedRootGroup.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ public class PBXFileSystemSynchronizedRootGroup: PBXFileElement {
8383

8484
// MARK: - PlistSerializable
8585

86-
override var multiline: Bool { (exceptions?.count ?? 0) < 2 }
87-
8886
override func assignParentToChildren() {
8987
super.assignParentToChildren()
9088
exceptions?.forEach { $0.synchronizedRootGroup = self }

Tests/XcodeProjTests/Objects/Files/PBXFileSystemSynchronizedBuildFileExceptionSetTests.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,18 @@ final class PBXFileSystemSynchronizedBuildFileExceptionSetTests: XCTestCase {
7575

7676
XCTAssertNil(plistValue.dictionary?[CommentedString("platformFiltersByRelativePath")])
7777
}
78+
79+
func test_plistComment_withSynchronizedRootGroup_returnsDescriptiveComment() {
80+
let group = PBXFileSystemSynchronizedRootGroup(sourceTree: .group, path: "Sources", exceptions: [subject])
81+
XCTAssertEqual(subject.plistComment, "Exceptions for \"Sources\" folder in \"Test\" target")
82+
withExtendedLifetime(group) {}
83+
}
84+
85+
func test_plistKeyAndValue_keyComment_matchesPlistComment() throws {
86+
let proj = PBXProj()
87+
let group = PBXFileSystemSynchronizedRootGroup(sourceTree: .group, path: "Sources", exceptions: [subject])
88+
let (key, _) = try subject.plistKeyAndValue(proj: proj, reference: "ref")
89+
XCTAssertEqual(key.comment, subject.plistComment)
90+
withExtendedLifetime(group) {}
91+
}
7892
}

Tests/XcodeProjTests/Objects/Files/PBXFileSystemSynchronizedRootGroupTests.swift

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,46 @@ final class PBXFileSystemSynchronizedRootGroupTests: XCTestCase {
4848
explicitFolders: [])
4949
XCTAssertEqual(subject, another)
5050
}
51+
52+
// MARK: - plistKeyAndValue
53+
54+
func test_plistKeyAndValue_explicitFileTypes_serializedOnlyWhenNonEmpty() throws {
55+
let (_, nonEmpty) = try subject.plistKeyAndValue(proj: PBXProj(), reference: "ref")
56+
XCTAssertNotNil(nonEmpty.dictionary?[CommentedString("explicitFileTypes")])
57+
58+
subject.explicitFileTypes = [:]
59+
let (_, empty) = try subject.plistKeyAndValue(proj: PBXProj(), reference: "ref")
60+
XCTAssertNil(empty.dictionary?[CommentedString("explicitFileTypes")])
61+
}
62+
63+
func test_plistKeyAndValue_explicitFolders_serializedOnlyWhenNonEmpty() throws {
64+
let (_, empty) = try subject.plistKeyAndValue(proj: PBXProj(), reference: "ref")
65+
XCTAssertNil(empty.dictionary?[CommentedString("explicitFolders")])
66+
67+
subject.explicitFolders = ["SubFolder"]
68+
let (_, nonEmpty) = try subject.plistKeyAndValue(proj: PBXProj(), reference: "ref")
69+
XCTAssertNotNil(nonEmpty.dictionary?[CommentedString("explicitFolders")])
70+
}
71+
72+
func test_plistKeyAndValue_name_serializedOnlyWhenDifferentFromPath() throws {
73+
let (_, same) = try subject.plistKeyAndValue(proj: PBXProj(), reference: "ref")
74+
XCTAssertNil(same.dictionary?[CommentedString("name")])
75+
76+
subject.name = "Display Name"
77+
let (_, different) = try subject.plistKeyAndValue(proj: PBXProj(), reference: "ref")
78+
XCTAssertEqual(different.dictionary?[CommentedString("name")], .string(CommentedString("Display Name")))
79+
}
80+
81+
func test_plistKeyAndValue_exceptionReference_usesDescriptiveComment() throws {
82+
let (_, value) = try subject.plistKeyAndValue(proj: PBXProj(), reference: "ref")
83+
let exceptionsArray = try XCTUnwrap(value.dictionary?[CommentedString("exceptions")]?.array)
84+
let entry = try XCTUnwrap(exceptionsArray.first?.string)
85+
XCTAssertEqual(entry.comment, "Exceptions for \"synchronized\" folder in \"Test\" target")
86+
}
87+
88+
// MARK: - assignParentToChildren
89+
90+
func test_assignParentToChildren_wiresSynchronizedRootGroup() {
91+
XCTAssertIdentical(exception.synchronizedRootGroup, subject)
92+
}
5193
}

Tests/XcodeProjTests/Objects/Project/PBXProjEncoderTests.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,15 @@
294294
let lines = lines(fromFile: encodeProject(settings: settings))
295295

296296
let beginGroup = lines.findLine("/* Begin PBXFileSystemSynchronizedRootGroup section */")
297-
var line = lines.validate(line: "6CF05B9D2C53F64800EF267F /* SynchronizedRootGroups */ = {isa = PBXFileSystemSynchronizedRootGroup; exceptions = (6CF05BA32C53F97F00EF267F /* PBXFileSystemSynchronizedBuildFileExceptionSet */, F841A9D12D63B00A00059ED6 /* PBXFileSystemSynchronizedGroupBuildPhaseMembershipExceptionSet */, ); explicitFileTypes = {}; explicitFolders = (); path = SynchronizedRootGroups; sourceTree = \"<group>\"; };", after: beginGroup)
297+
var line = lines.validate(line: "6CF05B9D2C53F64800EF267F /* SynchronizedRootGroups */ = {", after: beginGroup)
298+
line = lines.validate(line: "isa = PBXFileSystemSynchronizedRootGroup;", after: line)
299+
line = lines.validate(line: "exceptions = (", after: line)
300+
line = lines.validate(line: "6CF05BA32C53F97F00EF267F /* Exceptions for \"SynchronizedRootGroups\" folder in \"SynchronizedRootGroups\" target */,", after: line)
301+
line = lines.validate(line: "F841A9D12D63B00A00059ED6 /* Exceptions for \"SynchronizedRootGroups\" folder in \"Copy Files\" phase from \"SynchronizedRootGroups\" target */,", after: line)
302+
line = lines.validate(line: ");", after: line)
303+
line = lines.validate(line: "path = SynchronizedRootGroups;", after: line)
304+
line = lines.validate(line: "sourceTree = \"<group>\";", after: line)
305+
line = lines.validate(line: "};", after: line)
298306
line = lines.validate(line: "/* End PBXFileSystemSynchronizedRootGroup section */", after: line)
299307
}
300308

@@ -307,7 +315,7 @@
307315
let lines = lines(fromFile: encodeProject(settings: settings))
308316

309317
let beginGroup = lines.findLine("/* Begin PBXFileSystemSynchronizedBuildFileExceptionSet section */")
310-
var line = lines.validate(line: "6CF05BA32C53F97F00EF267F /* PBXFileSystemSynchronizedBuildFileExceptionSet */ = {", after: beginGroup)
318+
var line = lines.validate(line: "6CF05BA32C53F97F00EF267F /* Exceptions for \"SynchronizedRootGroups\" folder in \"SynchronizedRootGroups\" target */ = {", after: beginGroup)
311319
line = lines.validate(line: "isa = PBXFileSystemSynchronizedBuildFileExceptionSet;", after: line)
312320
line = lines.validate(line: "membershipExceptions = (", after: line)
313321
line = lines.validate(line: "Exception/Exception.swift,", after: line)
@@ -326,7 +334,7 @@
326334
let lines = lines(fromFile: encodeProject(settings: settings))
327335

328336
let beginGroup = lines.findLine("/* Begin PBXFileSystemSynchronizedGroupBuildPhaseMembershipExceptionSet section */")
329-
var line = lines.validate(line: "F841A9D12D63B00A00059ED6 /* PBXFileSystemSynchronizedGroupBuildPhaseMembershipExceptionSet */ = {", after: beginGroup)
337+
var line = lines.validate(line: "F841A9D12D63B00A00059ED6 /* Exceptions for \"SynchronizedRootGroups\" folder in \"Copy Files\" phase from \"SynchronizedRootGroups\" target */ = {", after: beginGroup)
330338
line = lines.validate(line: "isa = PBXFileSystemSynchronizedGroupBuildPhaseMembershipExceptionSet;", after: line)
331339
line = lines.validate(line: "attributesByRelativePath = {", after: line)
332340
line = lines.validate(line: "XPCService.xpc = (", after: line)

0 commit comments

Comments
 (0)