Skip to content

Commit d4eb98c

Browse files
committed
Revert "Fix accidentally-introduced warnings and regression in test behavior in PIFLoadingTests"
The original code was correct and these changes overlooked some context as to why the original code was the way it was (e.g., the warnings are due to a compiler bug, #require will already emit an issue). But we can work around most of the warnings by casting to an optional, which is low-profile and allows us to retain the same approach to these checks, so that has been added where possible. This reverts commit a6a6bb7.
1 parent 713303e commit d4eb98c

File tree

1 file changed

+41
-80
lines changed

1 file changed

+41
-80
lines changed

Tests/SWBCoreTests/PIFLoadingTests.swift

Lines changed: 41 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -683,24 +683,19 @@ private final class ProjectModelItemClass: ProjectModelItem {
683683
#expect(fileGroup.children.count == 2)
684684

685685
// Examine its children
686-
if let fileRef = fileGroup.children.first as? FileReference {
686+
if let fileRef = try? #require(fileGroup.children.first as? FileReference?) {
687687
#expect(fileRef.guid == "first-fileReference-guid")
688688
#expect(fileRef.sourceTree == SourceTree.groupRelative)
689689
#expect(fileRef.path.stringRep == "ClassOne.m")
690690
#expect(fileRef.fileTypeIdentifier == "sourcecode.c.objc")
691691
#expect(fileRef.regionVariantName == nil)
692-
} else {
693-
Issue.record("Missing file reference in group")
694692
}
695-
696-
if let fileRef = fileGroup.children[1] as? FileReference {
693+
if let fileRef = try? #require(fileGroup.children[1] as? FileReference?) {
697694
#expect(fileRef.guid == "second-fileReference-guid")
698695
#expect(fileRef.sourceTree == SourceTree.groupRelative)
699696
#expect(fileRef.path.stringRep == "ClassOne.h")
700697
#expect(fileRef.fileTypeIdentifier == "sourcecode.c.h")
701698
#expect(fileRef.regionVariantName == nil)
702-
} else {
703-
Issue.record("Missing file reference in group")
704699
}
705700
}
706701

@@ -745,24 +740,19 @@ private final class ProjectModelItemClass: ProjectModelItem {
745740
#expect(versionGroup.children.count == 2)
746741

747742
// Examine its children
748-
if let fileRef = versionGroup.children[0] as? FileReference {
743+
if let fileRef = try? #require(versionGroup.children[0] as? FileReference?) {
749744
#expect(fileRef.guid == "first-versionedFile-guid")
750745
#expect(fileRef.sourceTree == SourceTree.groupRelative)
751746
#expect(fileRef.path.stringRep == "CoreData-1.xcdatamodel")
752747
#expect(fileRef.fileTypeIdentifier == "wrapper.xcdatamodel")
753748
#expect(fileRef.regionVariantName == nil)
754-
} else {
755-
Issue.record("Missing file reference in group")
756749
}
757-
758-
if let fileRef = versionGroup.children[1] as? FileReference {
750+
if let fileRef = try? #require(versionGroup.children[1] as? FileReference?) {
759751
#expect(fileRef.guid == "second-versionedFile-guid")
760752
#expect(fileRef.sourceTree == SourceTree.groupRelative)
761753
#expect(fileRef.path.stringRep == "CoreData-2.xcdatamodel")
762754
#expect(fileRef.fileTypeIdentifier == "wrapper.xcdatamodel")
763755
#expect(fileRef.regionVariantName == nil)
764-
} else {
765-
Issue.record("Missing file reference in group")
766756
}
767757
}
768758

@@ -831,34 +821,26 @@ private final class ProjectModelItemClass: ProjectModelItem {
831821
#expect(variantGroup.name == "Thingy.xib")
832822

833823
// Examine its children, the xib and its localized strings files
834-
if let fileRef = variantGroup.children[0] as? FileReference {
824+
if let fileRef = try? #require(variantGroup.children[0] as? FileReference?) {
835825
#expect(fileRef.guid == "xib-fileReference-guid")
836826
#expect(fileRef.sourceTree == SourceTree.groupRelative)
837827
#expect(fileRef.path.stringRep == "Thingy.xib")
838828
#expect(fileRef.fileTypeIdentifier == "file.xib")
839829
#expect(fileRef.regionVariantName == nil)
840-
} else {
841-
Issue.record("Missing file reference in group")
842830
}
843-
844-
if let fileRef = variantGroup.children[1] as? FileReference {
831+
if let fileRef = try? #require(variantGroup.children[1] as? FileReference?) {
845832
#expect(fileRef.guid == "fr-strings-fileReference-guid")
846833
#expect(fileRef.sourceTree == SourceTree.groupRelative)
847834
#expect(fileRef.path.stringRep == "Thingy.strings")
848835
#expect(fileRef.fileTypeIdentifier == "text.plist.strings")
849836
#expect(fileRef.regionVariantName == "fr")
850-
} else {
851-
Issue.record("Missing file reference in group")
852837
}
853-
854-
if let fileRef = variantGroup.children[2] as? FileReference {
838+
if let fileRef = try? #require(variantGroup.children[2] as? FileReference?) {
855839
#expect(fileRef.guid == "de-strings-fileReference-guid")
856840
#expect(fileRef.sourceTree == SourceTree.groupRelative)
857841
#expect(fileRef.path.stringRep == "Thingy.strings")
858842
#expect(fileRef.fileTypeIdentifier == "text.plist.strings")
859843
#expect(fileRef.regionVariantName == "de")
860-
} else {
861-
Issue.record("Missing file reference in group")
862844
}
863845
}
864846

@@ -959,14 +941,10 @@ private final class ProjectModelItemClass: ProjectModelItem {
959941
]
960942

961943
// Convert the test data into a property list, then read the build phase from it.
962-
#expect(throws: Never.self, performing: {
963-
if let buildPhase = try BuildPhase.parsePIFDictAsBuildPhase(buildPhasePIF, pifLoader: pifLoader) as? SourcesBuildPhase {
964-
// Examine the build phase.
965-
#expect(buildPhase.buildFiles.count == 1)
966-
} else {
967-
Issue.record("Unexpected build phase type")
968-
}
969-
})
944+
if let buildPhase = try? #require(BuildPhase.parsePIFDictAsBuildPhase(buildPhasePIF, pifLoader: pifLoader) as? SourcesBuildPhase?) {
945+
// Examine the build phase.
946+
#expect(buildPhase.buildFiles.count == 1)
947+
}
970948
}
971949

