Skip to content

Commit f2612ea

Browse files
sportlabsMikedjones6
authored andcommitted
Fixes for Swift 4.2 on Linux (#43)
* Use same test as OSX, as issue IBM-Swift/SwiftRuntime#183 appears fixed in swift 4.2 on linux * 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? * Trap Int before Doubles before Bools in setPObjectHelper otherwise swift4.2 on linux can interpret Ints as Doubles and Bools as Ints * Reinstate linux swift 4.2 build on travis
1 parent c687182 commit f2612ea

File tree

6 files changed

+59
-17
lines changed

6 files changed

+59
-17
lines changed

.travis.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ matrix:
1212
dist: trusty
1313
sudo: required
1414
env: SWIFT_SNAPSHOT=4.0.3
15-
# Tests fail on Swift 4.2 on Linux.
16-
# - os: linux
17-
# dist: trusty
18-
# sudo: required
19-
# env: DOCKER_IMAGE=ubuntu:16.04 SWIFT_SNAPSHOT=4.2.1
15+
- os: linux
16+
dist: trusty
17+
sudo: required
18+
env: DOCKER_IMAGE=ubuntu:16.04 SWIFT_SNAPSHOT=4.2.1
2019
# - os: linux
2120
# dist: trusty
2221
# sudo: required

Package@swift-4.2.swift

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// swift-tools-version:4.2
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
/**
4+
* Copyright IBM Corporation 2016, 2017
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
**/
18+
19+
import PackageDescription
20+
21+
let package = Package(
22+
name: "SwiftyJSON",
23+
products: [
24+
// Products define the executables and libraries produced by a package, and make them visible to other packages.
25+
.library(
26+
name: "SwiftyJSON",
27+
targets: ["SwiftyJSON"]
28+
)
29+
],
30+
dependencies: [],
31+
targets: [
32+
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
33+
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
34+
.target(
35+
name: "SwiftyJSON",
36+
dependencies: []
37+
),
38+
.testTarget(
39+
name: "SwiftyJSONTests",
40+
dependencies: ["SwiftyJSON"]
41+
)
42+
]
43+
)

Sources/SwiftyJSON/SwiftyJSON.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,13 @@ public struct JSON {
237237
var type: Type
238238
var value: Any
239239

240-
if let bool = newValue as? Bool {
240+
if let number = newValue as? Int {
241+
type = .number
242+
value = NSNumber(value: number)
243+
} else if let number = newValue as? Double {
244+
type = .number
245+
value = NSNumber(value: number)
246+
} else if let bool = newValue as? Bool {
241247
type = .bool
242248
value = bool
243249
} else if let number = newValue as? NSNumber {
@@ -248,13 +254,7 @@ public struct JSON {
248254
type = .number
249255
value = number
250256
}
251-
} else if let number = newValue as? Double {
252-
type = .number
253-
value = NSNumber(value: number)
254-
} else if let number = newValue as? Int {
255-
type = .number
256-
value = NSNumber(value: number)
257-
} else if let string = newValue as? String {
257+
} else if let string = newValue as? String {
258258
type = .string
259259
value = string
260260
} else if let string = newValue as? NSString {

Tests/SwiftyJSONTests/LiteralConvertibleTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class LiteralConvertibleTests: XCTestCase {
7070
XCTAssert(jsonNil_1 == nil)
7171
let jsonNil_2:JSON = JSON(NSNull.self)
7272
XCTAssert(jsonNil_2 != nil)
73-
let jsonNil_3:JSON = JSON([1:2])
73+
let jsonNil_3:JSON = JSON(["1":2])
7474
XCTAssert(jsonNil_3 != nil)
7575
}
7676

Tests/SwiftyJSONTests/NumberTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class NumberTests: XCTestCase {
5555
XCTAssertEqual(json.numberValue, 9876543210.123456789)
5656
// Number of fraction digits differs on OSX and Linux,
5757
// issue https://github.com/IBM-Swift/SwiftRuntime/issues/183
58-
#if os(Linux)
58+
#if (os(Linux) && !swift(>=4.2))
5959
XCTAssertEqual(json.stringValue, "9876543210.12346")
6060
#else
6161
XCTAssertEqual(json.stringValue, "9876543210.123457")
@@ -128,7 +128,7 @@ class NumberTests: XCTestCase {
128128
XCTAssertEqual(json.numberValue, 9876543210.123456789)
129129
// Number of fraction digits differs on OSX and Linux,
130130
// issue https://github.com/IBM-Swift/SwiftRuntime/issues/183
131-
#if os(Linux)
131+
#if (os(Linux) && !swift(>=4.2))
132132
XCTAssertEqual(json.stringValue, "9876543210.12346")
133133
#else
134134
XCTAssertEqual(json.stringValue, "9876543210.123457")

Tests/SwiftyJSONTests/PrintableTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class PrintableTests: XCTestCase {
4343
let json:JSON = 1234567890.876623
4444
// Number of fraction digits differs on OSX and Linux,
4545
// issue https://github.com/IBM-Swift/SwiftRuntime/issues/183
46-
#if os(Linux)
46+
#if (os(Linux) && !swift(>=4.2))
4747
XCTAssertEqual(json.description, "1234567890.87662")
4848
XCTAssertEqual(json.debugDescription, "1234567890.87662")
4949
#else

0 commit comments

Comments
 (0)