From 46fd455c17499c44f37068f45810c4bf27c8f5e7 Mon Sep 17 00:00:00 2001 From: Kevin Wooten Date: Wed, 15 May 2024 22:01:47 -0700 Subject: [PATCH] Fix tests for old and new OS versions --- .github/workflows/ci.yml | 4 ++-- Makefile | 6 +++--- Tests/ASN1Tests.swift | 28 ++++++++++++++++++++-------- Tests/CBORDecoderTests.swift | 3 +-- Tests/JSONDecoderTests.swift | 2 +- Tests/TimeZoneTests.swift | 21 +++++++++++++++++---- Tests/ValueTransformerTests.swift | 30 +++++++++++++++--------------- Tests/YAMLDecoderTests.swift | 2 +- 8 files changed, 60 insertions(+), 36 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b6a74520a..8f1f0e232 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -48,7 +48,7 @@ jobs: build-test: - runs-on: macos-12 + runs-on: macos-13 needs: [check-build-test] @@ -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 }} diff --git a/Makefile b/Makefile index 72c7312b9..63e1e0d44 100644 --- a/Makefile +++ b/Makefile @@ -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/ diff --git a/Tests/ASN1Tests.swift b/Tests/ASN1Tests.swift index bd6ec8b84..c7e936066 100644 --- a/Tests/ASN1Tests.swift +++ b/Tests/ASN1Tests.swift @@ -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) @@ -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) diff --git a/Tests/CBORDecoderTests.swift b/Tests/CBORDecoderTests.swift index 4a5b4327c..89b82d98c 100644 --- a/Tests/CBORDecoderTests.swift +++ b/Tests/CBORDecoderTests.swift @@ -983,8 +983,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) } diff --git a/Tests/JSONDecoderTests.swift b/Tests/JSONDecoderTests.swift index e65d51e19..b1df9d10b 100644 --- a/Tests/JSONDecoderTests.swift +++ b/Tests/JSONDecoderTests.swift @@ -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) diff --git a/Tests/TimeZoneTests.swift b/Tests/TimeZoneTests.swift index 79e5a63d0..d983d39e6 100644 --- a/Tests/TimeZoneTests.swift +++ b/Tests/TimeZoneTests.swift @@ -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) diff --git a/Tests/ValueTransformerTests.swift b/Tests/ValueTransformerTests.swift index b3c10fa15..a66a95f2f 100644 --- a/Tests/ValueTransformerTests.swift +++ b/Tests/ValueTransformerTests.swift @@ -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()) } @@ -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()) } @@ -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()) } @@ -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()) } @@ -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()) } @@ -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()) } @@ -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()) } @@ -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()) } @@ -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()) } @@ -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()) } @@ -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()) } @@ -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()) } @@ -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()) } @@ -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()) } @@ -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()) } diff --git a/Tests/YAMLDecoderTests.swift b/Tests/YAMLDecoderTests.swift index fff9fdc21..f21fb323f 100644 --- a/Tests/YAMLDecoderTests.swift +++ b/Tests/YAMLDecoderTests.swift @@ -517,7 +517,7 @@ class YAMLDecoderTests: XCTestCase { let yaml = """ --- - url: Not a URL + url: "" ... """