From 5b17ce96e247088d20588602767dd948b8dc6217 Mon Sep 17 00:00:00 2001 From: Lawrence Forooghian Date: Wed, 1 Dec 2021 19:54:55 -0300 Subject: [PATCH 1/3] Suppress compiler warning for deprecated property MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Our tests are using the deprecated -ARTClientOptions.fallbackHostsUseDefault property. We can’t remove this usage until we remove the property. But we want to be able to turn on “treat warnings as errors” so we need a way to suppress the resultant compiler warning. Swift doesn’t really provide options for suppressing warnings, so instead we take advantage of the fact that it doesn’t emit warnings when using deprecated functionality inside of a method which is itself marked as deprecated. See https://forums.swift.org/t/swift-should-allow-for-suppression-of-warnings-especially-those-that-come-from-objective-c/19216/68. --- Spec/Tests/RealtimeClientConnectionTests.swift | 2 ++ Spec/Tests/RestClientChannelTests.swift | 1 + Spec/Tests/RestClientTests.swift | 6 ++++++ 3 files changed, 9 insertions(+) diff --git a/Spec/Tests/RealtimeClientConnectionTests.swift b/Spec/Tests/RealtimeClientConnectionTests.swift index 6c3cba9ad..139dc0ab2 100644 --- a/Spec/Tests/RealtimeClientConnectionTests.swift +++ b/Spec/Tests/RealtimeClientConnectionTests.swift @@ -3326,6 +3326,7 @@ class RealtimeClientConnectionTests: XCTestCase { } // RTN17b + @available(*, deprecated, message: "This test is marked as deprecated so as to not trigger a compiler warning for using the -ARTClientOptions.fallbackHostsUseDefault property. Remove this deprecation when removing the property.") func test__086__Connection__Host_Fallback__failing_connections_with_custom_endpoint_should_result_in_an_error_immediately() { beforeEach__Connection__Host_Fallback() @@ -3380,6 +3381,7 @@ class RealtimeClientConnectionTests: XCTestCase { } // RTN17b + @available(*, deprecated, message: "This test is marked as deprecated so as to not trigger a compiler warning for using the -ARTClientOptions.fallbackHostsUseDefault property. Remove this deprecation when removing the property.") func test__087__Connection__Host_Fallback__failing_connections_with_custom_endpoint_should_result_in_time_outs() { beforeEach__Connection__Host_Fallback() diff --git a/Spec/Tests/RestClientChannelTests.swift b/Spec/Tests/RestClientChannelTests.swift index c2b6e2744..d95c6c5df 100644 --- a/Spec/Tests/RestClientChannelTests.swift +++ b/Spec/Tests/RestClientChannelTests.swift @@ -744,6 +744,7 @@ class RestClientChannelTests: XCTestCase { } // RSL1k4 + @available(*, deprecated, message: "This test is marked as deprecated so as to not trigger a compiler warning for using the -ARTClientOptions.fallbackHostsUseDefault property. Remove this deprecation when removing the property.") func test__025__publish__idempotent_publishing__should_have_only_one_published_message() { client.internal.options.idempotentRestPublishing = true client.internal.httpExecutor = testHTTPExecutor diff --git a/Spec/Tests/RestClientTests.swift b/Spec/Tests/RestClientTests.swift index 8266ea789..2c7167419 100644 --- a/Spec/Tests/RestClientTests.swift +++ b/Spec/Tests/RestClientTests.swift @@ -765,6 +765,7 @@ class RestClientTests: XCTestCase { // TO3k7 + @available(*, deprecated, message: "This test is marked as deprecated so as to not trigger a compiler warning for using the -ARTClientOptions.fallbackHostsUseDefault property. Remove this deprecation when removing the property.") func test__051__RestClient__Host_Fallback__fallbackHostsUseDefault_option__allows_the_default_fallback_hosts_to_be_used_when__environment__is_not_production() { let options = ARTClientOptions(key: "xxxx:xxxx") options.environment = "not-production" @@ -785,6 +786,7 @@ class RestClientTests: XCTestCase { } } + @available(*, deprecated, message: "This test is marked as deprecated so as to not trigger a compiler warning for using the -ARTClientOptions.fallbackHostsUseDefault property. Remove this deprecation when removing the property.") func test__052__RestClient__Host_Fallback__fallbackHostsUseDefault_option__allows_the_default_fallback_hosts_to_be_used_when_a_custom_Realtime_or_REST_host_endpoint_is_being_used() { let options = ARTClientOptions(key: "xxxx:xxxx") options.restHost = "fake1.ably.io" @@ -806,11 +808,13 @@ class RestClientTests: XCTestCase { } } + @available(*, deprecated, message: "This test is marked as deprecated so as to not trigger a compiler warning for using the -ARTClientOptions.fallbackHostsUseDefault property. Remove this deprecation when removing the property.") func test__053__RestClient__Host_Fallback__fallbackHostsUseDefault_option__should_be_inactive_by_default() { let options = ARTClientOptions(key: "xxxx:xxxx") expect(options.fallbackHostsUseDefault).to(beFalse()) } + @available(*, deprecated, message: "This test is marked as deprecated so as to not trigger a compiler warning for using the -ARTClientOptions.fallbackHostsUseDefault property. Remove this deprecation when removing the property.") func test__054__RestClient__Host_Fallback__fallbackHostsUseDefault_option__should_never_accept_to_configure__fallbackHost__and_set__fallbackHostsUseDefault__to__true_() { let options = ARTClientOptions(key: "xxxx:xxxx") expect(options.fallbackHosts).to(beNil()) @@ -953,6 +957,7 @@ class RestClientTests: XCTestCase { } // RSC15b3, RSC15g4 + @available(*, deprecated, message: "This test is marked as deprecated so as to not trigger a compiler warning for using the -ARTClientOptions.fallbackHostsUseDefault property. Remove this deprecation when removing the property.") func test__060__RestClient__Host_Fallback__Fallback_behavior__should_be_applied_when_ClientOptions_fallbackHosts_is_not_provided_and_deprecated_fallbackHostsUseDefault_is_on() { let options = ARTClientOptions(key: "xxxx:xxxx") options.fallbackHostsUseDefault = true @@ -1100,6 +1105,7 @@ class RestClientTests: XCTestCase { } // RSC15g4 + @available(*, deprecated, message: "This test is marked as deprecated so as to not trigger a compiler warning for using the -ARTClientOptions.fallbackHostsUseDefault property. Remove this deprecation when removing the property.") func test__046__RestClient__Host_Fallback__applies_when_ClientOptions_fallbackHostsUseDefault_is_true() { let options = ARTClientOptions(key: "xxxx:xxxx") options.environment = "test" From 4d87e237855177867dd02eacfcfd0cb7a010a7d7 Mon Sep 17 00:00:00 2001 From: Lawrence Forooghian Date: Wed, 1 Dec 2021 20:05:28 -0300 Subject: [PATCH 2/3] Fix warning in comparing messages in Crypto tests The warning is: > Treating a forced downcast to 'ARTMessage' as optional will never > produce 'nil' --- Spec/Tests/CryptoTests.swift | 44 ++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/Spec/Tests/CryptoTests.swift b/Spec/Tests/CryptoTests.swift index 4c41fee0f..90640c616 100644 --- a/Spec/Tests/CryptoTests.swift +++ b/Spec/Tests/CryptoTests.swift @@ -128,7 +128,7 @@ class CryptoTests: XCTestCase { case should_decrypt_messages_as_expected_in_the_fixtures } - func reusableTestsTestFixture(_ cryptoFixture: (fileName: String, expectedEncryptedEncoding: String, keyLength: UInt), testCase: TestCase_ReusableTestsTestFixture, beforeEach contextBeforeEach: (() -> Void)? = nil, afterEach contextAfterEach: (() -> Void)? = nil) { + func reusableTestsTestFixture(_ cryptoFixture: (fileName: String, expectedEncryptedEncoding: String, keyLength: UInt), testCase: TestCase_ReusableTestsTestFixture, beforeEach contextBeforeEach: (() -> Void)? = nil, afterEach contextAfterEach: (() -> Void)? = nil) throws { let (key, iv, items) = AblyTests.loadCryptoTestData(cryptoFixture.fileName) let decoder = ARTDataEncoder(cipherParams: nil, error: nil) let cipherParams = ARTCipherParams(algorithm: "aes", key: key as ARTCipherKeyCompatible, iv: iv) @@ -140,7 +140,7 @@ class CryptoTests: XCTestCase { return msg } - func test__should_encrypt_messages_as_expected_in_the_fixtures() { + func test__should_encrypt_messages_as_expected_in_the_fixtures() throws { contextBeforeEach?() for item in items { @@ -153,17 +153,17 @@ class CryptoTests: XCTestCase { expect(error).to(beNil()) expect(decoded).notTo(beNil()) - let encrypted = decoded.encode(with: encrypter, error: &error) + let encrypted = try XCTUnwrap(decoded.encode(with: encrypter, error: &error) as? ARTMessage) expect(error).to(beNil()) expect(encrypted).notTo(beNil()) - - expect(encrypted as! ARTMessage).to(equal(encryptedFixture)) + + expect(encrypted).to(equal(encryptedFixture)) } contextAfterEach?() } - func test__should_decrypt_messages_as_expected_in_the_fixtures() { + func test__should_decrypt_messages_as_expected_in_the_fixtures() throws { contextBeforeEach?() for item in items { @@ -176,11 +176,11 @@ class CryptoTests: XCTestCase { expect(error).to(beNil()) expect(decoded).notTo(beNil()) - let decrypted = encryptedFixture.decode(with: encrypter, error: &error) + let decrypted = try XCTUnwrap(encryptedFixture.decode(with: encrypter, error: &error) as? ARTMessage) expect(error).to(beNil()) expect(decrypted).notTo(beNil()) - expect(decrypted as! ARTMessage).to(equal(decoded)) + expect(decrypted).to(equal(decoded)) } contextAfterEach?() @@ -188,33 +188,33 @@ class CryptoTests: XCTestCase { switch testCase { case .should_encrypt_messages_as_expected_in_the_fixtures: - test__should_encrypt_messages_as_expected_in_the_fixtures() + try test__should_encrypt_messages_as_expected_in_the_fixtures() case .should_decrypt_messages_as_expected_in_the_fixtures: - test__should_decrypt_messages_as_expected_in_the_fixtures() + try test__should_decrypt_messages_as_expected_in_the_fixtures() } } - func reusableTestsWrapper__Crypto__with_fixtures_from_crypto_data_128_json__reusableTestsTestFixture(testCase: TestCase_ReusableTestsTestFixture) { - reusableTestsTestFixture(("crypto-data-128", "cipher+aes-128-cbc", 128), testCase: testCase) + func reusableTestsWrapper__Crypto__with_fixtures_from_crypto_data_128_json__reusableTestsTestFixture(testCase: TestCase_ReusableTestsTestFixture) throws { + try reusableTestsTestFixture(("crypto-data-128", "cipher+aes-128-cbc", 128), testCase: testCase) } - func test__011__Crypto__with_fixtures_from_crypto_data_128_json__should_encrypt_messages_as_expected_in_the_fixtures() { - reusableTestsWrapper__Crypto__with_fixtures_from_crypto_data_128_json__reusableTestsTestFixture(testCase: .should_encrypt_messages_as_expected_in_the_fixtures) + func test__011__Crypto__with_fixtures_from_crypto_data_128_json__should_encrypt_messages_as_expected_in_the_fixtures() throws { + try reusableTestsWrapper__Crypto__with_fixtures_from_crypto_data_128_json__reusableTestsTestFixture(testCase: .should_encrypt_messages_as_expected_in_the_fixtures) } - func test__012__Crypto__with_fixtures_from_crypto_data_128_json__should_decrypt_messages_as_expected_in_the_fixtures() { - reusableTestsWrapper__Crypto__with_fixtures_from_crypto_data_128_json__reusableTestsTestFixture(testCase: .should_decrypt_messages_as_expected_in_the_fixtures) + func test__012__Crypto__with_fixtures_from_crypto_data_128_json__should_decrypt_messages_as_expected_in_the_fixtures() throws { + try reusableTestsWrapper__Crypto__with_fixtures_from_crypto_data_128_json__reusableTestsTestFixture(testCase: .should_decrypt_messages_as_expected_in_the_fixtures) } - func reusableTestsWrapper__Crypto__with_fixtures_from_crypto_data_256_json__reusableTestsTestFixture(testCase: TestCase_ReusableTestsTestFixture) { - reusableTestsTestFixture(("crypto-data-256", "cipher+aes-256-cbc", 256), testCase: testCase) + func reusableTestsWrapper__Crypto__with_fixtures_from_crypto_data_256_json__reusableTestsTestFixture(testCase: TestCase_ReusableTestsTestFixture) throws { + try reusableTestsTestFixture(("crypto-data-256", "cipher+aes-256-cbc", 256), testCase: testCase) } - func test__013__Crypto__with_fixtures_from_crypto_data_256_json__should_encrypt_messages_as_expected_in_the_fixtures() { - reusableTestsWrapper__Crypto__with_fixtures_from_crypto_data_256_json__reusableTestsTestFixture(testCase: .should_encrypt_messages_as_expected_in_the_fixtures) + func test__013__Crypto__with_fixtures_from_crypto_data_256_json__should_encrypt_messages_as_expected_in_the_fixtures() throws { + try reusableTestsWrapper__Crypto__with_fixtures_from_crypto_data_256_json__reusableTestsTestFixture(testCase: .should_encrypt_messages_as_expected_in_the_fixtures) } - func test__014__Crypto__with_fixtures_from_crypto_data_256_json__should_decrypt_messages_as_expected_in_the_fixtures() { - reusableTestsWrapper__Crypto__with_fixtures_from_crypto_data_256_json__reusableTestsTestFixture(testCase: .should_decrypt_messages_as_expected_in_the_fixtures) + func test__014__Crypto__with_fixtures_from_crypto_data_256_json__should_decrypt_messages_as_expected_in_the_fixtures() throws { + try reusableTestsWrapper__Crypto__with_fixtures_from_crypto_data_256_json__reusableTestsTestFixture(testCase: .should_decrypt_messages_as_expected_in_the_fixtures) } } From 122ae44d573041d215b1cc71af0fb9af723672dc Mon Sep 17 00:00:00 2001 From: Lawrence Forooghian Date: Wed, 1 Dec 2021 20:13:31 -0300 Subject: [PATCH 3/3] =?UTF-8?q?Turn=20on=20=E2=80=9Ctreat=20warnings=20as?= =?UTF-8?q?=20errors=E2=80=9D=20across=20the=20codebase?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ably.xcodeproj/project.pbxproj | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Ably.xcodeproj/project.pbxproj b/Ably.xcodeproj/project.pbxproj index 24deed2d0..0cd24692d 100644 --- a/Ably.xcodeproj/project.pbxproj +++ b/Ably.xcodeproj/project.pbxproj @@ -3220,6 +3220,7 @@ "$(inherited)", ); GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_TREAT_WARNINGS_AS_ERRORS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNDECLARED_SELECTOR = YES; @@ -3230,6 +3231,7 @@ MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; + SWIFT_TREAT_WARNINGS_AS_ERRORS = YES; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -3275,6 +3277,7 @@ ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_NO_COMMON_BLOCKS = YES; + GCC_TREAT_WARNINGS_AS_ERRORS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNDECLARED_SELECTOR = YES; @@ -3286,6 +3289,7 @@ SDKROOT = iphoneos; SWIFT_COMPILATION_MODE = wholemodule; SWIFT_OPTIMIZATION_LEVEL = "-O"; + SWIFT_TREAT_WARNINGS_AS_ERRORS = YES; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic";