Skip to content

Commit f07b836

Browse files
jmschonfeldxedin
andauthored
Fix hard-coded path to FoundationEssentialsTests resources (#855) (#901)
SwiftPM used to incorrectly build tests for both host and target. That has been fixed by swiftlang/swift-package-manager#7879. The fix makes sure that if there are any direct macro dependencies in test targets xctest bundle is only built for "host". This means that the hard-coded resources path needs to be updated to include "-tool" suffix. Co-authored-by: Pavel Yaskevich <[email protected]>
1 parent 56c44b0 commit f07b836

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

Tests/FoundationEssentialsTests/ResourceUtilities.swift

+16-3
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,23 @@ func testData(forResource resource: String, withExtension ext: String, subdirect
5656
// swiftpm drops the resources next to the executable, at:
5757
// ./FoundationPreview_FoundationEssentialsTests.resources/Resources/
5858
// Hard-coding the path is unfortunate, but a temporary need until we have a better way to handle this
59-
var path = URL(filePath: ProcessInfo.processInfo.arguments[0])
59+
60+
var toolsResourcesDir = URL(filePath: ProcessInfo.processInfo.arguments[0])
6061
.deletingLastPathComponent()
61-
.appending(component: "FoundationPreview_FoundationEssentialsTests.resources", directoryHint: .isDirectory)
62-
.appending(component: "Resources", directoryHint: .isDirectory)
62+
.appending(component: "FoundationPreview_FoundationEssentialsTests-tool.resources", directoryHint: .isDirectory)
63+
64+
// On Linux the tests are built for the "host" because there are macro tests, on Windows
65+
// the tests are only built for the "target" so we need to figure out whether `-tools`
66+
// resources exist and if so, use them.
67+
let resourcesDir = if FileManager.default.fileExists(atPath: toolsResourcesDir.path) {
68+
toolsResourcesDir
69+
} else {
70+
URL(filePath: ProcessInfo.processInfo.arguments[0])
71+
.deletingLastPathComponent()
72+
.appending(component: "FoundationPreview_FoundationEssentialsTests.resources", directoryHint: .isDirectory)
73+
}
74+
75+
var path = resourcesDir.appending(component: "Resources", directoryHint: .isDirectory)
6376
if let subdirectory {
6477
path.append(path: subdirectory, directoryHint: .isDirectory)
6578
}

0 commit comments

Comments
 (0)