Skip to content

Commit 442dbda

Browse files
committed
throw exceptions and fixing tests
1 parent 1556a98 commit 442dbda

6 files changed

Lines changed: 16 additions & 44 deletions

File tree

XcodeProject.xcodeproj/project.pbxproj

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,9 @@
4242
6C2644271E11C80A0057CFA4 /* XCVersionGroup.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C2644051E11C80A0057CFA4 /* XCVersionGroup.swift */; };
4343
6C2644281E11C80A0057CFA4 /* ProjectFile.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C2644061E11C80A0057CFA4 /* ProjectFile.swift */; };
4444
6C82B6841FFC03180040FD50 /* Workspace.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C82B6831FFC03180040FD50 /* Workspace.swift */; };
45-
6CBB7D7F1F002EC300188560 /* DiffTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CD0855E1EFF581C00AEC92A /* DiffTests.swift */; };
4645
6CD2228D1DDD5C180058C7CD /* XcodeProject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6CD222831DDD5C180058C7CD /* XcodeProject.framework */; };
4746
6CD222921DDD5C180058C7CD /* XcodeProjectTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CD222911DDD5C180058C7CD /* XcodeProjectTests.swift */; };
48-
6CE0F78A1E0C69FC001DF692 /* GlobalIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CE0F7891E0C69FC001DF692 /* GlobalIDTests.swift */; };
47+
6CE0F78A1E0C69FC001DF692 /* PBXObjectIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CE0F7891E0C69FC001DF692 /* PBXObjectIDTests.swift */; };
4948
6CE0F7BA1E0CAB23001DF692 /* Projects in Resources */ = {isa = PBXBuildFile; fileRef = 6CE0F7B91E0CAB23001DF692 /* Projects */; };
5049
6CE346AD1FE9B2E400EFF588 /* PBXGroup+Sorting.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CE346AC1FE9B2E400EFF588 /* PBXGroup+Sorting.swift */; };
5150
6CE346AF1FE9B45E00EFF588 /* PBXGroup+FolderSync.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CE346AE1FE9B45E00EFF588 /* PBXGroup+FolderSync.swift */; };
@@ -102,12 +101,11 @@
102101
6C2644061E11C80A0057CFA4 /* ProjectFile.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProjectFile.swift; sourceTree = "<group>"; };
103102
6C2644081E11C80A0057CFA4 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
104103
6C82B6831FFC03180040FD50 /* Workspace.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Workspace.swift; sourceTree = "<group>"; };
105-
6CD0855E1EFF581C00AEC92A /* DiffTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiffTests.swift; sourceTree = "<group>"; };
106104
6CD222831DDD5C180058C7CD /* XcodeProject.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = XcodeProject.framework; sourceTree = BUILT_PRODUCTS_DIR; };
107105
6CD2228C1DDD5C180058C7CD /* XcodeProjectTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = XcodeProjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
108106
6CD222911DDD5C180058C7CD /* XcodeProjectTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XcodeProjectTests.swift; sourceTree = "<group>"; };
109107
6CD222931DDD5C180058C7CD /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
110-
6CE0F7891E0C69FC001DF692 /* GlobalIDTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GlobalIDTests.swift; sourceTree = "<group>"; };
108+
6CE0F7891E0C69FC001DF692 /* PBXObjectIDTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PBXObjectIDTests.swift; sourceTree = "<group>"; };
111109
6CE0F7B91E0CAB23001DF692 /* Projects */ = {isa = PBXFileReference; lastKnownFileType = folder; path = Projects; sourceTree = "<group>"; };
112110
6CE346AC1FE9B2E400EFF588 /* PBXGroup+Sorting.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PBXGroup+Sorting.swift"; sourceTree = "<group>"; };
113111
6CE346AE1FE9B45E00EFF588 /* PBXGroup+FolderSync.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PBXGroup+FolderSync.swift"; sourceTree = "<group>"; };
@@ -262,8 +260,7 @@
262260
isa = PBXGroup;
263261
children = (
264262
6CD222931DDD5C180058C7CD /* Info.plist */,
265-
6CD0855E1EFF581C00AEC92A /* DiffTests.swift */,
266-
6CE0F7891E0C69FC001DF692 /* GlobalIDTests.swift */,
263+
6CE0F7891E0C69FC001DF692 /* PBXObjectIDTests.swift */,
267264
6CD222911DDD5C180058C7CD /* XcodeProjectTests.swift */,
268265
6CD2229F1DDD5CC10058C7CD /* Resources */,
269266
);
@@ -281,9 +278,9 @@
281278
6CE346AB1FE9B24000EFF588 /* Objects+Extensions */ = {
282279
isa = PBXGroup;
283280
children = (
284-
6C2643F91E11C80A0057CFA4 /* PBXProject+Helpers.swift */,
285-
6CE346AC1FE9B2E400EFF588 /* PBXGroup+Sorting.swift */,
286281
6CE346AE1FE9B45E00EFF588 /* PBXGroup+FolderSync.swift */,
282+
6CE346AC1FE9B2E400EFF588 /* PBXGroup+Sorting.swift */,
283+
6C2643F91E11C80A0057CFA4 /* PBXProject+Helpers.swift */,
287284
6CE346B01FE9B4F600EFF588 /* PBXReference+Extensions.swift */,
288285
6CE346CB1FECA29100EFF588 /* PBXTarget+Extensions.swift */,
289286
);
@@ -456,8 +453,7 @@
456453
buildActionMask = 2147483647;
457454
files = (
458455
6CD222921DDD5C180058C7CD /* XcodeProjectTests.swift in Sources */,
459-
6CBB7D7F1F002EC300188560 /* DiffTests.swift in Sources */,
460-
6CE0F78A1E0C69FC001DF692 /* GlobalIDTests.swift in Sources */,
456+
6CE0F78A1E0C69FC001DF692 /* PBXObjectIDTests.swift in Sources */,
461457
);
462458
runOnlyForDeploymentPostprocessing = 0;
463459
};

