Skip to content
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

[WIP] swift test in Linux #708

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
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
16 changes: 16 additions & 0 deletions SwiftyJSON.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
A8580F8B1BCF69A000DA927B /* DictionaryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8B66C8B19E51D6500540692 /* DictionaryTests.swift */; };
A8580F8C1BCF69A000DA927B /* ArrayTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8B66C8D19E52F4200540692 /* ArrayTests.swift */; };
A863BE2819EED46F0092A41F /* RawTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A863BE2719EED46F0092A41F /* RawTests.swift */; };
A869FA651DD02D2200DBCBEF /* XCTestCaseProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = A869FA641DD02D2200DBCBEF /* XCTestCaseProvider.swift */; };
A869FA661DD02D2200DBCBEF /* XCTestCaseProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = A869FA641DD02D2200DBCBEF /* XCTestCaseProvider.swift */; };
A869FA671DD02D2200DBCBEF /* XCTestCaseProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = A869FA641DD02D2200DBCBEF /* XCTestCaseProvider.swift */; };
A86BAA0E19EBC32B009EAAEB /* PerformanceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A86BAA0D19EBC32B009EAAEB /* PerformanceTests.swift */; };
A87080E419E3C2A600CDE086 /* SequenceTypeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A87080E319E3C2A600CDE086 /* SequenceTypeTests.swift */; };
A87080E619E3DF7800CDE086 /* ComparableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A87080E519E3DF7800CDE086 /* ComparableTests.swift */; };
Expand Down Expand Up @@ -110,6 +113,7 @@
A8580F741BCF5C5B00DA927B /* SwiftyJSON tvOS Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SwiftyJSON tvOS Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
A8580F781BCF5C5B00DA927B /* Info-tvOS.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Info-tvOS.plist"; sourceTree = "<group>"; };
A863BE2719EED46F0092A41F /* RawTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RawTests.swift; sourceTree = "<group>"; };
A869FA641DD02D2200DBCBEF /* XCTestCaseProvider.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = XCTestCaseProvider.swift; sourceTree = "<group>"; };
A86BAA0D19EBC32B009EAAEB /* PerformanceTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PerformanceTests.swift; sourceTree = "<group>"; };
A87080E319E3C2A600CDE086 /* SequenceTypeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SequenceTypeTests.swift; sourceTree = "<group>"; };
A87080E519E3DF7800CDE086 /* ComparableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ComparableTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -226,6 +230,7 @@
2E4FEFEA19575BE100351305 /* SwiftyJSONTests */ = {
isa = PBXGroup;
children = (
A869FA631DD02CFF00DBCBEF /* Helpers */,
A885D1DA19CFCFF0002FD4C3 /* Tests.json */,
A86BAA0D19EBC32B009EAAEB /* PerformanceTests.swift */,
A885D1D119CF1EE6002FD4C3 /* BaseTests.swift */,
Expand Down Expand Up @@ -257,6 +262,14 @@
name = "Supporting Files";
sourceTree = "<group>";
};
A869FA631DD02CFF00DBCBEF /* Helpers */ = {
isa = PBXGroup;
children = (
A869FA641DD02D2200DBCBEF /* XCTestCaseProvider.swift */,
);
name = Helpers;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXHeadersBuildPhase section */
Expand Down Expand Up @@ -551,6 +564,7 @@
buildActionMask = 2147483647;
files = (
A87080E819E439DA00CDE086 /* NumberTests.swift in Sources */,
A869FA651DD02D2200DBCBEF /* XCTestCaseProvider.swift in Sources */,
A87080E419E3C2A600CDE086 /* SequenceTypeTests.swift in Sources */,
5DD502911D9B21810004C112 /* NestedJSONTests.swift in Sources */,
A86BAA0E19EBC32B009EAAEB /* PerformanceTests.swift in Sources */,
Expand Down Expand Up @@ -588,6 +602,7 @@
buildActionMask = 2147483647;
files = (
9C459EFB1A9103C1008C9A41 /* SequenceTypeTests.swift in Sources */,
A869FA661DD02D2200DBCBEF /* XCTestCaseProvider.swift in Sources */,
9C459F001A9103C1008C9A41 /* ComparableTests.swift in Sources */,
5DD502921D9B21810004C112 /* NestedJSONTests.swift in Sources */,
9C459F021A9103C1008C9A41 /* NumberTests.swift in Sources */,
Expand All @@ -609,6 +624,7 @@
buildActionMask = 2147483647;
files = (
A8580F801BCF69A000DA927B /* PerformanceTests.swift in Sources */,
A869FA671DD02D2200DBCBEF /* XCTestCaseProvider.swift in Sources */,
A8580F811BCF69A000DA927B /* BaseTests.swift in Sources */,
5DD502931D9B21810004C112 /* NestedJSONTests.swift in Sources */,
A8580F821BCF69A000DA927B /* SequenceTypeTests.swift in Sources */,
Expand Down
21 changes: 21 additions & 0 deletions Tests/LinuxMain.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import XCTest
@testable import SwiftyJSONTests

// This is the entry point for SwiftyJSONTests on Linux

XCTMain([
testCase(PerformanceTests.allTests),
testCase(BaseTests.allTests),
testCase(NestedJSONTests.allTests),
testCase(SequenceTypeTests.allTests),
testCase(PrintableTests.allTests),
testCase(SubscriptTests.allTests),
testCase(LiteralConvertibleTests.allTests),
testCase(RawRepresentableTests.allTests),
testCase(ComparableTests.allTests),
testCase(StringTests.allTests),
testCase(NumberTests.allTests),
testCase(RawTests.allTests),
testCase(DictionaryTests.allTests),
testCase(ArrayTests.allTests)
])
11 changes: 9 additions & 2 deletions Tests/SwiftyJSONTests/ArrayTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,15 @@
import XCTest
import SwiftyJSON

class ArrayTests: XCTestCase {

final class ArrayTests: XCTestCase, XCTestCaseProvider {

static var allTests: [(String, (ArrayTests) -> () throws -> Void)] {
return [
("testSingleDimensionalArraysGetter", testSingleDimensionalArraysGetter),
("testSingleDimensionalArraysSetter", testSingleDimensionalArraysSetter)
]
}

func testSingleDimensionalArraysGetter() {
let array = ["1","2", "a", "B", "D"]
let json = JSON(array)
Expand Down
34 changes: 26 additions & 8 deletions Tests/SwiftyJSONTests/BaseTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,39 @@
import XCTest
@testable import SwiftyJSON

class BaseTests: XCTestCase {

final class BaseTests: XCTestCase, XCTestCaseProvider {

static var allTests: [(String, (BaseTests) -> () throws -> Void)] {
return [
("testInit", testInit),
("testCompare", testCompare),
("testJSONDoesProduceValidWithCorrectKeyPath", testJSONDoesProduceValidWithCorrectKeyPath),
("testJSONNumberCompare", testJSONNumberCompare),
("testNumberConvertToString", testNumberConvertToString),
("testNumberPrint", testNumberPrint),
("testNullJSON", testNullJSON),
("testExistance", testExistance),
("testErrorHandle", testErrorHandle),
("testReturnObject", testReturnObject),
("testNumberCompare", testNumberCompare)
]
}

var testData: Data!

override func setUp() {

super.setUp()

if let file = Bundle(for:BaseTests.self).path(forResource: "Tests", ofType: "json") {
self.testData = try? Data(contentsOf: URL(fileURLWithPath: file))
} else {
XCTFail("Can't find the test JSON file")
}
do {
self.testData = try Data(contentsOf: URL(fileURLWithPath: "Tests/SwiftyJSONTests/Tests.json"))
}
catch {
XCTFail("Failed to read in the test data")
exit(1)
}
}
override func tearDown() {
super.tearDown()
}
Expand Down
28 changes: 27 additions & 1 deletion Tests/SwiftyJSONTests/ComparableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,34 @@
import XCTest
import SwiftyJSON

class ComparableTests: XCTestCase {
final class ComparableTests: XCTestCase, XCTestCaseProvider {

static var allTests: [(String, (ComparableTests) -> () throws -> Void)] {
return [
("testNumberEqual", testNumberEqual),
("testNumberNotEqual", testNumberNotEqual),
("testNumberGreaterThanOrEqual", testNumberGreaterThanOrEqual),
("testNumberLessThanOrEqual", testNumberLessThanOrEqual),
("testNumberGreaterThan", testNumberGreaterThan),
("testNumberLessThan", testNumberLessThan),
("testBoolEqual", testBoolEqual),
("testBoolNotEqual", testBoolNotEqual),
("testBoolGreaterThanOrEqual", testBoolGreaterThanOrEqual),
("testBoolLessThanOrEqual", testBoolLessThanOrEqual),
("testBoolGreaterThan", testBoolGreaterThan),
("testBoolLessThan", testBoolLessThan),
("testStringEqual", testStringEqual),
("testStringNotEqual", testStringNotEqual),
("testStringGreaterThanOrEqual", testStringGreaterThanOrEqual),
("testStringLessThanOrEqual", testStringLessThanOrEqual),
("testStringGreaterThan", testStringGreaterThan),
("testStringLessThan", testStringLessThan),
("testNil", testNil),
("testArray", testArray),
("testDictionary", testDictionary)
]
}

func testNumberEqual() {
let jsonL1:JSON = 1234567890.876623
let jsonR1:JSON = JSON(1234567890.876623)
Expand Down
11 changes: 9 additions & 2 deletions Tests/SwiftyJSONTests/DictionaryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,15 @@
import XCTest
import SwiftyJSON

class DictionaryTests: XCTestCase {

final class DictionaryTests: XCTestCase, XCTestCaseProvider {

static var allTests: [(String, (DictionaryTests) -> () throws -> Void)] {
return [
("testGetter", testGetter),
("testSetter", testSetter)
]
}

func testGetter() {
let dictionary = ["number":9823.212, "name":"NAME", "list":[1234, 4.212], "object":["sub_number":877.2323, "sub_name":"sub_name"], "bool":true] as [String : Any]
let json = JSON(dictionary)
Expand Down
13 changes: 12 additions & 1 deletion Tests/SwiftyJSONTests/LiteralConvertibleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,19 @@
import XCTest
import SwiftyJSON

class LiteralConvertibleTests: XCTestCase {
final class LiteralConvertibleTests: XCTestCase, XCTestCaseProvider {

static var allTests: [(String, (LiteralConvertibleTests) -> () throws -> Void)] {
return [
("testNumber", testNumber),
("testBool", testBool),
("testString", testString),
("testNil", testNil),
("testArray", testArray),
("testDictionary", testDictionary)
]
}

func testNumber() {
var json:JSON = 1234567890.876623
XCTAssertEqual(json.int!, 1234567890)
Expand Down
10 changes: 9 additions & 1 deletion Tests/SwiftyJSONTests/NestedJSONTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@
import XCTest
import SwiftyJSON

class NestedJSONTests: XCTestCase {
final class NestedJSONTests: XCTestCase, XCTestCaseProvider {

static var allTests: [(String, (NestedJSONTests) -> () throws -> Void)] {
return [
("testTopLevelNestedJSON", testTopLevelNestedJSON),
("testDeeplyNestedJSON", testDeeplyNestedJSON)
]
}

let family: JSON = [
"names" : [
"Brooke Abigail Matos",
Expand Down
26 changes: 21 additions & 5 deletions Tests/SwiftyJSONTests/NumberTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,27 @@
import XCTest
import SwiftyJSON

class NumberTests: XCTestCase {

final class NumberTests: XCTestCase, XCTestCaseProvider {

static var allTests: [(String, (NumberTests) -> () throws -> Void)] {
return [
("testNumber", testNumber),
("testBool", testBool),
("testDouble", testDouble),
("testFloat", testFloat),
("testInt", testInt),
("testUInt", testUInt),
("testInt8", testInt8),
("testUInt8", testUInt8),
("testInt16", testInt16),
("testUInt16", testUInt16),
("testInt32", testInt32),
("testUInt32", testUInt32),
("testInt64", testInt64),
("testUInt64", testUInt64)
]
}

func testNumber() {
//getter
var json = JSON(NSNumber(value: 9876543210.123456789))
Expand Down Expand Up @@ -103,7 +122,6 @@ class NumberTests: XCTestCase {
var json = JSON(54321.12345)
XCTAssertTrue(json.float! == 54321.12345)
XCTAssertTrue(json.floatValue == 54321.12345)
print(json.numberValue.doubleValue)
XCTAssertEqual(json.numberValue, 54321.12345)
XCTAssertEqual(json.stringValue, "54321.12345")

Expand Down Expand Up @@ -189,7 +207,6 @@ class NumberTests: XCTestCase {
json.int8Value = n0.int8Value
XCTAssertTrue(json.int8! == n0.int8Value)
XCTAssertTrue(json.int8Value == n0.int8Value)
print(json.number)
XCTAssertTrue(json.number! == n0)
XCTAssertEqual(json.numberValue, n0)
XCTAssertEqual(json.stringValue, "0")
Expand Down Expand Up @@ -260,7 +277,6 @@ class NumberTests: XCTestCase {
json.int16Value = n0.int16Value
XCTAssertTrue(json.int16! == n0.int16Value)
XCTAssertTrue(json.int16Value == n0.int16Value)
print(json.number)
XCTAssertTrue(json.number! == n0)
XCTAssertEqual(json.numberValue, n0)
XCTAssertEqual(json.stringValue, "0")
Expand Down
31 changes: 22 additions & 9 deletions Tests/SwiftyJSONTests/PerformanceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,33 @@
import XCTest
import SwiftyJSON

class PerformanceTests: XCTestCase {

final class PerformanceTests: XCTestCase, XCTestCaseProvider {

static var allTests: [(String, (PerformanceTests) -> () throws -> Void)] {
return [
("testInitPerformance", testInitPerformance),
("testObjectMethodPerformance", testObjectMethodPerformance),
("testArrayMethodPerformance", testArrayMethodPerformance),
("testDictionaryMethodPerformance", testDictionaryMethodPerformance),
("testRawStringMethodPerformance", testRawStringMethodPerformance),
("testLargeDictionaryMethodPerformance", testLargeDictionaryMethodPerformance)
]
}

var testData: Data!

override func setUp() {
super.setUp()

if let file = Bundle(for:PerformanceTests.self).path(forResource: "Tests", ofType: "json") {
self.testData = try? Data(contentsOf: URL(fileURLWithPath: file))
} else {
XCTFail("Can't find the test JSON file")
}
}

do {
self.testData = try Data(contentsOf: URL(fileURLWithPath: "Tests/SwiftyJSONTests/Tests.json"))
}
catch {
XCTFail("Failed to read in the test data")
exit(1)
}
}

override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
super.tearDown()
Expand Down
14 changes: 13 additions & 1 deletion Tests/SwiftyJSONTests/PrintableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,19 @@
import XCTest
import SwiftyJSON

class PrintableTests: XCTestCase {
final class PrintableTests: XCTestCase, XCTestCaseProvider {

static var allTests: [(String, (PrintableTests) -> () throws -> Void)] {
return [
("testNumber", testNumber),
("testBool", testBool),
("testString", testString),
("testNil", testNil),
("testArray", testArray),
("testDictionary", testDictionary)
]
}

func testNumber() {
let json:JSON = 1234567890.876623
XCTAssertEqual(json.description, "1234567890.876623")
Expand Down
13 changes: 12 additions & 1 deletion Tests/SwiftyJSONTests/RawRepresentableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,19 @@
import XCTest
import SwiftyJSON

class RawRepresentableTests: XCTestCase {
final class RawRepresentableTests: XCTestCase, XCTestCaseProvider {

static var allTests: [(String, (RawRepresentableTests) -> () throws -> Void)] {
return [
("testNumber", testNumber),
("testBool", testBool),
("testString", testString),
("testNil", testNil),
("testArray", testArray),
("testDictionary", testDictionary)
]
}

func testNumber() {
var json:JSON = JSON(rawValue: 948394394.347384 as NSNumber)!
XCTAssertEqual(json.int!, 948394394)
Expand Down
Loading