972950
// A headers build phase
@@ -984,14 +962,10 @@ private final class ProjectModelItemClass: ProjectModelItem {
984962
]
985963

986964
// Convert the test data into a property list, then read the build phase from it.
987-
#expect(throws: Never.self, performing: {
988-
if let buildPhase = try BuildPhase.parsePIFDictAsBuildPhase(buildPhasePIF, pifLoader: pifLoader) as? HeadersBuildPhase {
989-
// Examine the build phase.
990-
#expect(buildPhase.buildFiles.count == 1)
991-
} else {
992-
Issue.record("Unexpected build phase type")
993-
}
994-
})
965+
if let buildPhase = try? #require(BuildPhase.parsePIFDictAsBuildPhase(buildPhasePIF, pifLoader: pifLoader) as? HeadersBuildPhase?) {
966+
// Examine the build phase.
967+
#expect(buildPhase.buildFiles.count == 1)
968+
}
995969
}
996970

997971
// A resources build phase
@@ -1009,14 +983,10 @@ private final class ProjectModelItemClass: ProjectModelItem {
1009983
]
1010984

1011985
// Convert the test data into a property list, then read the build phase from it.
1012-
#expect(throws: Never.self, performing: {
1013-
if let buildPhase = try BuildPhase.parsePIFDictAsBuildPhase(buildPhasePIF, pifLoader: pifLoader) as? ResourcesBuildPhase {
1014-
// Examine the build phase.
1015-
#expect(buildPhase.buildFiles.count == 1)
1016-
} else {
1017-
Issue.record("Unexpected build phase type")
1018-
}
1019-
})
986+
if let buildPhase = try? #require(BuildPhase.parsePIFDictAsBuildPhase(buildPhasePIF, pifLoader: pifLoader) as? ResourcesBuildPhase?) {
987+
// Examine the build phase.
988+
#expect(buildPhase.buildFiles.count == 1)
989+
}
1020990
}
1021991

1022992
// A copy files build phase
@@ -1037,17 +1007,13 @@ private final class ProjectModelItemClass: ProjectModelItem {
10371007
]
10381008