XcodeProject/Objects+Extensions/PBXProject+Helpers.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public extension PBXProject {
1313
}
1414
public extension PBXProject {
1515
func addTarget(name: String, type: PBXNativeTarget.ProductType) {
16-
let target = PBXNativeTarget(globalID: PBXObject.ID())
16+
let target = PBXNativeTarget(globalID: generateGlobalId())
1717
target.name = name
1818
target.productName = name
1919
target.productType = type

XcodeProject/ProjectFile.swift

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,19 @@ public final class ProjectFile {
3838
///
3939
/// - Parameter url: Path to an xcodeproj file to be opened
4040
/// - Returns: A fully parsed project from the provided source or `nil` if an error happened
41-
public init?(url: URL) {
41+
public init?(url: URL) throws {
4242
self.url = url
4343
do {
4444
self.fileWrapper = try FileWrapper(url: url, options: [])
4545
} catch {
4646
return nil
4747
}
48-
if fileWrapper.isDirectory == false {
49-
//throw
48+
guard fileWrapper.isDirectory else {
49+
throw CocoaError.error(.fileReadUnknown)
5050
}
5151

5252
guard let pbxproj = fileWrapper.fileWrappers?["project.pbxproj"], pbxproj.isRegularFile else {
53-
// throw
54-
return nil
53+
throw CocoaError.error(.fileReadUnknown)
5554
}
5655

5756
guard let data = pbxproj.regularFileContents else {
@@ -109,8 +108,7 @@ extension ProjectFile {
109108
let destination = destination ?? url
110109

111110
guard let oldPbxproj = fileWrapper.fileWrappers?["project.pbxproj"], oldPbxproj.isRegularFile else {
112-
// throw
113-
return
111+
throw CocoaError.error(.fileReadUnknown)
114112
}
115113

116114
let dataStream = DataStreamWriter()

XcodeProjectTests/DiffTests.swift

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// PBXObject.IDTests.swift
2+
// PBXObjectIDTests.swift
33
// XcodeProject
44
//
55
// Created by Geoffrey Foster on 2016-12-22.
@@ -9,7 +9,7 @@
99
import XCTest
1010
@testable import XcodeProject
1111

12-
class PBXObject.IDTests: XCTestCase {
12+
class PBXObjectIDTests: XCTestCase {
1313

1414
func testIDGeneration() {
1515
var generator = PBXObject.ID.IDGenerator(userName: "XcodeProject", processId: 50_000, referenceDateFunc: { () -> UInt32 in

XcodeProjectTests/XcodeProjectTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class XcodeProjectTests: XCTestCase {
1313

1414
@inline(__always)
1515
func assertReadWriteProject(xcodeprojURL: URL) {
16-
let projectFile = ProjectFile(url: xcodeprojURL)!
16+
let projectFile = try! ProjectFile(url: xcodeprojURL)!
1717

1818
let archiver = PBXPListArchiver(projectFile: projectFile)
1919
let streamWriter = StringStreamWriter()
@@ -40,7 +40,7 @@ class XcodeProjectTests: XCTestCase {
4040

4141
do {
4242
try FileManager.default.copyItem(at: xcodeprojURL, to: copyiedProjectURL)
43-
let projectFile = ProjectFile(url: copyiedProjectURL)!
43+
let projectFile = try! ProjectFile(url: copyiedProjectURL)!
4444
projectFile.project.mainGroup.sort(recursive: true, by: .type)
4545
try projectFile.save()
4646
} catch (let error) {

0 commit comments

Comments
 (0)