Skip to content

Commit b7863da

Browse files
authored
Merge pull request Carthage#1371 from Carthage/test-for-1366
Add a test for Carthage#1366
2 parents e751f2f + 9c264c3 commit b7863da

File tree

4 files changed

+56
-31
lines changed

4 files changed

+56
-31
lines changed

Source/CarthageKitTests/ProjectSpec.swift

Lines changed: 55 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,44 +15,69 @@ import Tentacle
1515

1616
class ProjectSpec: QuickSpec {
1717
override func spec() {
18-
let directoryURL = NSBundle(forClass: self.dynamicType).URLForResource("CartfilePrivateOnly", withExtension: nil)!
18+
describe("loadCombinedCartfile") {
19+
it("should load a combined Cartfile when only a Cartfile is present") {
20+
let directoryURL = NSBundle(forClass: self.dynamicType).URLForResource("CartfileOnly", withExtension: nil)!
21+
let result = Project(directoryURL: directoryURL).loadCombinedCartfile().single()
22+
expect(result).notTo(beNil())
23+
expect(result?.value).notTo(beNil())
24+
25+
let dependencies = result?.value?.dependencies
26+
expect(dependencies?.count) == 1
27+
expect(dependencies?.first?.project.name) == "Carthage"
28+
}
1929

20-
it("should load a combined Cartfile when only a Cartfile.private is present") {
21-
let result = Project(directoryURL: directoryURL).loadCombinedCartfile().single()
22-
expect(result).notTo(beNil())
23-
expect(result?.value).notTo(beNil())
30+
it("should load a combined Cartfile when only a Cartfile.private is present") {
31+
let directoryURL = NSBundle(forClass: self.dynamicType).URLForResource("CartfilePrivateOnly", withExtension: nil)!
32+
let result = Project(directoryURL: directoryURL).loadCombinedCartfile().single()
33+
expect(result).notTo(beNil())
34+
expect(result?.value).notTo(beNil())
2435

25-
let dependencies = result?.value?.dependencies
26-
expect(dependencies?.count) == 1
27-
expect(dependencies?.first?.project.name) == "Carthage"
28-
}
36+
let dependencies = result?.value?.dependencies
37+
expect(dependencies?.count) == 1
38+
expect(dependencies?.first?.project.name) == "Carthage"
39+
}
2940

30-
it("should detect duplicate dependencies across Cartfile and Cartfile.private") {
31-
let directoryURL = NSBundle(forClass: self.dynamicType).URLForResource("DuplicateDependencies", withExtension: nil)!
32-
let result = Project(directoryURL: directoryURL).loadCombinedCartfile().single()
33-
expect(result).notTo(beNil())
41+
it("should detect duplicate dependencies across Cartfile and Cartfile.private") {
42+
let directoryURL = NSBundle(forClass: self.dynamicType).URLForResource("DuplicateDependencies", withExtension: nil)!
43+
let result = Project(directoryURL: directoryURL).loadCombinedCartfile().single()
44+
expect(result).notTo(beNil())
3445

35-
let resultError = result?.error
36-
expect(resultError).notTo(beNil())
46+
let resultError = result?.error
47+
expect(resultError).notTo(beNil())
3748

38-
let makeDependency: (String, String, [String]) -> DuplicateDependency = { (repoOwner, repoName, locations) in
39-
let project = ProjectIdentifier.GitHub(Repository(owner: repoOwner, name: repoName))
40-
return DuplicateDependency(project: project, locations: locations)
41-
}
49+
let makeDependency: (String, String, [String]) -> DuplicateDependency = { (repoOwner, repoName, locations) in
50+
let project = ProjectIdentifier.GitHub(Repository(owner: repoOwner, name: repoName))
51+
return DuplicateDependency(project: project, locations: locations)
52+
}
4253

43-
let mainLocation = ["\(CarthageProjectCartfilePath)"]
44-
let bothLocations = ["\(CarthageProjectCartfilePath)", "\(CarthageProjectPrivateCartfilePath)"]
54+
let mainLocation = ["\(CarthageProjectCartfilePath)"]
55+
let bothLocations = ["\(CarthageProjectCartfilePath)", "\(CarthageProjectPrivateCartfilePath)"]
4556

46-
let expectedError = CarthageError.DuplicateDependencies([
47-
makeDependency("self2", "self2", mainLocation),
48-
makeDependency("self3", "self3", mainLocation),
49-
makeDependency("1", "1", bothLocations),
50-
makeDependency("3", "3", bothLocations),
51-
makeDependency("5", "5", bothLocations),
52-
])
57+
let expectedError = CarthageError.DuplicateDependencies([
58+
makeDependency("self2", "self2", mainLocation),
59+
makeDependency("self3", "self3", mainLocation),
60+
makeDependency("1", "1", bothLocations),
61+
makeDependency("3", "3", bothLocations),
62+
makeDependency("5", "5", bothLocations),
63+
])
5364

54-
expect(resultError) == expectedError
55-
}
65+
expect(resultError) == expectedError
66+
}
67+
68+
it("should error when neither a Cartfile nor a Cartfile.private exists") {
69+
let directoryURL = NSBundle(forClass: self.dynamicType).URLForResource("NoCartfile", withExtension: nil)!
70+
let result = Project(directoryURL: directoryURL).loadCombinedCartfile().single()
71+
expect(result).notTo(beNil())
72+
73+
if case let .ReadFailed(_, underlyingError)? = result?.error {
74+
expect(underlyingError?.domain) == NSCocoaErrorDomain
75+
expect(underlyingError?.code) == NSFileReadNoSuchFileError
76+
} else {
77+
fail()
78+
}
79+
}
80+
}
5681

5782
describe("cloneOrFetchProject") {
5883
// https://github.com/Carthage/Carthage/issues/1191
336 Bytes
Binary file not shown.
986 Bytes
Binary file not shown.

script/copy-fixtures

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
destination="${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}"
88

9-
for fixture in "ReactiveCocoaLayout" "CartfilePrivateOnly" "SchemeDiscoverySampleForCarthage-0.2" "Swell-0.5.0" "SampleMultipleSubprojects" "SampleGitSubmodule"
9+
for fixture in "ReactiveCocoaLayout" "CartfileOnly" "CartfilePrivateOnly" "NoCartfile" "SchemeDiscoverySampleForCarthage-0.2" "Swell-0.5.0" "SampleMultipleSubprojects" "SampleGitSubmodule"
1010
do
1111
rm -Rf "$destination/$fixture"
1212
unzip -q -d "$destination" "Source/CarthageKitTests/fixtures/$fixture.zip"

0 commit comments

Comments
 (0)