Skip to content

Commit

Permalink
Merge pull request #68 from outfoxx/fix/ci-tests
Browse files Browse the repository at this point in the history
Upgrade CI and fix tests
  • Loading branch information
kdubb committed May 16, 2024
2 parents 583f1b0 + a73f80e commit e88b0a3
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 38 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:

check-build-test:

runs-on: macos-12
runs-on: macos-13

steps:

Expand All @@ -27,7 +27,7 @@ jobs:
fetch-depth: 0

- name: Select Xcode
run: sudo xcode-select -s /Applications/Xcode_14.1.app/Contents/Developer
run: sudo xcode-select -s /Applications/Xcode_15.2.app/Contents/Developer

- name: SwiftLint
run: |
Expand All @@ -48,7 +48,7 @@ jobs:

build-test:

runs-on: macos-12
runs-on: macos-13

needs: [check-build-test]

Expand All @@ -68,7 +68,7 @@ jobs:
- uses: actions/checkout@v3

- name: Select Xcode
run: sudo xcode-select -s /Applications/Xcode_14.1.app/Contents/Developer
run: sudo xcode-select -s /Applications/Xcode_15.2.app/Contents/Developer

- name: Build/Test
run: make build-test-${{ matrix.platform }}
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ build-test-macos: check-tools
$(call buildtest,macOS,platform=macOS)

build-test-ios: check-tools
$(call buildtest,iOS,$(shell findsimulator --os-type ios "iPhone"))
$(call buildtest,ios,platform=iOS Simulator$(comma)name=iPhone 15)

build-test-tvos: check-tools
$(call buildtest,tvOS,$(shell findsimulator --os-type tvos "Apple TV"))
$(call buildtest,tvos,platform=tvOS Simulator$(comma)name=Apple TV)

build-test-watchos: check-tools
$(call buildtest,watchOS,$(shell findsimulator --os-type watchos "Apple Watch"))
$(call buildtest,watchos,platform=watchOS Simulator$(comma)name=Apple Watch Series 9 (45mm))

format:
swiftformat --config .swiftformat Sources/ Tests/
Expand Down
28 changes: 20 additions & 8 deletions Tests/ASN1Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,26 @@ class ASN1Tests: XCTestCase {
XCTAssertEqual(date(3), 7_979_553_224.567)
XCTAssertEqual(tz(3), .utc)

let secondsOffset: Int
#if !os(Linux)
if #available(macOS 14, iOS 17, tvOS 17, watchOS 10, *) {
secondsOffset = 40953
}
else {
secondsOffset = 40980
}
#else
secondsOffset = 40980
#endif

