diff --git a/Sources/PodExtractor/Module+Podfile.swift b/Sources/PodExtractor/Module+Podfile.swift index 3bccf9a..bf5635e 100644 --- a/Sources/PodExtractor/Module+Podfile.swift +++ b/Sources/PodExtractor/Module+Podfile.swift @@ -117,19 +117,16 @@ public func extractModulesFromPodfileLock(_ contents: String, excludeExternals: private func extractPodFromJSON(_ json: Any) throws -> Module { if let name = json as? String { - return try .init(name: clean(name), dependencies: []) + return try .init(name: clean(name), dependencies: [], type: type(name)) } else if let container = json as? [String: [String]], let name = container.keys.first, let dependencies = container.values.first { - let podComponents = name.components(separatedBy: "/") - let podType: Module.ModuleType = podComponents.count > 1 && podComponents[1].contains("Tests") ? .test : .library - return try .init( name: clean(name), dependencies: dependencies.map(clean), - type: podType + type: type(name) ) } else { @@ -137,6 +134,16 @@ private func extractPodFromJSON(_ json: Any) throws -> Module { } } +private func type(_ name: String) -> Module.ModuleType { + let podComponents = name.components(separatedBy: "/") + + guard podComponents.count > 1 else { + return .library + } + + return podComponents[1].contains("Tests") ? .test : .library +} + private func clean(_ name: String) throws -> String { guard let cleanName = name.split(separator: " ").first else { throw PodError.failedParsingPodName diff --git a/Sources/jungle/Commands/Main.swift b/Sources/jungle/Commands/Main.swift index 098a1a7..2c1ba36 100644 --- a/Sources/jungle/Commands/Main.swift +++ b/Sources/jungle/Commands/Main.swift @@ -5,7 +5,7 @@ struct Jungle: AsyncParsableCommand { static var configuration = CommandConfiguration( commandName: "jungle", abstract: "SwiftPM and Cocoapods based projects complexity analyzer.", - version: "2.2.0", + version: "2.2.1", subcommands: [HistoryCommand.self, CompareCommand.self, GraphCommand.self, ModulesCommand.self, DependantCommand.self], defaultSubcommand: CompareCommand.self ) diff --git a/Tests/PodExtractorTests/PodExtractorTests.swift b/Tests/PodExtractorTests/PodExtractorTests.swift index 87bc469..9b4f57f 100644 --- a/Tests/PodExtractorTests/PodExtractorTests.swift +++ b/Tests/PodExtractorTests/PodExtractorTests.swift @@ -28,6 +28,23 @@ final class PodExtractorTests: XCTestCase { XCTAssertEqual(modules.count, 1) } + + func testExtractModulesNotIgnoringTests() throws { + let podfile = """ + PODS: + - A (1.0.0) + - B (1.0.0) + - B/Tests (1.0.0) + """ + + let modules = try extractModulesFromPodfileLock(podfile, excludeTests: false) + + let libraries = modules.filter({ $0.type == .library }) + let tests = modules.filter({ $0.type == .test }) + + XCTAssertEqual(libraries.count, 2) + XCTAssertEqual(tests.count, 1) + } func testExtractModulesIgnoresExternals() throws { let podfile = """