Until CLIon supports newer Swift, and Swift Package Manager versions, and SPM fixes https://bugs.swift.org/browse/SR-12912 I opt in to doing this hackery for test resources.

Signed-off-by: Adam Rocska <adam.rocska@adams.solutions>
This commit is contained in:
Adam Rocska 2020-06-05 13:45:28 +02:00
parent 2cd55ef5ab
commit d662ad3d22
65 changed files with 87 additions and 110 deletions

View File

@ -6,17 +6,11 @@ import PackageDescription
let package = Package(
name: "GeoIP2",
products: [
.library(
name: "GeoIP2",
targets: ["Api"]
),
.library(
name: "DBReader",
targets: ["DBReader"]
),
.library(name: "GeoIP2", targets: ["Api"])
],
dependencies: [],
targets: [
// MARK : Sources
.target(name: "IndexReader", dependencies: ["Decoder", "MetadataReader"]),
.target(name: "DataSection", dependencies: ["Decoder", "MetadataReader"]),
.target(name: "MetadataReader", dependencies: ["Decoder"]),
@ -24,35 +18,45 @@ let package = Package(
.target(name: "DBReader", dependencies: ["IndexReader", "DataSection", "MetadataReader", "Decoder"]),
.target(name: "Api", dependencies: ["DBReader", "Decoder", "MetadataReader", "IndexReader"]),
// MARK : Temporary hackery until CLion supports new Swift Package Manager with its Resources handling.
.target(name: "TestResources", dependencies: [], path: "Tests/TestResources"),
// MARK : "unit" tests. They will be actual unit tests one day.
.testTarget(
name: "IndexReaderTests",
dependencies: ["IndexReader", "MetadataReader"],
name: "IndexReaderTests",
dependencies: ["TestResources", "IndexReader", "MetadataReader"],
path: "Tests/Unit/IndexReaderTests"
),
.testTarget(
name: "DataSectionTests",
dependencies: ["DataSection", "MetadataReader"],
name: "DataSectionTests",
dependencies: ["TestResources", "DataSection", "MetadataReader"],
path: "Tests/Unit/DataSectionTests"
),
.testTarget(
name: "MetadataReaderTests",
dependencies: ["MetadataReader", "Decoder"],
name: "MetadataReaderTests",
dependencies: ["TestResources", "MetadataReader", "Decoder"],
path: "Tests/Unit/MetadataReaderTests"
),
.testTarget(
name: "DecoderTests",
dependencies: ["Decoder"],
name: "DecoderTests",
dependencies: ["TestResources", "Decoder"],
path: "Tests/Unit/DecoderTests"
),
.testTarget(
name: "DBReaderTests",
dependencies: ["DBReader"],
name: "DBReaderTests",
dependencies: ["TestResources", "DBReader"],
path: "Tests/Unit/DBReaderTests"
),
.testTarget(
name: "ApiTests",
dependencies: ["Api", "Decoder", "IndexReader","DBReader", "MetadataReader"],
name: "ApiTests",
dependencies: ["TestResources", "Api", "Decoder", "IndexReader", "DBReader", "MetadataReader"],
path: "Tests/Unit/ApiTests"
),
// MARK : System tests
.testTarget(
name: "GeoIP2_FileBased",
dependencies: ["TestResources", "Api"],
path: "Tests/System/FileBased"
)
]
)

View File

@ -0,0 +1,25 @@
import Foundation
import XCTest
import TestResources
class Wut: XCTestCase {
func testWut() {
print(bundle.path(
forResource: "GeoLite2-ASN_20200526/GeoLite2-ASN",
ofType: "mmdb"
))
// print(Bundle.main.bundlePath)
// print(Bundle.main.resourcePath)
// print(Bundle.main.privateFrameworksPath)
// print(Bundle.main.builtInPlugInsPath)
// print(Bundle.main.executablePath)
// print(Bundle.main.sharedFrameworksPath)
// print(Bundle.main.sharedSupportPath)
// XCTAssertTrue(false)
// let bundle = Bundle(for: Wut.self)
// bundle.path(forResource: <#T##String?##Swift.String?#>, ofType: <#T##String?##Swift.String?#>)
// print(bundle)
}
}

View File

@ -1,8 +1,7 @@
import Foundation
import XCTest
extension XCTestCase {
public extension XCTestCase {
static var bundle: Bundle {
get {
guard let currentFileUrl = URL(string: #file) else { return Bundle.main }
@ -14,5 +13,4 @@ extension XCTestCase {
}
var bundle: Bundle { get { return XCTestCase.bundle } }
}

View File

@ -1,5 +1,6 @@
import Foundation
import XCTest
import TestResources
@testable import class Api.ReaderFactory
@testable import struct MetadataReader.Metadata
import enum Api.DatabaseType

View File

@ -1,5 +1,6 @@
import Foundation
import XCTest
import TestResources
@testable import struct MetadataReader.Metadata
@testable import class Api.Reader
import enum Decoder.Payload

View File

@ -1,20 +1,8 @@
import Foundation
import XCTest
import TestResources
extension XCTestCase {
static var bundle: Bundle {
get {
guard let currentFileUrl = URL(string: #file) else { return Bundle.main }
guard let testBundle = Bundle(path: currentFileUrl.deletingLastPathComponent().path) else {
return Bundle.main
}
return testBundle
}
}
var bundle: Bundle { get { return XCTestCase.bundle } }
private static var countryFilePath: String {
get {
guard let countryFilePath = bundle.path(

View File

@ -1,5 +1,5 @@
import XCTest
import TestResources
#if !canImport(ObjectiveC)
public func allTests() -> [XCTestCaseEntry] {
return [

View File

@ -1,5 +1,6 @@
import Foundation
import XCTest
import TestResources
@testable import DBReader
import enum Decoder.Payload
import enum IndexReader.IpAddress

View File

@ -1 +0,0 @@
Database and Contents Copyright (c) 2020 MaxMind, Inc.

View File

@ -1,3 +0,0 @@
Use of this MaxMind product is governed by MaxMind's GeoLite2 End User License Agreement, which can be viewed at https://www.maxmind.com/en/geolite2/eula.
This database incorporates GeoNames [https://www.geonames.org] geographical data, which is made available under the Creative Commons Attribution 4.0 License. To view a copy of this license, visit https://creativecommons.org/licenses/by/4.0/.

View File

@ -1,20 +0,0 @@
import Foundation
import XCTest
extension XCTestCase {
var bundle: Bundle {
get {
guard let currentFileUrl = URL(string: #file) else {
return Bundle.main
}
guard let testBundle = Bundle(path: currentFileUrl.deletingLastPathComponent().path) else {
return Bundle.main
}
return testBundle
}
}
}

View File

@ -1,5 +1,5 @@
import XCTest
import TestResources
#if !canImport(ObjectiveC)
public func allTests() -> [XCTestCaseEntry] {
return [

View File

@ -1,5 +1,6 @@
import Foundation
import XCTest
import TestResources
import class MetadataReader.Reader
import Decoder
@testable import DataSection

View File

@ -1 +0,0 @@
Database and Contents Copyright (c) 2020 MaxMind, Inc.

View File

@ -1,3 +0,0 @@
Use of this MaxMind product is governed by MaxMind's GeoLite2 End User License Agreement, which can be viewed at https://www.maxmind.com/en/geolite2/eula.
This database incorporates GeoNames [https://www.geonames.org] geographical data, which is made available under the Creative Commons Attribution 4.0 License. To view a copy of this license, visit https://creativecommons.org/licenses/by/4.0/.

View File

@ -1,18 +0,0 @@
import Foundation
import XCTest
extension XCTestCase {
static var bundle: Bundle {
get {
guard let currentFileUrl = URL(string: #file) else { return Bundle.main }
guard let testBundle = Bundle(path: currentFileUrl.deletingLastPathComponent().path) else {
return Bundle.main
}
return testBundle
}
}
var bundle: Bundle { get { return XCTestCase.bundle } }
}

View File

@ -1,5 +1,6 @@
import Foundation
import XCTest
import TestResources
@testable import Decoder
class ControlByteInterpreterTest: XCTestCase {

View File

@ -1,5 +1,6 @@
import Foundation
import XCTest
import TestResources
@testable import Decoder
class DataTypeTest: XCTestCase {

View File

@ -1,5 +1,6 @@
import Foundation
import XCTest
import TestResources
@testable import Decoder
class FunctionResolveDefinitionSizeTest: XCTestCase {

View File

@ -1,5 +1,6 @@
import Foundation
import XCTest
import TestResources
@testable import Decoder
class FunctionResolvePayloadSizeTest: XCTestCase {

View File

@ -1,5 +1,6 @@
import Foundation
import XCTest
import TestResources
@testable import Decoder
class FunctionResolveTypeTest: XCTestCase {

View File

@ -1,5 +1,6 @@
import Foundation
import XCTest
import TestResources
@testable import Decoder
class ControlByteTest: XCTestCase {

View File

@ -1,5 +1,6 @@
import Foundation
import XCTest
import TestResources
@testable import Decoder
class DataTest: XCTestCase {

View File

@ -1,5 +1,6 @@
import Foundation
import XCTest
import TestResources
@testable import Decoder
class DecoderTest: XCTestCase {

View File

@ -1,5 +1,6 @@
import Foundation
import XCTest
import TestResources
@testable import Decoder
class NumericTest: XCTestCase {

View File

@ -1,5 +1,6 @@
import Foundation
import XCTest
import TestResources
@testable import Decoder
class FunctionInterpretArrayTest: XCTestCase {

View File

@ -1,5 +1,6 @@
import Foundation
import XCTest
import TestResources
@testable import Decoder
class FunctionInterpretDataCacheContainerTest: XCTestCase {

View File

@ -1,5 +1,6 @@
import Foundation
import XCTest
import TestResources
@testable import Decoder
class FunctionInterpretDoubleTest: XCTestCase {

View File

@ -1,5 +1,6 @@
import Foundation
import XCTest
import TestResources
@testable import Decoder
class FunctionInterpretFloatTest: XCTestCase {

View File

@ -1,5 +1,6 @@
import Foundation
import XCTest
import TestResources
@testable import Decoder
class FunctionInterpretInt32Test: XCTestCase {

View File

@ -1,5 +1,6 @@
import Foundation
import XCTest
import TestResources
@testable import Decoder
class FunctionInterpretMapTest: XCTestCase {

View File

@ -1,5 +1,6 @@
import Foundation
import XCTest
import TestResources
@testable import Decoder
class FunctionInterpretPointerTest: XCTestCase {

View File

@ -1,5 +1,6 @@
import Foundation
import XCTest
import TestResources
@testable import Decoder
class FunctionInterpretUInt16Test: XCTestCase {

View File

@ -1,5 +1,6 @@
import Foundation
import XCTest
import TestResources
@testable import Decoder
class FunctionInterpretUInt32Test: XCTestCase {

View File

@ -1,5 +1,6 @@
import Foundation
import XCTest
import TestResources
@testable import Decoder
class FunctionInterpretUInt64Test: XCTestCase {

View File

@ -1,5 +1,6 @@
import Foundation
import XCTest
import TestResources
@testable import Decoder
class FunctionInterpretUtf8StringTest: XCTestCase {

View File

@ -1,5 +1,6 @@
import Foundation
import XCTest
import TestResources
@testable import Decoder
class PayloadInterpreterTest: XCTestCase {

View File

@ -1,5 +1,6 @@
import Foundation
import XCTest
import TestResources
@testable import Decoder
class PayloadTest: XCTestCase {

View File

@ -1,5 +1,6 @@
import Foundation
import XCTest
import TestResources
@testable import Decoder
class StringTest: XCTestCase {

View File

@ -1,5 +1,6 @@
import Foundation
import XCTest
import TestResources
import class MetadataReader.Reader
@testable import IndexReader

View File

@ -1,5 +1,6 @@
import Foundation
import XCTest
import TestResources
@testable import IndexReader
class IpAddressTest: XCTestCase {

View File

@ -1,5 +1,6 @@
import Foundation
import XCTest
import TestResources
@testable import IndexReader
class LookupDirectionTest: XCTestCase {

View File

@ -1,5 +1,6 @@
import Foundation
import XCTest
import TestResources
@testable import IndexReader
class NodeTest: XCTestCase {

View File

@ -1 +0,0 @@
Database and Contents Copyright (c) 2020 MaxMind, Inc.

View File

@ -1,3 +0,0 @@
Use of this MaxMind product is governed by MaxMind's GeoLite2 End User License Agreement, which can be viewed at https://www.maxmind.com/en/geolite2/eula.
This database incorporates GeoNames [https://www.geonames.org] geographical data, which is made available under the Creative Commons Attribution 4.0 License. To view a copy of this license, visit https://creativecommons.org/licenses/by/4.0/.

View File

@ -1,5 +1,6 @@
import Foundation
import XCTest
import TestResources
@testable import MetadataReader
class FunctionDecodeTest: XCTestCase {

View File

@ -1,5 +1,6 @@
import Foundation
import XCTest
import TestResources
@testable import MetadataReader
class MarkerLookupTest: XCTestCase {

View File

@ -1,5 +1,6 @@
import Foundation
import XCTest
import TestResources
@testable import class MetadataReader.Reader
@testable import struct MetadataReader.Metadata

View File

@ -1 +0,0 @@
Database and Contents Copyright (c) 2020 MaxMind, Inc.

View File

@ -1,3 +0,0 @@
Use of this MaxMind product is governed by MaxMind's GeoLite2 End User License Agreement, which can be viewed at https://www.maxmind.com/en/geolite2/eula.
This database incorporates GeoNames [https://www.geonames.org] geographical data, which is made available under the Creative Commons Attribution 4.0 License. To view a copy of this license, visit https://creativecommons.org/licenses/by/4.0/.

View File

@ -1,18 +0,0 @@
import Foundation
import XCTest
extension XCTestCase {
static var bundle: Bundle {
get {
guard let currentFileUrl = URL(string: #file) else { return Bundle.main }
guard let testBundle = Bundle(path: currentFileUrl.deletingLastPathComponent().path) else {
return Bundle.main
}
return testBundle
}
}
var bundle: Bundle { get { return XCTestCase.bundle } }
}