From 6fac5103dc357074c827d16d13f7cdb6c6efdd0a Mon Sep 17 00:00:00 2001 From: Pierre Mardon Date: Wed, 23 Aug 2023 18:23:32 +0200 Subject: [PATCH] Enhance constructor error message in case the default value is missing (#31) * Enhance constructor error message in case the default value is missing * Delete unneeded overriden functions in test cases --- Sources/PDefaults/PDefaults+Init.swift | 2 +- Tests/PDefaultsTests/TestMigration.swift | 4 ---- Tests/PDefaultsTests/TestPublisher.swift | 4 ---- Tests/PDefaultsTests/TestStorage.swift | 4 ---- 4 files changed, 1 insertion(+), 13 deletions(-) diff --git a/Sources/PDefaults/PDefaults+Init.swift b/Sources/PDefaults/PDefaults+Init.swift index a3f34b1..98c59ed 100644 --- a/Sources/PDefaults/PDefaults+Init.swift +++ b/Sources/PDefaults/PDefaults+Init.swift @@ -155,7 +155,7 @@ public extension PDefaults { } /// Constructor catching all type errors to expose compatibility constraints message - @available(*, unavailable, message: "You can use PDefaults only types that either conform to Codable or are natively handled by UserDefaults") + @available(*, unavailable, message: "You have to provide a default value or use an optional type. In the latter case, make sure the type either conforms to Codable or is natively handled by UserDefaults") // swiftlint:disable:previous line_length convenience init(_ key: String, suite: UserDefaults = .standard, diff --git a/Tests/PDefaultsTests/TestMigration.swift b/Tests/PDefaultsTests/TestMigration.swift index e500e82..0fc7ef9 100644 --- a/Tests/PDefaultsTests/TestMigration.swift +++ b/Tests/PDefaultsTests/TestMigration.swift @@ -17,10 +17,6 @@ class TestMigration: XCTestCase { PDefaultsConfiguration.mock = false } - override func tearDown() { - super.tearDown() - } - func testNominalMigration() { let value = 1 let source = PDefaults(wrappedValue: nil, sourceKey) diff --git a/Tests/PDefaultsTests/TestPublisher.swift b/Tests/PDefaultsTests/TestPublisher.swift index be76811..f5e7ea4 100644 --- a/Tests/PDefaultsTests/TestPublisher.swift +++ b/Tests/PDefaultsTests/TestPublisher.swift @@ -13,10 +13,6 @@ class TestPublisher: XCTestCase { PDefaultsConfiguration.mock = false } - override func tearDown() { - super.tearDown() - } - func testClosureCalledOnSink() { let pdefaults = PDefaults(wrappedValue: 1, key, suite: suite) let expectCalled = expectation(description: "PDefaults publisher sink closure is expected to be called on" diff --git a/Tests/PDefaultsTests/TestStorage.swift b/Tests/PDefaultsTests/TestStorage.swift index 96d0b06..811c8be 100644 --- a/Tests/PDefaultsTests/TestStorage.swift +++ b/Tests/PDefaultsTests/TestStorage.swift @@ -13,10 +13,6 @@ class TestStorage: XCTestCase { PDefaultsConfiguration.mock = false } - override func tearDown() { - super.tearDown() - } - func testNoStorageWhenNotNeeded() { let pDefaults = PDefaults(wrappedValue: Optional.some(1), key, suite: suite) XCTAssert(suite.object(forKey: key) == nil, "Storage should not contain a value for key \"\(key)\"")