Skip to content

Commit

Permalink
Clean up and test error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonboyle committed Jul 24, 2018
1 parent e1fafd7 commit 9312520
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Carthage.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,8 @@
D0D1211B19E87861005E4BAA /* main.swift */,
F128A7191B463D490044368C /* Outdated.swift */,
D0AAC23F1A14933100060F2E /* Update.swift */,
54911EF21A1D34EC00FFAE5F /* Version.swift */,
F1A39D5120F947D400FA88B6 /* Verify.swift */,
54911EF21A1D34EC00FFAE5F /* Version.swift */,
D026578B1B143BA000E833B5 /* swift-is-crashy.c */,
5499CA981A2394BD00783309 /* Supporting Files */,
);
Expand Down Expand Up @@ -524,10 +524,10 @@
8A239F3A20975762005F02F2 /* BundleExtensions.swift */,
D0D1218F19E88A15005E4BAA /* Cartfile.swift */,
CD43D9D91F41640E00CD60F6 /* CarthageKitVersion.swift */,
F1A39D5320F9AF7600FA88B6 /* CompatibilityInfo.swift */,
A1411ED51EFC1BFD0060461F /* Constants.swift */,
CDD7CF781F75ED88000E0EA5 /* Dependency.swift */,
CDF94D941E71144300200486 /* DuplicateDependency.swift */,
F1A39D5320F9AF7600FA88B6 /* CompatibilityInfo.swift */,
D0AAAB4919FAEDB4007B24B3 /* Errors.swift */,
D074EDC41A049283001DE082 /* FrameworkExtensions.swift */,
88ED56D519ECE34900CBF5C4 /* Git.swift */,
Expand Down
14 changes: 11 additions & 3 deletions Source/CarthageKit/CompatibilityInfo.swift
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
import Foundation

/// Identifies a dependency, its pinned version, and versions of this dependency with which it may or may not be compatible
public struct CompatibilityInfo: Equatable {
public struct CompatibilityInfo {
/// The dependecy
public let dependency: Dependency

/// The pinned version of the dependency
public let pinnedVersion: PinnedVersion

/// Versions of this dependency with which it may or may not be compatible
public let requirements: [Dependency: VersionSpecifier]

/// The versions which are not compatible with the pinned version of this dependency
public var incompatibleRequirements: [Dependency: VersionSpecifier] {
return requirements.filter { _, version in !version.isSatisfied(by: pinnedVersion) }
}
}

extension CompatibilityInfo: Equatable {
public static func == (_ lhs: CompatibilityInfo, _ rhs: CompatibilityInfo) -> Bool {
return lhs.dependency == rhs.dependency &&
lhs.pinnedVersion == rhs.pinnedVersion &&
lhs.requirements == rhs.requirements
}
}
8 changes: 5 additions & 3 deletions Source/CarthageKit/Errors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,11 @@ extension CarthageError: CustomStringConvertible {
case let .invalidResolvedCartfile(incompatibilities):
var message = "The following incompatibilities were found in Cartfile.resolved:\n"
var lines: [String] = []
incompatibilities.forEach { incompatibility in
for (dependency, version) in incompatibility.requirements {
lines.append("* \(incompatibility.dependency.name) is incompatible with \(dependency.name) \(version)")
let sortedIncompatibilities = incompatibilities.sorted(by: { $0.dependency.name < $1.dependency.name })
sortedIncompatibilities.forEach { incompatibility in
let sortedRequirements = incompatibility.incompatibleRequirements.sorted(by: { $0.0.name < $1.0.name })
for (dependency, version) in sortedRequirements {
lines.append("* \(incompatibility.dependency.name) \(incompatibility.pinnedVersion) is incompatible with \(dependency.name) \(version)")
}
}
message += lines.joined(separator: "\n")
Expand Down
19 changes: 14 additions & 5 deletions Tests/CarthageKitTests/VerifySpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class VerifySpec: QuickSpec {
let yapDatabaseDependency = Dependency.gitHub(.dotCom, Repository(owner: "yapstudios", name: "YapDatabase"))
let cocoaLumberjackDependency = Dependency.gitHub(.dotCom, Repository(owner: "CocoaLumberjack", name: "CocoaLumberjack"))

describe("transitiveDependenciesAndVersionsByParent") {
describe("requirementsByDependency") {
it("should group dependencies by parent dependency") {
let resolvedCartfile = ResolvedCartfile.from(string: validCartfile)
let project = Project(directoryURL: URL(string: "file://fake")!)
Expand Down Expand Up @@ -83,18 +83,27 @@ class VerifySpec: QuickSpec {
let resolvedCartfile = ResolvedCartfile.from(string: invalidCartfile)
let project = Project(directoryURL: URL(string: "file://fake")!)

let infos = project.verify(resolvedCartfile: resolvedCartfile.value!).single()?.error?.compatibilityInfos
let error = project.verify(resolvedCartfile: resolvedCartfile.value!).single()?.error
let infos = error?.compatibilityInfos

expect(infos?[0].dependency) == alamofireDependency
expect(infos?[0].pinnedVersion) == PinnedVersion("5.0.0")

expect(infos?[0].requirements.contains(where: { $0 == moya_4_1_0 })) == true
expect(infos?[0].incompatibleRequirements.contains(where: { $0 == moya_4_1_0 })) == true

expect(infos?[1].dependency) == resultDependency
expect(infos?[1].pinnedVersion) == PinnedVersion("4.0.0")

expect(infos?[1].requirements.contains(where: { $0 == moya_3_1_0 })) == true
expect(infos?[1].requirements.contains(where: { $0 == reactiveSwift_3_2_1 })) == true
expect(infos?[1].incompatibleRequirements.contains(where: { $0 == moya_3_1_0 })) == true
expect(infos?[1].incompatibleRequirements.contains(where: { $0 == reactiveSwift_3_2_1 })) == true

expect(error?.description) ==
"""
The following incompatibilities were found in Cartfile.resolved:
* Alamofire "5.0.0" is incompatible with Moya ~> 4.1.0
* Result "4.0.0" is incompatible with Moya ~> 3.1.0
* Result "4.0.0" is incompatible with ReactiveSwift ~> 3.2.1
"""
}
}
}
Expand Down

0 comments on commit 9312520

Please sign in to comment.