From d55ea3b4fbd264cdd0ae3b3c625ee9fd44d25ef6 Mon Sep 17 00:00:00 2001 From: minsOne Date: Thu, 14 Mar 2024 15:54:09 +0900 Subject: [PATCH] =?UTF-8?q?MacroKitClient=20=ED=83=80=EA=B2=9F=20=EC=9D=B4?= =?UTF-8?q?=EB=A6=84=EC=9D=84=20MacroPlayground=EB=A1=9C=20=EC=9D=B4?= =?UTF-8?q?=EB=A6=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Package.swift | 8 ++++---- .../{MacroKitClient => Playground}/main.swift | 17 +++++++++++++++++ .../Expression/LoggingExpressionMacros.swift | 12 ++++-------- 3 files changed, 25 insertions(+), 12 deletions(-) rename Sources/{MacroKitClient => Playground}/main.swift (51%) diff --git a/Package.swift b/Package.swift index 41801c5..742b8d6 100644 --- a/Package.swift +++ b/Package.swift @@ -14,13 +14,13 @@ let package = Package( targets: ["MacroKit"] ), .executable( - name: "MacroKitClient", - targets: ["MacroKitClient"] + name: "MacroPlayground", + targets: ["MacroPlayground"] ), ], dependencies: [ // Depend on the Swift 5.9 release of SwiftSyntax - .package(url: "https://github.com/apple/swift-syntax.git", from: "509.0.0"), + .package(url: "https://github.com/apple/swift-syntax.git", from: "510.0.1"), ], targets: [ // Targets are the basic building blocks of a package, defining a module or a test suite. @@ -37,7 +37,7 @@ let package = Package( .target(name: "MacroKit", dependencies: ["Macros"]), // A client of the library, which is able to use the macro in its own code. - .executableTarget(name: "MacroKitClient", dependencies: ["MacroKit"]), + .executableTarget(name: "MacroPlayground", dependencies: ["MacroKit"], path: "Sources/Playground"), // A test target used to develop the macro implementation. .testTarget( diff --git a/Sources/MacroKitClient/main.swift b/Sources/Playground/main.swift similarity index 51% rename from Sources/MacroKitClient/main.swift rename to Sources/Playground/main.swift index 856252c..f9f35f5 100644 --- a/Sources/MacroKitClient/main.swift +++ b/Sources/Playground/main.swift @@ -32,8 +32,25 @@ print("cat is \(cat.isCat)") @Logging class LogModel { func log() { + Logger(logger).trace("log messsage") + os_log(.info, log: logger, "log messsage") + #log(level: .info, "log messsage") #log(level: .debug, "log messsage") + #log(level: .error, "log messsage") } } LogModel().log() + +struct MyStruct { + @AddAsync + func c(a: Int, for b: String, _ value: Double, completionBlock: @escaping (Result) -> Void) -> Void { + completionBlock(.success("a: \(a), b: \(b), value: \(value)")) + } + + @AddAsync + func d(a: Int, for b: String, _ value: Double, completionBlock: @escaping (Bool) -> Void) -> Void { + completionBlock(true) + } +} + diff --git a/Tests/MacroKitTests/Expression/LoggingExpressionMacros.swift b/Tests/MacroKitTests/Expression/LoggingExpressionMacros.swift index 39883c8..84060a8 100644 --- a/Tests/MacroKitTests/Expression/LoggingExpressionMacros.swift +++ b/Tests/MacroKitTests/Expression/LoggingExpressionMacros.swift @@ -11,15 +11,11 @@ final class LoggingExpressionMacrosTests: XCTestCase { """#, expandedSource: #""" { - #if os(iOS) - if #available (iOS 14.0, *) { - Logger(logger).log(level: .debug, "message") - } else { - os_log(.debug, log: logger, "message") - } - #else + if #available (iOS 14.0, macOS 11.0, watchOS 7.0, tvOS 14.0, *) { + Logger(logger).log(level: .debug, "message") + } else { os_log(.debug, log: logger, "message") - #endif + } }() """#, macros: ["log": LoggingExpressionMacros.self]