Skip to content

[6.0] Fix hard-coded path to FoundationEssentialsTests resources #887

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions Tests/FoundationEssentialsTests/ResourceUtilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,23 @@ func testData(forResource resource: String, withExtension ext: String, subdirect
// swiftpm drops the resources next to the executable, at:
// ./FoundationPreview_FoundationEssentialsTests.resources/Resources/
// Hard-coding the path is unfortunate, but a temporary need until we have a better way to handle this
var path = URL(filePath: ProcessInfo.processInfo.arguments[0])

var toolsResourcesDir = URL(filePath: ProcessInfo.processInfo.arguments[0])
.deletingLastPathComponent()
.appending(component: "FoundationPreview_FoundationEssentialsTests.resources", directoryHint: .isDirectory)
.appending(component: "Resources", directoryHint: .isDirectory)
.appending(component: "FoundationPreview_FoundationEssentialsTests-tool.resources", directoryHint: .isDirectory)

// On Linux the tests are built for the "host" because there are macro tests, on Windows
// the tests are only built for the "target" so we need to figure out whether `-tools`
// resources exist and if so, use them.
let resourcesDir = if FileManager.default.fileExists(atPath: toolsResourcesDir.path) {
toolsResourcesDir
} else {
URL(filePath: ProcessInfo.processInfo.arguments[0])
.deletingLastPathComponent()
.appending(component: "FoundationPreview_FoundationEssentialsTests.resources", directoryHint: .isDirectory)
}

var path = resourcesDir.appending(component: "Resources", directoryHint: .isDirectory)
if let subdirectory {
path.append(path: subdirectory, directoryHint: .isDirectory)
}
Expand Down