@@ -12,13 +12,29 @@ import XCTest
12
12
13
13
import Basic
14
14
import Commands
15
+ import PackageDescription
16
+ import PackageLoading
17
+ import PackageModel
15
18
import SourceControl
16
19
import Utility
17
20
21
+ import struct TestSupport. MockManifestLoader
22
+
18
23
import TestSupport
19
24
20
25
@testable import class Commands. Workspace
21
26
27
+ private let sharedManifestLoader = ManifestLoader ( resources: Resources ( ) )
28
+
29
+ extension Workspace {
30
+ convenience init ( rootPackage path: AbsolutePath ) throws {
31
+ try self . init ( rootPackage: path, manifestLoader: sharedManifestLoader)
32
+ }
33
+ }
34
+
35
+ private let v1 : Version = " 1.0.0 "
36
+ private let v2 : Version = " 2.0.0 "
37
+
22
38
final class WorkspaceTests : XCTestCase {
23
39
func testBasics( ) throws {
24
40
mktmpdir { path in
@@ -83,7 +99,84 @@ final class WorkspaceTests: XCTestCase {
83
99
}
84
100
}
85
101
102
+ func testDependencyManifestLoading( ) {
103
+ // We mock up the following dep graph:
104
+ //
105
+ // Root
106
+ // \ A: checked out (@v1)
107
+ // \ AA: checked out (@v2)
108
+ // \ B: missing
109
+
110
+ mktmpdir { path in
111
+ // Create the test repositories, we don't need them to have actual
112
+ // contents (the manifests are mocked).
113
+ var repos : [ String : RepositorySpecifier ] = [ : ]
114
+ for name in [ " A " , " AA " ] {
115
+ let repoPath = path. appending ( component: name)
116
+ try makeDirectories ( repoPath)
117
+ initGitRepo ( repoPath, tag: " initial " )
118
+ repos [ name] = RepositorySpecifier ( url: repoPath. asString)
119
+ }
120
+
121
+ // Create the mock manifests.
122
+ let rootManifest = Manifest (
123
+ path: AbsolutePath ( " /UNUSED " ) ,
124
+ url: path. asString,
125
+ package : PackageDescription . Package (
126
+ name: " Root " ,
127
+ dependencies: [
128
+ . Package( url: repos [ " A " ] !. url, majorVersion: 1 ) ,
129
+ . Package( url: " //B " , majorVersion: 1 )
130
+ ] ) ,
131
+ products: [ ] ,
132
+ version: nil
133
+ )
134
+ let aManifest = Manifest (
135
+ path: AbsolutePath ( " /UNUSED " ) ,
136
+ url: repos [ " A " ] !. url,
137
+ package : PackageDescription . Package (
138
+ name: " A " ,
139
+ dependencies: [
140
+ . Package( url: repos [ " AA " ] !. url, majorVersion: 2 )
141
+ ] ) ,
142
+ products: [ ] ,
143
+ version: v1
144
+ )
145
+ let aaManifest = Manifest (
146
+ path: AbsolutePath ( " /UNUSED " ) ,
147
+ url: repos [ " AA " ] !. url,
148
+ package : PackageDescription . Package (
149
+ name: " AA " ) ,
150
+ products: [ ] ,
151
+ version: v2
152
+ )
153
+ let mockManifestLoader = MockManifestLoader ( manifests: [
154
+ MockManifestLoader . Key ( url: path. asString, version: nil ) : rootManifest,
155
+ // FIXME: These versions are wrong, we aren't preserving versions currently.
156
+ MockManifestLoader . Key ( url: repos [ " A " ] !. url, version: nil ) : aManifest,
157
+ MockManifestLoader . Key ( url: repos [ " AA " ] !. url, version: nil ) : aaManifest
158
+ ] )
159
+
160
+ // Create the workspace.
161
+ let workspace = try Workspace ( rootPackage: path, manifestLoader: mockManifestLoader)
162
+
163
+ // Ensure we have checkouts for A & AA.
164
+ for name in [ " A " , " AA " ] {
165
+ let revision = try GitRepository ( path: AbsolutePath ( repos [ name] !. url) ) . getCurrentRevision ( )
166
+ _ = try workspace. clone ( repository: repos [ name] !, at: revision)
167
+ }
168
+
169
+ // Load the "current" manifests.
170
+ let manifests = try workspace. loadDependencyManifests ( )
171
+ XCTAssertEqual ( manifests. root. package , rootManifest. package )
172
+ XCTAssertEqual ( manifests. dependencies. map { $0. package . name } . sorted ( ) , [ " A " , " AA " ] )
173
+
174
+ // FIXME: These manifests do not have the right versions in them, and they should.
175
+ }
176
+ }
177
+
86
178
static var allTests = [
87
179
( " testBasics " , testBasics) ,
180
+ ( " testDependencyManifestLoading " , testDependencyManifestLoading) ,
88
181
]
89
182
}
0 commit comments