Skip to content

Commit

Permalink
Locate the test databases using #filePath
Browse files Browse the repository at this point in the history
In Xcode `SRCROOT` isn't passed in the environment
anymore.
  • Loading branch information
helje5 committed Nov 20, 2024
1 parent 6d58ece commit aaad5b7
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions Tests/ZeeQLTests/ContactsDBModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,16 @@ import class Foundation.FileManager
import struct Foundation.URL

internal func lookupTestDataPath() -> String {
let path = ProcessInfo.processInfo.environment["SRCROOT"]
?? FileManager.default.currentDirectoryPath
let fm = FileManager.default

let dataPath : String = {
let fm = FileManager.default
// This isn't set anymore when running the test in Xcode 16.1?
if let path = ProcessInfo.processInfo.environment["SRCROOT"], !path.isEmpty {
if fm.fileExists(atPath: "\(path)/data") { return "\(path)/data" }
fatalError("could not locate data path in SRCROOT: \(path)")
}

do { // Xcode 16: runs in /private/tmp
let path = FileManager.default.currentDirectoryPath
if fm.fileExists(atPath: "\(path)/data") { return "\(path)/data" }

// on Linux we seem to be in `/src/Tests/ZeeQLTests`, so step up two
Expand All @@ -164,9 +169,23 @@ internal func lookupTestDataPath() -> String {
.deletingLastPathComponent()
.appendingPathComponent("data")
if fm.fileExists(atPath: url.path) { return url.path }

print("could not locate data path in:", path)
return "\(path)/data"
}()
return dataPath
print("could not locate data path in current dir:", path)
}

do {
let path = #filePath // Tests/ZeeQLTests/ContactsDBModel.swift
let url = URL(fileURLWithPath: path)
.deletingLastPathComponent()
.deletingLastPathComponent()
.deletingLastPathComponent()
.appendingPathComponent("data")
if fm.fileExists(atPath: url.path) { return url.path }
print("could not locate data path in src dir:", path)
}

for ( key, value ) in ProcessInfo.processInfo.environment {
print("\(key):", value)
}
fatalError("Missing data path?")
//return "\(path)/data"
}

0 comments on commit aaad5b7

Please sign in to comment.