From d5f08f5e03bfc25f88adbe5bcab684ad2f25b45c Mon Sep 17 00:00:00 2001 From: unicov Date: Wed, 28 Apr 2021 22:12:04 -0700 Subject: [PATCH 1/4] Rename/move files --- Sources/Mockolo/Executor.swift | 10 +--- Sources/Mockolo/main.swift | 1 + .../Operations/Generator.swift | 2 +- ...iaSwiftSyntax.swift => SourceParser.swift} | 21 ++++++-- .../Parsers/SourceParsing.swift | 49 ------------------- .../SwiftSyntaxExtensions.swift | 0 Sources/MockoloFramework/Version.swift | 7 +++ Tests/MockoloTestCase.swift | 2 +- 8 files changed, 29 insertions(+), 63 deletions(-) rename Sources/MockoloFramework/Parsers/{ViaSwiftSyntax/ParserViaSwiftSyntax.swift => SourceParser.swift} (81%) delete mode 100644 Sources/MockoloFramework/Parsers/SourceParsing.swift rename Sources/MockoloFramework/Parsers/{ViaSwiftSyntax => }/SwiftSyntaxExtensions.swift (100%) create mode 100644 Sources/MockoloFramework/Version.swift diff --git a/Sources/Mockolo/Executor.swift b/Sources/Mockolo/Executor.swift index f80b38c3..95dee040 100644 --- a/Sources/Mockolo/Executor.swift +++ b/Sources/Mockolo/Executor.swift @@ -206,7 +206,7 @@ class Executor { do { try generate(sourceDirs: srcDirs, sourceFiles: srcs, - parser: ParserViaSwiftSyntax(), + parser: SourceParser(), exclusionSuffixes: exclusionSuffixes, mockFilePaths: mockFilePaths, annotation: annotation, @@ -233,11 +233,3 @@ class Executor { } } } - -public struct Version { - /// The string value for this version. - public let value: String - - /// The current Mockolo version. - public static let current = Version(value: "1.3.2") -} diff --git a/Sources/Mockolo/main.swift b/Sources/Mockolo/main.swift index 960dda9f..c65871eb 100644 --- a/Sources/Mockolo/main.swift +++ b/Sources/Mockolo/main.swift @@ -16,6 +16,7 @@ import Foundation import TSCUtility import TSCBasic +import MockoloFramework func main() { let parser = ArgumentParser(usage: "", overview: "Mockolo: Swift mock generator.") diff --git a/Sources/MockoloFramework/Operations/Generator.swift b/Sources/MockoloFramework/Operations/Generator.swift index 80cc1e8e..d0a7ebd7 100644 --- a/Sources/MockoloFramework/Operations/Generator.swift +++ b/Sources/MockoloFramework/Operations/Generator.swift @@ -24,7 +24,7 @@ enum InputError: Error { /// Performs end to end mock generation flow public func generate(sourceDirs: [String]?, sourceFiles: [String]?, - parser: SourceParsing, + parser: SourceParser, exclusionSuffixes: [String], mockFilePaths: [String]?, annotation: String, diff --git a/Sources/MockoloFramework/Parsers/ViaSwiftSyntax/ParserViaSwiftSyntax.swift b/Sources/MockoloFramework/Parsers/SourceParser.swift similarity index 81% rename from Sources/MockoloFramework/Parsers/ViaSwiftSyntax/ParserViaSwiftSyntax.swift rename to Sources/MockoloFramework/Parsers/SourceParser.swift index 3626e8d7..04c240ad 100644 --- a/Sources/MockoloFramework/Parsers/ViaSwiftSyntax/ParserViaSwiftSyntax.swift +++ b/Sources/MockoloFramework/Parsers/SourceParser.swift @@ -17,9 +17,17 @@ import Foundation import SwiftSyntax -public class ParserViaSwiftSyntax: SourceParsing { + +public enum DeclType { + case protocolType, classType, other, all +} + +public class SourceParser { public init() {} - + /// Parses processed decls (mock classes) and calls a completion block + /// @param paths File paths containing processed mocks + /// @param fileMacro: File level macro + /// @param completion:The block to be executed on completion public func parseProcessedDecls(_ paths: [String], fileMacro: String?, completion: @escaping ([Entity], ImportMap?) -> ()) { @@ -27,7 +35,14 @@ public class ParserViaSwiftSyntax: SourceParsing { self.generateASTs(path, annotation: "", fileMacro: fileMacro, declType: .classType, lock: lock, completion: completion) } } - + /// Parses decls (protocol, class) with annotations (/// @mockable) and calls a completion block + /// @param paths File/dir paths containing types with mock annotation + /// @param isDirs:True if paths are dir paths + /// @param exclusionSuffixess List of file suffixes to exclude when processing + /// @param annotation The mock annotation + /// @param fileMacro: File level macro + /// @param declType: The declaration type, e.g. protocol, class. + /// @param completion:The block to be executed on completion public func parseDecls(_ paths: [String]?, isDirs: Bool, exclusionSuffixes: [String]? = nil, diff --git a/Sources/MockoloFramework/Parsers/SourceParsing.swift b/Sources/MockoloFramework/Parsers/SourceParsing.swift deleted file mode 100644 index 019ee307..00000000 --- a/Sources/MockoloFramework/Parsers/SourceParsing.swift +++ /dev/null @@ -1,49 +0,0 @@ - -// -// Copyright (c) 2018. Uber Technologies -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -import Foundation - -public enum DeclType { - case protocolType, classType, other, all -} - -public protocol SourceParsing { - - /// Parses processed decls (mock classes) and calls a completion block - /// @param paths File paths containing processed mocks - /// @param fileMacro: File level macro - /// @param completion:The block to be executed on completion - func parseProcessedDecls(_ paths: [String], - fileMacro: String?, - completion: @escaping ([Entity], ImportMap?) -> ()) - - /// Parses decls (protocol, class) with annotations (/// @mockable) and calls a completion block - /// @param paths File/dir paths containing types with mock annotation - /// @param isDirs:True if paths are dir paths - /// @param exclusionSuffixess List of file suffixes to exclude when processing - /// @param annotation The mock annotation - /// @param fileMacro: File level macro - /// @param declType: The declaration type, e.g. protocol, class. - /// @param completion:The block to be executed on completion - func parseDecls(_ paths: [String]?, - isDirs: Bool, - exclusionSuffixes: [String]?, - annotation: String, - fileMacro: String?, - declType: DeclType, - completion: @escaping ([Entity], ImportMap?) -> ()) -} diff --git a/Sources/MockoloFramework/Parsers/ViaSwiftSyntax/SwiftSyntaxExtensions.swift b/Sources/MockoloFramework/Parsers/SwiftSyntaxExtensions.swift similarity index 100% rename from Sources/MockoloFramework/Parsers/ViaSwiftSyntax/SwiftSyntaxExtensions.swift rename to Sources/MockoloFramework/Parsers/SwiftSyntaxExtensions.swift diff --git a/Sources/MockoloFramework/Version.swift b/Sources/MockoloFramework/Version.swift new file mode 100644 index 00000000..ca8e14f0 --- /dev/null +++ b/Sources/MockoloFramework/Version.swift @@ -0,0 +1,7 @@ +public struct Version { + /// The string value for this version. + public let value: String + + /// The current Mockolo version. + public static let current = Version(value: "1.3.2") +} diff --git a/Tests/MockoloTestCase.swift b/Tests/MockoloTestCase.swift index 5db4ce5f..d76aec26 100644 --- a/Tests/MockoloTestCase.swift +++ b/Tests/MockoloTestCase.swift @@ -108,7 +108,7 @@ class MockoloTestCase: XCTestCase { try? generate(sourceDirs: nil, sourceFiles: srcFilePaths, - parser: ParserViaSwiftSyntax(), + parser: SourceParser(), exclusionSuffixes: ["Mocks", "Tests"], mockFilePaths: mockFilePaths, annotation: String.mockAnnotation, From d90290c9f371b7c68d6284641b30e904ed8b5c75 Mon Sep 17 00:00:00 2001 From: unicov Date: Wed, 28 Apr 2021 22:53:17 -0700 Subject: [PATCH 2/4] Add github workflow for build actions --- .github/workflows/builds.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .github/workflows/builds.yml diff --git a/.github/workflows/builds.yml b/.github/workflows/builds.yml new file mode 100644 index 00000000..50fcd19b --- /dev/null +++ b/.github/workflows/builds.yml @@ -0,0 +1,17 @@ +name: Build Actions +on: + push: + branches: [master] + pull_request: + branches: [master] +jobs: + macos: + runs-on: macOS-latest + steps: + - name: Checkout + uses: actions/checkout@v1 + - name: Build + run: swift build -v + - name: Test + run: swift test -v -c release + From 1b630935c2c2d92501e786121c9e6b6ba22f9117 Mon Sep 17 00:00:00 2001 From: unicov Date: Wed, 28 Apr 2021 22:54:36 -0700 Subject: [PATCH 3/4] Remove travis --- .travis.yml | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 1e200caa..00000000 --- a/.travis.yml +++ /dev/null @@ -1,8 +0,0 @@ -language: swift -osx_image: xcode12.2 -matrix: - include: - - name: "MockoloTests" - script: swift test -Xswiftc -DDEBUG - - name: "MockoloBinary" - script: swift build -c release From 5ca5bb60a788cfd86f4499eb2aead8a5a74e6188 Mon Sep 17 00:00:00 2001 From: unicov Date: Wed, 28 Apr 2021 22:57:04 -0700 Subject: [PATCH 4/4] Update version 1.4.0 --- Sources/MockoloFramework/Version.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/MockoloFramework/Version.swift b/Sources/MockoloFramework/Version.swift index ca8e14f0..ad7f22c4 100644 --- a/Sources/MockoloFramework/Version.swift +++ b/Sources/MockoloFramework/Version.swift @@ -3,5 +3,5 @@ public struct Version { public let value: String /// The current Mockolo version. - public static let current = Version(value: "1.3.2") + public static let current = Version(value: "1.4.0") }