Skip to content

Commit

Permalink
Support Swift Package Manager. (#77)
Browse files Browse the repository at this point in the history
* add SwiftPackageManager support.
* add resourcehelper's file reference to fix test error in SwiftPM
  • Loading branch information
orangeince authored and DivineDominion committed Jun 14, 2019
1 parent 0a5ac63 commit f918bde
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ DerivedData
*.hmap
*.ipa
*.xcuserstate
.build/

# CocoaPods
#
Expand Down
29 changes: 29 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// swift-tools-version:5.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "SwiftCSV",
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.library(
name: "SwiftCSV",
targets: ["SwiftCSV"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
.target(
name: "SwiftCSV",
path: "SwiftCSV"),
.testTarget(
name: "SwiftCSVTests",
dependencies: ["SwiftCSV"],
path: "SwiftCSVTests"),
]
)
8 changes: 8 additions & 0 deletions SwiftCSV.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@
BEE5461E1CBBB15900C0666F /* Description.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEE5461D1CBBB15900C0666F /* Description.swift */; };
E46085921CCB1E8F00385286 /* large.csv in Resources */ = {isa = PBXBuildFile; fileRef = E46085911CCB1E8F00385286 /* large.csv */; };
E46085941CCB1F5C00385286 /* PerformanceTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E46085931CCB1F5C00385286 /* PerformanceTest.swift */; };
F5C19F502283243C00920B06 /* ResourceHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = F5C19F4F2283243C00920B06 /* ResourceHelper.swift */; };
F5C19F512283C0C100920B06 /* ResourceHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = F5C19F4F2283243C00920B06 /* ResourceHelper.swift */; };
F5C19F522283C0C300920B06 /* ResourceHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = F5C19F4F2283243C00920B06 /* ResourceHelper.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -124,6 +127,7 @@
BEE5461D1CBBB15900C0666F /* Description.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Description.swift; sourceTree = "<group>"; };
E46085911CCB1E8F00385286 /* large.csv */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = large.csv; sourceTree = "<group>"; };
E46085931CCB1F5C00385286 /* PerformanceTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PerformanceTest.swift; sourceTree = "<group>"; };
F5C19F4F2283243C00920B06 /* ResourceHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ResourceHelper.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -243,6 +247,7 @@
BE06B67C1CB7267B009578CC /* empty_fields.csv */,
BE06B6811CB7287F009578CC /* quotes.csv */,
E46085911CCB1E8F00385286 /* large.csv */,
F5C19F4F2283243C00920B06 /* ResourceHelper.swift */,
);
name = Res;
sourceTree = "<group>";
Expand Down Expand Up @@ -558,6 +563,7 @@
files = (
E46085941CCB1F5C00385286 /* PerformanceTest.swift in Sources */,
3D1E59C71945FFAD001CF760 /* CSVTests.swift in Sources */,
F5C19F502283243C00920B06 /* ResourceHelper.swift in Sources */,
508975E11DBF3E51006F3DBE /* EnumeratedViewTests.swift in Sources */,
3D3749E3194D6DF7008F262A /* TSVTests.swift in Sources */,
BE06B6801CB726B5009578CC /* URLTests.swift in Sources */,
Expand Down Expand Up @@ -585,6 +591,7 @@
files = (
5FB74BE01CCB9312009DDBF1 /* CSVTests.swift in Sources */,
5FB74BE11CCB9312009DDBF1 /* QuotedTests.swift in Sources */,
F5C19F512283C0C100920B06 /* ResourceHelper.swift in Sources */,
508975E21DBF3E51006F3DBE /* EnumeratedViewTests.swift in Sources */,
5FB74BE21CCB9312009DDBF1 /* TSVTests.swift in Sources */,
5FB74BE31CCB9312009DDBF1 /* URLTests.swift in Sources */,
Expand Down Expand Up @@ -612,6 +619,7 @@
files = (
5FB74BE51CCB931F009DDBF1 /* CSVTests.swift in Sources */,
5FB74BE61CCB931F009DDBF1 /* QuotedTests.swift in Sources */,
F5C19F522283C0C300920B06 /* ResourceHelper.swift in Sources */,
508975E31DBF3E51006F3DBE /* EnumeratedViewTests.swift in Sources */,
5FB74BE71CCB931F009DDBF1 /* TSVTests.swift in Sources */,
5FB74BE81CCB931F009DDBF1 /* URLTests.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion SwiftCSVTests/PerformanceTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class PerformanceTest: XCTestCase {
var csv: CSV!

override func setUp() {
let csvURL = Bundle(for: CSVTests.self).url(forResource: "large", withExtension: "csv")!
let csvURL = ResourceHelper.url(forResource: "large", withExtension: "csv")!
csv = try! CSV(url: csvURL)
}

Expand Down
16 changes: 16 additions & 0 deletions SwiftCSVTests/ResourceHelper.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import Foundation

// Find url of resource.
// This is a workaround for SwiftPM, becasue SwiftPM is not yet support for include resources with targets.(https://bugs.swift.org/browse/SR-2866)
struct ResourceHelper {
static func url(forResource name: String, withExtension type: String) -> URL? {
let bundle = Bundle(for: CSVTests.self)
if let url = bundle.url(forResource: name, withExtension: type) {
return url
} else if let realBundle = Bundle(path: "\(bundle.bundlePath)/../../../../SwiftCSVTests") {
return realBundle.url(forResource: name, withExtension: type)
} else {
return nil
}
}
}
4 changes: 2 additions & 2 deletions SwiftCSVTests/URLTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class URLTests: XCTestCase {
var csv: CSV!

func testEmptyFields() {
let csvURL = Bundle(for: CSVTests.self).url(forResource: "empty_fields", withExtension: "csv")!
let csvURL = ResourceHelper.url(forResource: "empty_fields", withExtension: "csv")!
csv = try! CSV(url: csvURL)
let expected = [
["id": "1", "name": "John", "age": "23"],
Expand All @@ -29,7 +29,7 @@ class URLTests: XCTestCase {
}

func testQuotes() {
let csvURL = Bundle(for: CSVTests.self).url(forResource: "quotes", withExtension: "csv")!
let csvURL = ResourceHelper.url(forResource: "quotes", withExtension: "csv")!
csv = try! CSV(url: csvURL)
let expected = [
["id": "4", "name, first": "Alex", "name, last": "Smith"],
Expand Down

0 comments on commit f918bde

Please sign in to comment.