10391009
// Convert the test data into a property list, then read the build phase from it.
1040-
#expect(throws: Never.self, performing: {
1041-
if let buildPhase = try BuildPhase.parsePIFDictAsBuildPhase(buildPhasePIF, pifLoader: pifLoader) as? CopyFilesBuildPhase {
1042-
// Examine the build phase.
1043-
#expect(buildPhase.destinationSubfolder.stringRep == "Resources")
1044-
#expect(buildPhase.destinationSubpath.stringRep == "Subpath")
1045-
#expect(buildPhase.buildFiles.count == 1)
1046-
#expect(buildPhase.runOnlyForDeploymentPostprocessing);
1047-
} else {
1048-
Issue.record("Unexpected build phase type")
1049-
}
1050-
})
1010+
if let buildPhase = try? #require(BuildPhase.parsePIFDictAsBuildPhase(buildPhasePIF, pifLoader: pifLoader) as? CopyFilesBuildPhase?) {
1011+
// Examine the build phase.
1012+
#expect(buildPhase.destinationSubfolder.stringRep == "Resources")
1013+
#expect(buildPhase.destinationSubpath.stringRep == "Subpath")
1014+
#expect(buildPhase.buildFiles.count == 1)
1015+
#expect(buildPhase.runOnlyForDeploymentPostprocessing);
1016+
}
10511017
}
10521018

10531019
// A shell script build phase
@@ -1070,24 +1036,20 @@ private final class ProjectModelItemClass: ProjectModelItem {
10701036
]
10711037

10721038
// Convert the test data into a property list, then read the build phase from it.
1073-
#expect(throws: Never.self, performing: {
1074-
if let buildPhase = try BuildPhase.parsePIFDictAsBuildPhase(buildPhasePIF, pifLoader: pifLoader) as? ShellScriptBuildPhase {
1075-
// Examine the build phase.
1076-
#expect(buildPhase.guid == "some-shellScriptBuildPhase-guid")
1077-
#expect(buildPhase.name == "A Shell Script Phase")
1078-
#expect(buildPhase.shellPath.stringRep == "/bin/sh")
1079-
#expect(buildPhase.scriptContents == "echo \"Nothing to do.\"\nexit 0")
1080-
#expect(buildPhase.originalObjectID == "1234512345")
1081-
#expect(buildPhase.inputFilePaths.count == 1)
1082-
#expect(buildPhase.inputFilePaths.first?.stringRep == "/tmp/foo.in")
1083-
#expect(buildPhase.outputFilePaths.count == 1)
1084-
#expect(buildPhase.outputFilePaths.first?.stringRep == "/tmp/foo.out")
1085-
#expect(buildPhase.emitEnvironment);
1086-
#expect(buildPhase.runOnlyForDeploymentPostprocessing);
1087-
} else {
1088-
Issue.record("Unexpected build phase type")
1089-
}
1090-
})
1039+
if let buildPhase = try? #require(BuildPhase.parsePIFDictAsBuildPhase(buildPhasePIF, pifLoader: pifLoader) as? ShellScriptBuildPhase?) {
1040+
// Examine the build phase.
1041+
#expect(buildPhase.guid == "some-shellScriptBuildPhase-guid")
1042+
#expect(buildPhase.name == "A Shell Script Phase")
1043+
#expect(buildPhase.shellPath.stringRep == "/bin/sh")
1044+
#expect(buildPhase.scriptContents == "echo \"Nothing to do.\"\nexit 0")
1045+
#expect(buildPhase.originalObjectID == "1234512345")
1046+
#expect(buildPhase.inputFilePaths.count == 1)
1047+
#expect(buildPhase.inputFilePaths.first?.stringRep == "/tmp/foo.in")
1048+
#expect(buildPhase.outputFilePaths.count == 1)
1049+
#expect(buildPhase.outputFilePaths.first?.stringRep == "/tmp/foo.out")
1050+
#expect(buildPhase.emitEnvironment);
1051+
#expect(buildPhase.runOnlyForDeploymentPostprocessing);
1052+
}
10911053
}
10921054
}
10931055

@@ -1391,8 +1353,7 @@ private final class ProjectModelItemClass: ProjectModelItem {
13911353

13921354
// Because of the way reference resolution of a BuildFile.BuildableItem works, we don't have a context to resolve the build file's references to real references, so all we can do is check that the GUID is what we expect.
13931355
func checkBuildFileRef(of buildPhase: BuildPhaseWithBuildFiles, fileRef: FileReference) throws {
1394-
guard let buildFileRef = buildPhase.buildFiles.first else {
1395-
Issue.record("No build file in build phase")
1356+
guard let buildFileRef = try? #require(buildPhase.buildFiles.first) else {
13961357
return
13971358
}
13981359
guard case let .reference(buildFileRefGuid) = buildFileRef.buildableItem else {

0 commit comments

Comments
 (0)