diff --git a/Package.swift b/Package.swift index 3f5827a0..163ac7bc 100644 --- a/Package.swift +++ b/Package.swift @@ -28,7 +28,6 @@ let package = Package( targets: [ .target( name: "UBFoundation", - dependencies: ["UBMacros"], swiftSettings: [ .swiftLanguageMode(.v6), ] @@ -67,13 +66,6 @@ let package = Package( .swiftLanguageMode(.v6), ] ), - .macro(name: "UBMacros", dependencies: [ - .product(name: "SwiftSyntaxMacros", package: "swift-syntax"), - .product(name: "SwiftCompilerPlugin", package: "swift-syntax"), - ], - swiftSettings: [ - .swiftLanguageMode(.v6), - ]), .testTarget(name: "UBFoundationTests", dependencies: ["UBFoundation", .product(name: "UBLocalNetworking", package: "ios-local-networking")], resources: [ diff --git a/Sources/UBFoundation/Cron/CronJob.swift b/Sources/UBFoundation/Cron/CronJob.swift index cb7ed8d0..4f6a15a1 100644 --- a/Sources/UBFoundation/Cron/CronJob.swift +++ b/Sources/UBFoundation/Cron/CronJob.swift @@ -55,7 +55,7 @@ public final class UBCronJob: Sendable { /// The state of the Job public private(set) nonisolated(unsafe) var state: State = .initial { willSet { - #assert(state != newValue) + assert(state != newValue) } } diff --git a/Sources/UBFoundation/Cron/CronRule.swift b/Sources/UBFoundation/Cron/CronRule.swift index cff5bda9..b59862ed 100644 --- a/Sources/UBFoundation/Cron/CronRule.swift +++ b/Sources/UBFoundation/Cron/CronRule.swift @@ -86,7 +86,7 @@ public struct UBFireAtIntervalRule: UBCronRule { /// - isRepeating: If the job should keep repeat afterwards /// - tolerence: The accepted tolerence with the firing date public init(_ interval: TimeInterval, repeat isRepeating: Bool = false, tolerence: DispatchTimeInterval? = nil) { - #assert((isRepeating && interval > 0) || !isRepeating) + assert((isRepeating && interval > 0) || !isRepeating) repeatRule = isRepeating ? .after(interval.dispatchTimeInterval) : .never self.tolerence = tolerence self.interval = interval diff --git a/Sources/UBFoundation/Helpers/URL+Macro.swift b/Sources/UBFoundation/Helpers/URL+Macro.swift deleted file mode 100644 index 5311089a..00000000 --- a/Sources/UBFoundation/Helpers/URL+Macro.swift +++ /dev/null @@ -1,11 +0,0 @@ -// -// URL+Macro.swift -// -// -// Created by Matthias Felix on 20.09.2023. -// - -import Foundation - -@freestanding(expression) -public macro URL(_ stringLiteral: String) -> URL = #externalMacro(module: "UBMacros", type: "URLMacro") diff --git a/Sources/UBFoundation/Logging/Logger.swift b/Sources/UBFoundation/Logging/Logger.swift new file mode 100644 index 00000000..e1322aa6 --- /dev/null +++ b/Sources/UBFoundation/Logging/Logger.swift @@ -0,0 +1,79 @@ +// +// Logger.swift +// UBKit +// +// Created by Nicolas Märki on 12.09.2024. +// + +// LOGGER TEMPLATE FILE +// Copy this file to your project, replace subsystem and category with your own values +// Copying ensures that methods shadow Swift originals + +import Foundation +import os + +public let Log = os.Logger(subsystem: "UBKit", category: "Default") + +public extension Logger { + func reportError( + _ message: String, file: StaticString = #file, line: UInt = #line + ) { + UBNonFatalErrorReporter.shared + .report( + NSError( + domain: (file.description as NSString).lastPathComponent, + code: Int(line), + userInfo: [NSDebugDescriptionErrorKey: message] + ) + ) + Log.error("\(message)") + } + + func reportCritical( + _ message: String, file: StaticString = #file, line: UInt = #line + ) { + UBNonFatalErrorReporter.shared + .report( + NSError( + domain: (file.description as NSString).lastPathComponent, + code: Int(line), + userInfo: [NSDebugDescriptionErrorKey: message] + ) + ) + Log.critical("\(message)") + } +} + +@available(*, deprecated, message: "Use Logger instead", renamed: "Log.debug") +public func print( + _ items: Any..., separator: String = " ", terminator: String = "\n" +) { + Log.debug("(\(items.map { "\($0)" }.joined(separator: separator)))") +} + +public func assert( + _ condition: @autoclosure () -> Bool, + _ message: @autoclosure () -> String = String(), + swiftAssertionFailure: Bool = true, + file: StaticString = #file, + line: UInt = #line +) { + if !condition() { + Log.reportCritical(message(), file: file, line: line) + if swiftAssertionFailure { + Swift.assertionFailure() + } + } +} + +public func assertionFailure( + _ message: @autoclosure () -> String = String(), + swiftAssertionFailure: Bool = true, + file: StaticString = #file, + line: UInt = #line +) { + Log.reportCritical("Assertion failed: \(message())") + if swiftAssertionFailure { + Swift.assertionFailure(message(), file: file, line: line) + } +} diff --git a/Sources/UBFoundation/Logging/PrintMacros+Implementation.swift b/Sources/UBFoundation/Logging/PrintMacros+Implementation.swift deleted file mode 100644 index d7674a7c..00000000 --- a/Sources/UBFoundation/Logging/PrintMacros+Implementation.swift +++ /dev/null @@ -1,46 +0,0 @@ -// -// PrintMacros+Implementation.swift -// UBKit -// -// Created by Nicolas Märki on 12.09.2024. -// - -import Foundation -import os - -@available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) -public struct _PrintMacro { - public static let Logger = os.Logger(subsystem: "UBLog", category: "Default") - - @_transparent - public static func noop() { - // This function will be optimized away - } - - // Assertion Failure can be disabled - // Useful for unit tests to avoid crash - public nonisolated(unsafe) static var disableAssertionFailure = false - - public static func sendError(_ message: String, file: String = #file, line: Int = #line) -> String { - UBNonFatalErrorReporter.shared.report(NSError(domain: (file as NSString).lastPathComponent, - code: line, - userInfo: [NSDebugDescriptionErrorKey: message])) - return message // allows nesting sendError ins os_log statements - } - - public static func assert(_ condition: Bool, _ handler: () -> Void) { - if !condition { - handler() - if !disableAssertionFailure { - Swift.assertionFailure() - } - } - } - - public static func assertionFailure(_ handler: () -> Void) { - handler() - if !disableAssertionFailure { - Swift.assertionFailure() - } - } -} diff --git a/Sources/UBFoundation/Logging/PrintMacros.swift b/Sources/UBFoundation/Logging/PrintMacros.swift deleted file mode 100644 index c4e23b79..00000000 --- a/Sources/UBFoundation/Logging/PrintMacros.swift +++ /dev/null @@ -1,58 +0,0 @@ -// -// PrintMacros.swift -// UBKit -// -// Created by Nicolas Märki on 12.09.2024. -// - -// Uncomment the following line and copy this file to your project - -import Foundation -import os - -// import UBFoundation - -// typealias _PrintMacro = UBFoundation._PrintMacro - -@available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) -@freestanding(expression) -public macro print(_ message: OSLogMessage) = #externalMacro( - module: "UBMacros", - type: "PrintMacro" -) - -@available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) -@freestanding(expression) -public macro printError(_ message: String) = #externalMacro( - module: "UBMacros", - type: "PrintErrorMacro" -) - -@available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) -@freestanding(expression) -public macro assert(_ condition: Bool, _ message: @autoclosure () -> String = String()) = #externalMacro( - module: "UBMacros", - type: "AssertMacro" -) - -@available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) -@freestanding(expression) -public macro assertionFailure(_ message: @autoclosure () -> String = String()) = #externalMacro( - module: "UBMacros", - type: "AssertionFailureMacro" -) - -@available(*, deprecated, message: "Use #print or #printError instead") -public func print(_ items: Any..., separator: String = " ", terminator: String = "\n") { - Swift.print(items, separator: separator, terminator: terminator) -} - -@available(*, deprecated, message: "Use #assert instead") -public func assert(_ condition: @autoclosure () -> Bool, _ message: @autoclosure () -> String = String(), file: StaticString = #file, line: UInt = #line) { - Swift.assert(condition(), message(), file: file, line: line) -} - -@available(*, deprecated, message: "Use #assertionFailure instead") -public func assertionFailure(_ message: @autoclosure () -> String = String(), file: StaticString = #file, line: UInt = #line) { - Swift.assertionFailure(message(), file: file, line: line) -} diff --git a/Sources/UBFoundation/Logging/UBNonFatalErrorReporter.swift b/Sources/UBFoundation/Logging/UBNonFatalErrorReporter.swift index f3d54226..c059e5db 100644 --- a/Sources/UBFoundation/Logging/UBNonFatalErrorReporter.swift +++ b/Sources/UBFoundation/Logging/UBNonFatalErrorReporter.swift @@ -18,7 +18,7 @@ public actor UBNonFatalErrorReporter { self.handler = handler } - nonisolated func report(_ error: Error) { + public nonisolated func report(_ error: Error) { Task { await _report(error) } diff --git a/Sources/UBFoundation/Networking/AutoRefreshCacheLogic.swift b/Sources/UBFoundation/Networking/AutoRefreshCacheLogic.swift index fc226e97..19c1be8d 100644 --- a/Sources/UBFoundation/Networking/AutoRefreshCacheLogic.swift +++ b/Sources/UBFoundation/Networking/AutoRefreshCacheLogic.swift @@ -8,10 +8,6 @@ import Foundation import OSLog -private enum Log { - static let logger = Logger(subsystem: "UBKit", category: "AutoRefreshCacheLogic") -} - /// A caching logic that will launch and refresh the data automatically when the data expires open class UBAutoRefreshCacheLogic: UBBaseCachingLogic, @unchecked Sendable { /// The refresh cron jobs @@ -31,18 +27,18 @@ open class UBAutoRefreshCacheLogic: UBBaseCachingLogic, @unchecked Sendable { cancelRefreshCronJob(for: task) guard let nextRefreshDate = cachedResponseNextRefreshDate(headers, metrics: metrics, referenceDate: referenceDate) else { - Log.logger.trace("No refresh date for task \(task)") + Log.trace("No refresh date for task \(task)") return } - Log.logger.trace("Schedule refresh for \(task) at \(nextRefreshDate) (\(round(nextRefreshDate.timeIntervalSinceNow))s)") + Log.trace("Schedule refresh for \(task) at \(nextRefreshDate) (\(round(nextRefreshDate.timeIntervalSinceNow))s)") // Schedule a new job let job = UBCronJob(fireAt: nextRefreshDate, qos: qos) { [weak task] in if let task { - Log.logger.trace("Start cron refresh for task \(task)") + Log.trace("Start cron refresh for task \(task)") } else { - Log.logger.trace("Not start cron refresh, task doesn't exist anymore.") + Log.trace("Not start cron refresh, task doesn't exist anymore.") } task?.start(flags: [.systemTriggered, .refresh]) } diff --git a/Sources/UBFoundation/Networking/UBURLDataTask.swift b/Sources/UBFoundation/Networking/UBURLDataTask.swift index de48b1f1..d9daa6c5 100644 --- a/Sources/UBFoundation/Networking/UBURLDataTask.swift +++ b/Sources/UBFoundation/Networking/UBURLDataTask.swift @@ -469,7 +469,7 @@ public final class UBURLDataTask: UBURLSessionTask, CustomStringConvertible, Cus break default: let errorMessage = "Invalid state transition from \(_state) -> \(newValue)" - #assertionFailure(errorMessage) + assertionFailure(errorMessage) UBNonFatalErrorReporter.shared.report(NSError(domain: "UBURLDataTask", code: 0, userInfo: [NSLocalizedDescriptionKey: errorMessage])) } } diff --git a/Sources/UBFoundation/Networking/UBURLSession+Delegate.swift b/Sources/UBFoundation/Networking/UBURLSession+Delegate.swift index 0226efcb..f2083e8e 100644 --- a/Sources/UBFoundation/Networking/UBURLSession+Delegate.swift +++ b/Sources/UBFoundation/Networking/UBURLSession+Delegate.swift @@ -58,7 +58,7 @@ final class UBURLSessionDelegate: NSObject, URLSessionTaskDelegate, URLSessionDa /// :nodoc: func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) { urlSessionQueue.sync { - #assert(session == self._urlSession, "The sessions are not matching") + assert(session == self._urlSession, "The sessions are not matching") } var _ubDataTask: UBURLDataTask? @@ -162,7 +162,7 @@ final class UBURLSessionDelegate: NSObject, URLSessionTaskDelegate, URLSessionDa /// :nodoc: func urlSession(_ session: URLSession, task: URLSessionTask, didFinishCollecting metrics: URLSessionTaskMetrics) { urlSessionQueue.sync { - #assert(session == self._urlSession, "The sessions are not matching") + assert(session == self._urlSession, "The sessions are not matching") } var _collectedData: UBURLSessionDelegate.DataHolder? @@ -179,7 +179,7 @@ final class UBURLSessionDelegate: NSObject, URLSessionTaskDelegate, URLSessionDa /// :nodoc: func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive response: URLResponse, completionHandler: @escaping (URLSession.ResponseDisposition) -> Void) { urlSessionQueue.sync { - #assert(session == self._urlSession, "The sessions are not matching") + assert(session == self._urlSession, "The sessions are not matching") } var _ubDataTask: UBURLDataTask? @@ -214,7 +214,7 @@ final class UBURLSessionDelegate: NSObject, URLSessionTaskDelegate, URLSessionDa /// :nodoc: func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive data: Data) { urlSessionQueue.sync { - #assert(session == self._urlSession, "The sessions are not matching") + assert(session == self._urlSession, "The sessions are not matching") } var _ubDataTask: UBURLDataTask? @@ -237,7 +237,7 @@ final class UBURLSessionDelegate: NSObject, URLSessionTaskDelegate, URLSessionDa /// :nodoc: func urlSession(_ session: URLSession, dataTask _: URLSessionDataTask, willCacheResponse proposedResponse: CachedURLResponse, completionHandler: @escaping (CachedURLResponse?) -> Void) { urlSessionQueue.sync { - #assert(session == self._urlSession, "The sessions are not matching") + assert(session == self._urlSession, "The sessions are not matching") } guard cachingLogic == nil else { // If we have a caching logic, we will skip the default caching implementation @@ -251,7 +251,7 @@ final class UBURLSessionDelegate: NSObject, URLSessionTaskDelegate, URLSessionDa /// :nodoc: func urlSession(_ session: URLSession, task: URLSessionTask, willPerformHTTPRedirection response: HTTPURLResponse, newRequest request: URLRequest, completionHandler: @escaping (URLRequest?) -> Void) { urlSessionQueue.sync { - #assert(session == self._urlSession, "The sessions are not matching") + assert(session == self._urlSession, "The sessions are not matching") } var _ubDataTask: UBURLDataTask? @@ -283,7 +283,7 @@ final class UBURLSessionDelegate: NSObject, URLSessionTaskDelegate, URLSessionDa /// :nodoc: func urlSession(_ session: URLSession, task: URLSessionTask, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) { urlSessionQueue.sync { - #assert(session == self._urlSession, "The sessions are not matching") + assert(session == self._urlSession, "The sessions are not matching") } var _ubDataTask: UBURLDataTask? diff --git a/Sources/UBFoundation/Networking/UBURLSession+ServerTrustEvaluation.swift b/Sources/UBFoundation/Networking/UBURLSession+ServerTrustEvaluation.swift index 3450ef5d..2c5cc529 100644 --- a/Sources/UBFoundation/Networking/UBURLSession+ServerTrustEvaluation.swift +++ b/Sources/UBFoundation/Networking/UBURLSession+ServerTrustEvaluation.swift @@ -100,7 +100,7 @@ public final class UBPinnedCertificatesTrustEvaluator: UBServerTrustEvaluator { /// :nodoc: public func evaluate(_ trust: SecTrust, forHost host: String) throws { - #assert(certificates.isEmpty == false, "This should not have happened as we make sure to crash if there are no certificates found during initialization.") + assert(certificates.isEmpty == false, "This should not have happened as we make sure to crash if there are no certificates found during initialization.") if acceptSelfSignedCertificates { try trust.setAnchorCertificates(certificates) diff --git a/Sources/UBLocation/UBLocationManager.swift b/Sources/UBLocation/UBLocationManager.swift index 8d38f8d2..ebc2fc40 100644 --- a/Sources/UBLocation/UBLocationManager.swift +++ b/Sources/UBLocation/UBLocationManager.swift @@ -384,7 +384,7 @@ public class UBLocationManager: NSObject { self.startLocationMonitoringForAllDelegates() - #assert(!delegateWrappers.isEmpty || allUsages == []) + assert(!delegateWrappers.isEmpty || allUsages == []) } /// Stops monitoring all location service events diff --git a/Sources/UBMacros/CustomError.swift b/Sources/UBMacros/CustomError.swift deleted file mode 100644 index 4e411364..00000000 --- a/Sources/UBMacros/CustomError.swift +++ /dev/null @@ -1,19 +0,0 @@ -// -// CustomError.swift -// UBKit -// -// Created by Nicolas Märki on 12.09.2024. -// - -import Foundation - -enum CustomError: Error, CustomStringConvertible { - case message(String) - - var description: String { - switch self { - case let .message(text): - text - } - } -} diff --git a/Sources/UBMacros/PrintMacro.swift b/Sources/UBMacros/PrintMacro.swift deleted file mode 100644 index 8f8f4c95..00000000 --- a/Sources/UBMacros/PrintMacro.swift +++ /dev/null @@ -1,59 +0,0 @@ -// -// PrintMacro.swift -// UBKit -// -// Created by Nicolas Märki on 12.09.2024. -// - -import Foundation -import os -import SwiftParser -import SwiftSyntax -import SwiftSyntaxBuilder -import SwiftSyntaxMacros - -public struct PrintMacro: ExpressionMacro { - public static func expansion(of node: some FreestandingMacroExpansionSyntax, in context: some MacroExpansionContext) throws -> ExprSyntax { -#if DEBUG - guard node.argumentList.count == 1, let firstArgument = node.argumentList.first?.expression else { - throw CustomError.message("Expected a single argument for #print") - } - return "_PrintMacro.Logger.debug(\(firstArgument))" -#else - return "_PrintMacro.noop()" -#endif - } -} - -public struct PrintErrorMacro: ExpressionMacro { - public static func expansion(of node: some FreestandingMacroExpansionSyntax, in context: some MacroExpansionContext) throws -> ExprSyntax { - guard node.argumentList.count == 1, let firstArgument = node.argumentList.first?.expression else { - throw CustomError.message("Expected a single argument for #printError") - } - return "_PrintMacro.Logger.critical(\"\\(_PrintMacro.sendError(\(firstArgument)))\")" - } -} - -public struct AssertMacro: ExpressionMacro { - public static func expansion(of node: some FreestandingMacroExpansionSyntax, in context: some MacroExpansionContext) throws -> ExprSyntax { - guard let firstArgument = node.argumentList.first?.expression - else { - throw CustomError.message("Expected at least one argument for #assert") - } - if node.argumentList.count > 1, let secondArgument = node.argumentList.last?.expression { - return "_PrintMacro.assert(\(firstArgument),\n{ _PrintMacro.Logger.critical(\"\\(_PrintMacro.sendError(\"Assertion failed:\" + \(secondArgument)))\") })" - } else { - return "_PrintMacro.assert(\(firstArgument),\n{ _PrintMacro.Logger.critical(\"\\(_PrintMacro.sendError(\"Assertion failed.\"))\") })" - } - } -} - -public struct AssertionFailureMacro: ExpressionMacro { - public static func expansion(of node: some FreestandingMacroExpansionSyntax, in context: some MacroExpansionContext) throws -> ExprSyntax { - if let firstArgument = node.argumentList.first?.expression { - "_PrintMacro.assertionFailure({ _PrintMacro.Logger.critical(\"\\(_PrintMacro.sendError(\"Assertion failed:\" + \(firstArgument)))\") })" - } else { - "_PrintMacro.assertionFailure({ _PrintMacro.Logger.critical(\"\\(_PrintMacro.sendError(\"Assertion failed.\"))\") })" - } - } -} diff --git a/Sources/UBMacros/UBMacroPlugin.swift b/Sources/UBMacros/UBMacroPlugin.swift deleted file mode 100644 index 6ffdb770..00000000 --- a/Sources/UBMacros/UBMacroPlugin.swift +++ /dev/null @@ -1,21 +0,0 @@ -// -// UBMacroPlugin.swift -// -// -// Created by Matthias Felix on 20.09.2023. -// - -import Foundation -import SwiftCompilerPlugin -import SwiftSyntaxMacros - -@main -struct UBMacroPlugin: CompilerPlugin { - let providingMacros: [Macro.Type] = [ - URLMacro.self, - PrintMacro.self, - PrintErrorMacro.self, - AssertMacro.self, - AssertionFailureMacro.self, - ] -} diff --git a/Sources/UBMacros/URLMacro.swift b/Sources/UBMacros/URLMacro.swift deleted file mode 100644 index 28cf2959..00000000 --- a/Sources/UBMacros/URLMacro.swift +++ /dev/null @@ -1,28 +0,0 @@ -// -// URLMacro.swift -// -// -// Created by Matthias Felix on 20.09.2023. -// - -import Foundation -import SwiftSyntax -import SwiftSyntaxBuilder -import SwiftSyntaxMacros - -public struct URLMacro: ExpressionMacro { - public static func expansion(of node: some FreestandingMacroExpansionSyntax, in context: some MacroExpansionContext) throws -> ExprSyntax { - guard let argument = node.argumentList.first?.expression, - let segments = argument.as(StringLiteralExprSyntax.self)?.segments, - segments.count == 1, - case let .stringSegment(literalSegment) = segments.first else { - throw CustomError.message("#URL requires a static string literal") - } - - guard let _ = URL(string: literalSegment.content.text) else { - throw CustomError.message("Malformed url: \(argument)") - } - - return "URL(string: \(argument))!" - } -} diff --git a/Sources/UBPush/UBPushManager.swift b/Sources/UBPush/UBPushManager.swift index 525e7663..fb3f35c1 100644 --- a/Sources/UBPush/UBPushManager.swift +++ b/Sources/UBPush/UBPushManager.swift @@ -289,7 +289,7 @@ open class UBPushManager: NSObject { } } } - + /// Querys the current push permissions from the system public func queryPushPermissions() async -> Bool { let settings = await UNUserNotificationCenter.current().notificationSettings() diff --git a/Sources/UBQRScanner/QRScannerError.swift b/Sources/UBQRScanner/QRScannerError.swift index 5c30dcaf..856295a5 100644 --- a/Sources/UBQRScanner/QRScannerError.swift +++ b/Sources/UBQRScanner/QRScannerError.swift @@ -16,18 +16,18 @@ public enum QRScannerError: Error { } extension QRScannerError: Equatable { - public static func == (lhs: QRScannerError, rhs: QRScannerError) -> Bool { - switch (lhs, rhs) { - case (.cameraPermissionDenied, .cameraPermissionDenied): - return true - case (.cameraPermissionRestricted, .cameraPermissionRestricted): - return true - case (.captureSessionError(let lhsError), .captureSessionError(let rhsError)): - return lhsError?.localizedDescription == rhsError?.localizedDescription - case (.torchError(let lhsError), .torchError(let rhsError)): - return lhsError?.localizedDescription == rhsError?.localizedDescription - default: - return false - } - } + public static func == (lhs: QRScannerError, rhs: QRScannerError) -> Bool { + switch (lhs, rhs) { + case (.cameraPermissionDenied, .cameraPermissionDenied): + true + case (.cameraPermissionRestricted, .cameraPermissionRestricted): + true + case let (.captureSessionError(lhsError), .captureSessionError(rhsError)): + lhsError?.localizedDescription == rhsError?.localizedDescription + case let (.torchError(lhsError), .torchError(rhsError)): + lhsError?.localizedDescription == rhsError?.localizedDescription + default: + false + } + } } diff --git a/Tests/UBFoundationTests/Logging/MacroTests.swift b/Tests/UBFoundationTests/Logging/LoggerTests.swift similarity index 62% rename from Tests/UBFoundationTests/Logging/MacroTests.swift rename to Tests/UBFoundationTests/Logging/LoggerTests.swift index c52b9546..58d6710d 100644 --- a/Tests/UBFoundationTests/Logging/MacroTests.swift +++ b/Tests/UBFoundationTests/Logging/LoggerTests.swift @@ -1,5 +1,5 @@ // -// MacroTests.swift +// LoggerTests.swift // UBKit // // Created by Nicolas Märki on 12.09.2024. @@ -9,12 +9,15 @@ import UBFoundation import XCTest @available(iOS 14.0, *) -class MacroTests: XCTestCase { +class LoggerTests: XCTestCase { func testMacro() { - #print("\(52.0)") + Log.debug("\(52.0)") let variable = "test" - #print("Test = \(variable, privacy: .public)") + let variable2 = "test2" + Log.debug( + "Test = \(variable, privacy: .public), ? = \(variable2, privacy: .private)" + ) } func testError() async { @@ -23,14 +26,14 @@ class MacroTests: XCTestCase { exp.fulfill() } - #printError("Failed to not fail") + Log.reportError("Failed to not fail") await fulfillment(of: [exp]) } func testAssertTrue() { - #assert(true, "Test") - #assert(true) + assert(true, "Test") + assert(true) } func testAssertFalse() async { @@ -38,8 +41,9 @@ class MacroTests: XCTestCase { await UBNonFatalErrorReporter.shared.setHandler { _ in exp.fulfill() } - _PrintMacro.disableAssertionFailure = true - #assert(false, "Test") + // swiftformat:disable all + assert(false, "Test", swiftAssertionFailure: false) + // swiftformat:enable all await fulfillment(of: [exp]) } @@ -51,10 +55,8 @@ class MacroTests: XCTestCase { exp.fulfill() } - _PrintMacro.disableAssertionFailure = true - - #assertionFailure("Failed") - #assertionFailure() + assertionFailure("Failed", swiftAssertionFailure: false) + assertionFailure(swiftAssertionFailure: false) await fulfillment(of: [exp]) }