Skip to content

Commit

Permalink
fix podextractor for some test targets
Browse files Browse the repository at this point in the history
  • Loading branch information
osrufung committed Mar 20, 2023
1 parent 9713f0f commit 803b14c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
17 changes: 12 additions & 5 deletions Sources/PodExtractor/Module+Podfile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,26 +117,33 @@ 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 {
throw PodError.failedParsingPod(json as? String ?? "")
}
}

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
Expand Down
2 changes: 1 addition & 1 deletion Sources/jungle/Commands/Main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
17 changes: 17 additions & 0 deletions Tests/PodExtractorTests/PodExtractorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """
Expand Down

0 comments on commit 803b14c

Please sign in to comment.