Skip to content

Commit a6a6bb7

Browse files
committed
Fix accidentally-introduced warnings and regression in test behavior in PIFLoadingTests
Some of the conditional checks had redundant uses of #require, and regressed previous behavior by failing to include an else case to induce a test failure when the condition was not satisfied.
1 parent ddc2552 commit a6a6bb7

File tree

1 file changed

+80
-42
lines changed

1 file changed

+80
-42
lines changed

Tests/SWBCoreTests/PIFLoadingTests.swift

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

685685
// Examine its children
686-
if let fileRef = try? #require(fileGroup.children.first as? FileReference) {
686+
if let fileRef = 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")
692694
}
693-
if let fileRef = try? #require(fileGroup.children[1] as? FileReference) {
695+
696+
if let fileRef = fileGroup.children[1] as? FileReference {
694697
#expect(fileRef.guid == "second-fileReference-guid")
695698
#expect(fileRef.sourceTree == SourceTree.groupRelative)
696699
#expect(fileRef.path.stringRep == "ClassOne.h")
697700
#expect(fileRef.fileTypeIdentifier == "sourcecode.c.h")
698701
#expect(fileRef.regionVariantName == nil)
702+
} else {
703+
Issue.record("Missing file reference in group")
699704
}
700705
}
701706

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

742747
// Examine its children
743-
if let fileRef = try? #require(versionGroup.children[0] as? FileReference) {
748+
if let fileRef = versionGroup.children[0] as? FileReference {
744749
#expect(fileRef.guid == "first-versionedFile-guid")
745750
#expect(fileRef.sourceTree == SourceTree.groupRelative)
746751
#expect(fileRef.path.stringRep == "CoreData-1.xcdatamodel")
747752
#expect(fileRef.fileTypeIdentifier == "wrapper.xcdatamodel")
748753
#expect(fileRef.regionVariantName == nil)
754+
} else {
755+
Issue.record("Missing file reference in group")
749756
}
750-
if let fileRef = try? #require(versionGroup.children[1] as? FileReference) {
757+
758+
if let fileRef = versionGroup.children[1] as? FileReference {
751759
#expect(fileRef.guid == "second-versionedFile-guid")
752760
#expect(fileRef.sourceTree == SourceTree.groupRelative)
753761
#expect(fileRef.path.stringRep == "CoreData-2.xcdatamodel")
754762
#expect(fileRef.fileTypeIdentifier == "wrapper.xcdatamodel")
755763
#expect(fileRef.regionVariantName == nil)
764+
} else {
765+
Issue.record("Missing file reference in group")
756766
}
757767
}
758768

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

823833
// Examine its children, the xib and its localized strings files
824-
if let fileRef = try? #require(variantGroup.children[0] as? FileReference) {
834+
if let fileRef = variantGroup.children[0] as? FileReference {
825835
#expect(fileRef.guid == "xib-fileReference-guid")
826836
#expect(fileRef.sourceTree == SourceTree.groupRelative)
827837
#expect(fileRef.path.stringRep == "Thingy.xib")
828838
#expect(fileRef.fileTypeIdentifier == "file.xib")
829839
#expect(fileRef.regionVariantName == nil)
840+
} else {
841+
Issue.record("Missing file reference in group")
830842
}
831-
if let fileRef = try? #require(variantGroup.children[1] as? FileReference) {
843+
844+
if let fileRef = variantGroup.children[1] as? FileReference {
832845
#expect(fileRef.guid == "fr-strings-fileReference-guid")
833846
#expect(fileRef.sourceTree == SourceTree.groupRelative)
834847
#expect(fileRef.path.stringRep == "Thingy.strings")
835848
#expect(fileRef.fileTypeIdentifier == "text.plist.strings")
836849
#expect(fileRef.regionVariantName == "fr")
850+
} else {
851+
Issue.record("Missing file reference in group")
837852
}
838-
if let fileRef = try? #require(variantGroup.children[2] as? FileReference) {
853+
854+
if let fileRef = variantGroup.children[2] as? FileReference {
839855
#expect(fileRef.guid == "de-strings-fileReference-guid")
840856
#expect(fileRef.sourceTree == SourceTree.groupRelative)
841857
#expect(fileRef.path.stringRep == "Thingy.strings")
842858
#expect(fileRef.fileTypeIdentifier == "text.plist.strings")
843859
#expect(fileRef.regionVariantName == "de")
860+
} else {
861+
Issue.record("Missing file reference in group")
844862
}
845863
}
846864

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

943961
// Convert the test data into a property list, then read the build phase from it.
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-
}
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+
})
948970
}
949971

950972
// A headers build phase
@@ -962,10 +984,14 @@ private final class ProjectModelItemClass: ProjectModelItem {
962984
]
963985

964986
// Convert the test data into a property list, then read the build phase from it.
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-
}
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+
})
969995
}
970996

971997
// A resources build phase
@@ -983,10 +1009,14 @@ private final class ProjectModelItemClass: ProjectModelItem {
9831009
]
9841010

9851011
// Convert the test data into a property list, then read the build phase from it.
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-
}
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+
})
9901020
}
9911021

9921022
// A copy files build phase
@@ -1007,13 +1037,17 @@ private final class ProjectModelItemClass: ProjectModelItem {
10071037
]
10081038

10091039
// Convert the test data into a property list, then read the build phase from it.
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-
}
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+
})
10171051
}
10181052

10191053
// A shell script build phase
@@ -1036,20 +1070,24 @@ private final class ProjectModelItemClass: ProjectModelItem {
10361070
]
10371071

10381072
// Convert the test data into a property list, then read the build phase from it.
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-
}
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+
})
10531091
}
10541092
}
10551093

@@ -1352,7 +1390,8 @@ private final class ProjectModelItemClass: ProjectModelItem {
13521390

13531391
// 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.
13541392
func checkBuildFileRef(of buildPhase: BuildPhaseWithBuildFiles, fileRef: FileReference) throws {
1355-
guard let buildFileRef = try? #require(buildPhase.buildFiles.first) else {
1393+
guard let buildFileRef = buildPhase.buildFiles.first else {
1394+
Issue.record("No build file in build phase")
13561395
return
13571396
}
13581397
guard case let .reference(buildFileRefGuid) = buildFileRef.buildableItem else {
@@ -1726,4 +1765,3 @@ private final class ProjectModelItemClass: ProjectModelItem {
17261765
])
17271766
}
17281767
}
1729-

0 commit comments

Comments
 (0)