Skip to content

Commit 0aceda4

Browse files
committed
[Utility] Fix ordering expectation on versions.
- This fixes a serious regression where `versions` was expected to be in order... it also boosts our test coverage of this scenario in two ways and adds an assertion on the internal invariant which wasn't previously documented.
1 parent 53d25f3 commit 0aceda4

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

Sources/Get/RawClone.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ class RawClone: Fetchable {
103103
}
104104

105105
var availableVersions: [Version] {
106-
return repo.versions
106+
let versions = repo.versions
107+
assert(versions == versions.sorted())
108+
return versions
107109
}
108110

109111
var finalName: String {

Sources/Utility/Git.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ public class Git {
7777
return knownVersions
7878
}(self)
7979

80-
/// The set of versions in the repository.
81-
public var versions: [Version] {
82-
return [Version](knownVersions.keys)
83-
}
80+
/// The set of versions in the repository, in order.
81+
public lazy var versions: [Version] = { repo in
82+
return [Version](repo.knownVersions.keys).sorted()
83+
}(self)
8484

8585
/// Check if repo contains a version tag
8686
public var hasVersion: Bool {

Tests/FunctionalTests/DependencyResolutionTests.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,15 @@ class DependencyResolutionTestCase: XCTestCase {
3838
}
3939
}
4040

41+
/// Check resolution of a trivial package with one dependency.
4142
func testExternalSimple() {
42-
fixture(name: "DependencyResolution/External/Simple") { prefix in
43+
// This will tag 'Foo' with 1.0.0, to start.
44+
fixture(name: "DependencyResolution/External/Simple", tags: ["1.0.0"]) { prefix in
45+
// Add several other tags to check version selection.
46+
for tag in ["1.1.0", "1.2.0", "1.2.3"] {
47+
try tagGitRepo(prefix.appending(components: "Foo"), tag: tag)
48+
}
49+
4350
XCTAssertBuilds(prefix.appending(component: "Bar"))
4451
XCTAssertFileExists(prefix.appending(components: "Bar", ".build", "debug", "Bar"))
4552
XCTAssertDirectoryExists(prefix.appending(components: "Bar", "Packages", "Foo-1.2.3"))

Tests/UtilityTests/GitTests.swift

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@
1010

1111
import XCTest
1212

13-
import TestSupport
1413
import Basic
14+
15+
import struct PackageDescription.Version
16+
1517
@testable import Utility
1618

19+
import TestSupport
20+
1721
class GitMoc: Git {
1822
static var mocVersion: String = "git version 2.5.4 (Apple Git-61)"
1923
override class var version: String! {
@@ -78,6 +82,16 @@ class GitUtilityTests: XCTestCase {
7882
}
7983
}
8084

85+
func testVersionOrdering() throws {
86+
mktmpdir { dir in
87+
let versionTags = (0..<10).map{ "\($0).0.0" }
88+
initGitRepo(dir)
89+
try versionTags.forEach{ try tagGitRepo(dir, tag: $0) }
90+
let repo = Git.Repo(path: dir)!
91+
XCTAssertEqual(repo.versions, versionTags.map{ Version($0)! })
92+
}
93+
}
94+
8195
//MARK: - Helpers
8296

8397
func checkSha(_ sha: String) {
@@ -100,5 +114,6 @@ class GitUtilityTests: XCTestCase {
100114
("testVersionSha", testVersionSha),
101115
("testHeadAndVersionSha", testHeadAndVersionSha),
102116
("testHasLocalChanges", testHasLocalChanges),
117+
("testVersionOrdering", testVersionOrdering),
103118
]
104119
}

0 commit comments

Comments
 (0)