Skip to content

Commit 9f605ee

Browse files
authored
Make necessary changes to build and test the library on iOS (#78)
1 parent aa25d27 commit 9f605ee

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

Package.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import PackageDescription
44
let package = Package(
55
name: "swift-bson",
66
platforms: [
7-
.macOS(.v10_14)
7+
.macOS(.v10_14),
8+
.iOS(.v11)
89
],
910
products: [
1011
.library(name: "SwiftBSON", targets: ["SwiftBSON"])

Tests/SwiftBSONTests/BSONTests.swift

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,15 @@ import SwiftBSON
66
import XCTest
77

88
open class BSONTestCase: XCTestCase {
9-
/// Gets the path of the directory containing spec files, depending on whether
10-
/// we're running from XCode or the command line
9+
/// Gets the path of the directory containing spec files.
1110
static var specsPath: String {
12-
// if we can access the "/Tests" directory, assume we're running from command line
13-
if FileManager.default.fileExists(atPath: "./Tests") {
14-
return "./Tests/Specs"
15-
}
16-
// otherwise we're in Xcode, get the bundle's resource path
17-
guard let path = Bundle(for: self).resourcePath else {
18-
XCTFail("Missing resource path")
19-
return ""
20-
}
21-
return path
11+
// Approach taken from https://stackoverflow.com/a/58034307
12+
// TODO: SWIFT-1442 Once we drop Swift < 5.3 we can switch to including the JSON files as Resources via our
13+
// package manifest instead.
14+
let thisFile = URL(fileURLWithPath: #file)
15+
// We are in Tests/SwiftBSONTests/BSONTests.swift; drop 2 components to get up to the Tests directory.
16+
let baseDirectory = thisFile.deletingLastPathComponent().deletingLastPathComponent()
17+
return baseDirectory.appendingPathComponent("Specs").path
2218
}
2319

2420
// indicates whether we are running on a 32-bit platform

Tests/SwiftBSONTests/LeakCheckTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#if os(macOS) // the Process APIs used do not exist on iOS, and `leaks` does not exist on Linux.
12
import Foundation
23

34
final class LeakCheckTests: BSONTestCase {
@@ -32,3 +33,4 @@ final class LeakCheckTests: BSONTestCase {
3233
}
3334
}
3435
}
36+
#endif

0 commit comments

Comments
 (0)