XCTAssertEqual(date(4), 7_979_553_224 - 40953)
XCTAssertEqual(offset(4), 40980)
XCTAssertEqual(offset(4), secondsOffset)
XCTAssertEqual(date(5), 7_979_553_224.567 - 40953)
XCTAssertEqual(offset(5), 40980)
XCTAssertEqual(offset(5), secondsOffset)
XCTAssertEqual(date(6), 7_979_553_224 - 40953)
XCTAssertEqual(offset(6), 40980)
XCTAssertEqual(offset(6), secondsOffset)
XCTAssertEqual(date(7), 7_979_553_224.567 - 40953)
XCTAssertEqual(offset(7), 40980)
XCTAssertEqual(offset(7), secondsOffset)
XCTAssertEqual(date(8), 7_979_553_224 - 40920)
XCTAssertEqual(offset(8), 40920)
XCTAssertEqual(date(9), 7_979_553_224.567 - 40920)
Expand All @@ -170,13 +182,13 @@ class ASN1Tests: XCTestCase {
XCTAssertEqual(offset(13), 39600)

XCTAssertEqual(date(14), 7_979_553_224 + 40953)
XCTAssertEqual(offset(14), -40980)
XCTAssertEqual(offset(14), -secondsOffset)
XCTAssertEqual(date(15), 7_979_553_224.567 + 40953)
XCTAssertEqual(offset(15), -40980)
XCTAssertEqual(offset(15), -secondsOffset)
XCTAssertEqual(date(16), 7_979_553_224 + 40953)
XCTAssertEqual(offset(16), -40980)
XCTAssertEqual(offset(16), -secondsOffset)
XCTAssertEqual(date(17), 7_979_553_224.567 + 40953)
XCTAssertEqual(offset(17), -40980)
XCTAssertEqual(offset(17), -secondsOffset)
XCTAssertEqual(date(18), 7_979_553_224 + 40920)
XCTAssertEqual(offset(18), -40920)
XCTAssertEqual(date(19), 7_979_553_224.567 + 40920)
Expand Down
8 changes: 6 additions & 2 deletions Tests/CBORDecoderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ import XCTest

class CBORDecoderTests: XCTestCase {

func testDecodeEmpty() {
struct Empty: Equatable, Codable {}
XCTAssertEqual(try CBORDecoder.default.decode(Empty.self, from: Data([0xA0])), Empty())
}

func testDecodeNull() {
XCTAssertNil(try CBORDecoder.default.decodeIfPresent(String.self, from: Data([0xF6])))
}
Expand Down Expand Up @@ -983,8 +988,7 @@ class CBORDecoderTests: XCTestCase {
URL(string: "https://example.com/some/thing")
)
XCTAssertThrowsError(
try CBORDecoder.default.decode(URL.self, from: Data([0xD8, 0x20, 0x67, 0x62, 0x61,
0x64, 0x20, 0x75, 0x72, 0x6C]))
try CBORDecoder.default.decode(URL.self, from: Data([0xD8, 0x20, 0x60]))
) { error in
AssertDecodingDataCorrupted(error)
}
Expand Down
5 changes: 5 additions & 0 deletions Tests/CBOREncoderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ class CBOREncoderTests: XCTestCase {
return Array(try CBOREncoder().encode(value))
}

func testEncodeEmpty() {
struct Empty: Codable {}
XCTAssertEqual(try encode(Empty()), [0xA0])
}

func testEncodeNull() {
XCTAssertEqual(try encode(String?(nil)), [0xF6])
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/JSONDecoderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ class JSONDecoderTests: XCTestCase {
var url: URL
}

let json = #"{"url":"Not a URL"}"#
let json = #"{"url":""}"#

XCTAssertThrowsError(try JSON.Decoder.default.decode(TestValue.self, from: json)) { error in
AssertDecodingDataCorrupted(error)
Expand Down
21 changes: 17 additions & 4 deletions Tests/TimeZoneTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,28 @@ class TimeZoneTests: XCTestCase {
let utcTZ = TimeZone.timeZone(from: "20201212111111.000Z")
XCTAssertEqual(utcTZ?.secondsFromGMT(), 0)

let secondsOffset: Int

#if !os(Linux)
if #available(macOS 14, iOS 17, tvOS 17, watchOS 10, *) {
secondsOffset = 45296
}
else {
secondsOffset = 45300
}
#else
secondsOffset = 45300
#endif

let aheadSecsTZ1 = TimeZone.timeZone(from: "20201212111111.000+123456")
XCTAssertEqual(aheadSecsTZ1?.secondsFromGMT(), 45300)
XCTAssertEqual(aheadSecsTZ1?.secondsFromGMT(), secondsOffset)
let aheadSecsTZ2 = TimeZone.timeZone(from: "20201212111111.000+12:34:56")
XCTAssertEqual(aheadSecsTZ2?.secondsFromGMT(), 45300)
XCTAssertEqual(aheadSecsTZ2?.secondsFromGMT(), secondsOffset)

let behindSecsTZ1 = TimeZone.timeZone(from: "20201212111111.000-123456")
XCTAssertEqual(behindSecsTZ1?.secondsFromGMT(), -45300)
XCTAssertEqual(behindSecsTZ1?.secondsFromGMT(), -secondsOffset)
let behindSecsTZ2 = TimeZone.timeZone(from: "20201212111111.000-12:34:56")
XCTAssertEqual(behindSecsTZ2?.secondsFromGMT(), -45300)
XCTAssertEqual(behindSecsTZ2?.secondsFromGMT(), -secondsOffset)

let aheadMinsTZ1 = TimeZone.timeZone(from: "20201212111111.000+1234")
XCTAssertEqual(aheadMinsTZ1?.secondsFromGMT(), 45240)
Expand Down
30 changes: 15 additions & 15 deletions Tests/ValueTransformerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ class ValueTransformerTests: XCTestCase {
}

init(from decoder: Decoder) throws {
var container = try decoder.singleValueContainer()
let container = try decoder.singleValueContainer()
value = try container.decode(using: IntToBool())
}

Expand All @@ -907,7 +907,7 @@ class ValueTransformerTests: XCTestCase {
}

init(from decoder: Decoder) throws {
var container = try decoder.singleValueContainer()
let container = try decoder.singleValueContainer()
value = try container.decode(using: BoolToInt<Int>())
}

Expand All @@ -933,7 +933,7 @@ class ValueTransformerTests: XCTestCase {
}

init(from decoder: Decoder) throws {
var container = try decoder.singleValueContainer()
let container = try decoder.singleValueContainer()
value = try container.decode(using: BoolToInt<Int8>())
}

Expand All @@ -959,7 +959,7 @@ class ValueTransformerTests: XCTestCase {
}

init(from decoder: Decoder) throws {
var container = try decoder.singleValueContainer()
let container = try decoder.singleValueContainer()
value = try container.decode(using: BoolToInt<Int16>())
}

Expand All @@ -985,7 +985,7 @@ class ValueTransformerTests: XCTestCase {
}

init(from decoder: Decoder) throws {
var container = try decoder.singleValueContainer()
let container = try decoder.singleValueContainer()
value = try container.decode(using: BoolToInt<Int32>())
}

Expand All @@ -1011,7 +1011,7 @@ class ValueTransformerTests: XCTestCase {
}

init(from decoder: Decoder) throws {
var container = try decoder.singleValueContainer()
let container = try decoder.singleValueContainer()
value = try container.decode(using: BoolToInt<Int64>())
}

Expand All @@ -1037,7 +1037,7 @@ class ValueTransformerTests: XCTestCase {
}

init(from decoder: Decoder) throws {
var container = try decoder.singleValueContainer()
let container = try decoder.singleValueContainer()
value = try container.decode(using: BoolToInt<UInt>())
}

Expand All @@ -1063,7 +1063,7 @@ class ValueTransformerTests: XCTestCase {
}

init(from decoder: Decoder) throws {
var container = try decoder.singleValueContainer()
let container = try decoder.singleValueContainer()
value = try container.decode(using: BoolToInt<UInt8>())
}

Expand All @@ -1089,7 +1089,7 @@ class ValueTransformerTests: XCTestCase {
}

init(from decoder: Decoder) throws {
var container = try decoder.singleValueContainer()
let container = try decoder.singleValueContainer()
value = try container.decode(using: BoolToInt<UInt16>())
}

Expand All @@ -1115,7 +1115,7 @@ class ValueTransformerTests: XCTestCase {
}

init(from decoder: Decoder) throws {
var container = try decoder.singleValueContainer()
let container = try decoder.singleValueContainer()
value = try container.decode(using: BoolToInt<UInt32>())
}

Expand All @@ -1141,7 +1141,7 @@ class ValueTransformerTests: XCTestCase {
}

init(from decoder: Decoder) throws {
var container = try decoder.singleValueContainer()
let container = try decoder.singleValueContainer()
value = try container.decode(using: BoolToInt<UInt64>())
}

Expand All @@ -1167,7 +1167,7 @@ class ValueTransformerTests: XCTestCase {
}

init(from decoder: Decoder) throws {
var container = try decoder.singleValueContainer()
let container = try decoder.singleValueContainer()
value = try container.decode(using: BoolToString())
}

Expand All @@ -1193,7 +1193,7 @@ class ValueTransformerTests: XCTestCase {
}

init(from decoder: Decoder) throws {
var container = try decoder.singleValueContainer()
let container = try decoder.singleValueContainer()
value = try container.decode(using: BoolToFloat<Float>())
}

Expand All @@ -1219,7 +1219,7 @@ class ValueTransformerTests: XCTestCase {
}

init(from decoder: Decoder) throws {
var container = try decoder.singleValueContainer()
let container = try decoder.singleValueContainer()
value = try container.decode(using: BoolToFloat<Double>())
}

Expand All @@ -1245,7 +1245,7 @@ class ValueTransformerTests: XCTestCase {
}

init(from decoder: Decoder) throws {
var container = try decoder.singleValueContainer()
let container = try decoder.singleValueContainer()
value = try container.decode(using: BoolToBoolValue())
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/YAMLDecoderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ class YAMLDecoderTests: XCTestCase {
let yaml =
"""
---
url: Not a URL
url: ""
...
"""
Expand Down

0 comments on commit e88b0a3

Please sign in to comment.