Skip to content

Commit a5c5fde

Browse files
committed
add tests for GitVersionTagRequired in RawClone
1 parent 0d2240e commit a5c5fde

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

Sources/dep/get.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@ extension Sandbox: Fetcher {
149149

150150
init(path: String) throws {
151151
self.path = path
152-
if !repo.hasVersion {
153-
throw Error.GitVersionTagRequired(path)
154-
}
152+
if !repo.hasVersion {
153+
throw Error.GitVersionTagRequired(path)
154+
}
155155
}
156156

157157
var repo: Git.Repo {

Tests/dep/GitTests.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ class GitTests: XCTestCase, XCTestCaseProvider {
2020
return [
2121
("testHasVersion", testHasVersion),
2222
("testHasNoVersion", testHasNoVersion),
23+
("testCloneShouldNotCrashWihoutTags", testCloneShouldNotCrashWihoutTags),
24+
("testCloneShouldCrashWihoutTags", testCloneShouldCrashWihoutTags),
25+
2326
]
2427
}
2528

@@ -36,6 +39,14 @@ class GitTests: XCTestCase, XCTestCaseProvider {
3639
XCTAssertFalse(gitRepo.hasVersion)
3740
}
3841
}
42+
43+
func testCloneShouldNotCrashWihoutTags() {
44+
tryCloningRepoWithTag("0.1.0", shouldCrash: false)
45+
}
46+
47+
func testCloneShouldCrashWihoutTags() {
48+
tryCloningRepoWithTag(nil, shouldCrash: true)
49+
}
3950
}
4051

4152
//MARK: - Helpers
@@ -59,3 +70,18 @@ private func makeGitRepo(dstdir: String, tag: String?, file: StaticString = __FI
5970
}
6071
return nil
6172
}
73+
74+
private func tryCloningRepoWithTag(tag: String?, shouldCrash: Bool) {
75+
var done = !shouldCrash
76+
mktmpdir { path in
77+
makeGitRepo(path, tag: tag)!
78+
do {
79+
_ = try Sandbox.RawClone(path: path)
80+
} catch Error.GitVersionTagRequired {
81+
done = shouldCrash
82+
} catch {
83+
XCTFail()
84+
}
85+
XCTAssertTrue(done)
86+
}
87+
}

0 commit comments

Comments
 (0)