From fe1be622bbb887c7579dbb8c7ce851157881375e Mon Sep 17 00:00:00 2001 From: Mike Pollard Date: Wed, 19 Dec 2018 12:13:03 +0000 Subject: [PATCH 1/4] Use same test as OSX, as issue https://github.com/IBM-Swift/SwiftRuntime/issues/183 appears fixed in swift 4.2 on linux --- Tests/SwiftyJSONTests/NumberTests.swift | 4 ++-- Tests/SwiftyJSONTests/PrintableTests.swift | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Tests/SwiftyJSONTests/NumberTests.swift b/Tests/SwiftyJSONTests/NumberTests.swift index 55c88548..ab35a441 100644 --- a/Tests/SwiftyJSONTests/NumberTests.swift +++ b/Tests/SwiftyJSONTests/NumberTests.swift @@ -55,7 +55,7 @@ class NumberTests: XCTestCase { XCTAssertEqual(json.numberValue, 9876543210.123456789) // Number of fraction digits differs on OSX and Linux, // issue https://github.com/IBM-Swift/SwiftRuntime/issues/183 - #if os(Linux) + #if (os(Linux) && !swift(>=4.2)) XCTAssertEqual(json.stringValue, "9876543210.12346") #else XCTAssertEqual(json.stringValue, "9876543210.123457") @@ -128,7 +128,7 @@ class NumberTests: XCTestCase { XCTAssertEqual(json.numberValue, 9876543210.123456789) // Number of fraction digits differs on OSX and Linux, // issue https://github.com/IBM-Swift/SwiftRuntime/issues/183 - #if os(Linux) + #if (os(Linux) && !swift(>=4.2)) XCTAssertEqual(json.stringValue, "9876543210.12346") #else XCTAssertEqual(json.stringValue, "9876543210.123457") diff --git a/Tests/SwiftyJSONTests/PrintableTests.swift b/Tests/SwiftyJSONTests/PrintableTests.swift index 593015f5..f76135f9 100644 --- a/Tests/SwiftyJSONTests/PrintableTests.swift +++ b/Tests/SwiftyJSONTests/PrintableTests.swift @@ -43,7 +43,7 @@ class PrintableTests: XCTestCase { let json:JSON = 1234567890.876623 // Number of fraction digits differs on OSX and Linux, // issue https://github.com/IBM-Swift/SwiftRuntime/issues/183 - #if os(Linux) + #if (os(Linux) && !swift(>=4.2)) XCTAssertEqual(json.description, "1234567890.87662") XCTAssertEqual(json.debugDescription, "1234567890.87662") #else From 090d4f95bd5beca3664a03c9b817b5f2a05a925b Mon Sep 17 00:00:00 2001 From: Mike Pollard Date: Wed, 19 Dec 2018 12:15:58 +0000 Subject: [PATCH 2/4] Use a String for the key in the json rather than an Int. Using an Int causes failure in Linux with swift 4.2. Surely all json keys are Strings anyway? --- Tests/SwiftyJSONTests/LiteralConvertibleTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/SwiftyJSONTests/LiteralConvertibleTests.swift b/Tests/SwiftyJSONTests/LiteralConvertibleTests.swift index d2dba525..fef0134d 100644 --- a/Tests/SwiftyJSONTests/LiteralConvertibleTests.swift +++ b/Tests/SwiftyJSONTests/LiteralConvertibleTests.swift @@ -70,7 +70,7 @@ class LiteralConvertibleTests: XCTestCase { XCTAssert(jsonNil_1 == nil) let jsonNil_2:JSON = JSON(NSNull.self) XCTAssert(jsonNil_2 != nil) - let jsonNil_3:JSON = JSON([1:2]) + let jsonNil_3:JSON = JSON(["1":2]) XCTAssert(jsonNil_3 != nil) } From 6244da99fe9e948ed124185f7fdc4373a5837da3 Mon Sep 17 00:00:00 2001 From: Mike Pollard Date: Wed, 19 Dec 2018 12:17:26 +0000 Subject: [PATCH 3/4] Trap Int before Doubles before Bools in setPObjectHelper otherwise swift4.2 on linux can interpret Ints as Doubles and Bools as Ints --- Sources/SwiftyJSON/SwiftyJSON.swift | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Sources/SwiftyJSON/SwiftyJSON.swift b/Sources/SwiftyJSON/SwiftyJSON.swift index 9362bc84..c7bd7e66 100755 --- a/Sources/SwiftyJSON/SwiftyJSON.swift +++ b/Sources/SwiftyJSON/SwiftyJSON.swift @@ -237,7 +237,13 @@ public struct JSON { var type: Type var value: Any - if let bool = newValue as? Bool { + if let number = newValue as? Int { + type = .number + value = NSNumber(value: number) + } else if let number = newValue as? Double { + type = .number + value = NSNumber(value: number) + } else if let bool = newValue as? Bool { type = .bool value = bool } else if let number = newValue as? NSNumber { @@ -248,13 +254,7 @@ public struct JSON { type = .number value = number } - } else if let number = newValue as? Double { - type = .number - value = NSNumber(value: number) - } else if let number = newValue as? Int { - type = .number - value = NSNumber(value: number) - } else if let string = newValue as? String { + } else if let string = newValue as? String { type = .string value = string } else if let string = newValue as? NSString { From f0f15b09c42300ba602474a14a4e59d9a8774dae Mon Sep 17 00:00:00 2001 From: Mike Pollard Date: Wed, 19 Dec 2018 12:17:58 +0000 Subject: [PATCH 4/4] Reinstate linux swift 4.2 build on travis --- .travis.yml | 9 ++++----- Package@swift-4.2.swift | 43 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 5 deletions(-) create mode 100644 Package@swift-4.2.swift diff --git a/.travis.yml b/.travis.yml index 69afcfba..1f9d626c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,11 +12,10 @@ matrix: dist: trusty sudo: required env: SWIFT_SNAPSHOT=4.0.3 -# Tests fail on Swift 4.2 on Linux. -# - os: linux -# dist: trusty -# sudo: required -# env: DOCKER_IMAGE=ubuntu:16.04 SWIFT_SNAPSHOT=4.2.1 + - os: linux + dist: trusty + sudo: required + env: DOCKER_IMAGE=ubuntu:16.04 SWIFT_SNAPSHOT=4.2.1 # - os: linux # dist: trusty # sudo: required diff --git a/Package@swift-4.2.swift b/Package@swift-4.2.swift new file mode 100644 index 00000000..7bd26320 --- /dev/null +++ b/Package@swift-4.2.swift @@ -0,0 +1,43 @@ +// swift-tools-version:4.2 +// The swift-tools-version declares the minimum version of Swift required to build this package. +/** + * Copyright IBM Corporation 2016, 2017 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ + +import PackageDescription + +let package = Package( + name: "SwiftyJSON", + products: [ + // Products define the executables and libraries produced by a package, and make them visible to other packages. + .library( + name: "SwiftyJSON", + targets: ["SwiftyJSON"] + ) + ], + dependencies: [], + 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: "SwiftyJSON", + dependencies: [] + ), + .testTarget( + name: "SwiftyJSONTests", + dependencies: ["SwiftyJSON"] + ) + ] +)