Skip to content

Commit be2dee2

Browse files
committed
[WorkspaceTests] Migrate Workspace tests to new testing infrastructure #2
1 parent ef9899e commit be2dee2

File tree

6 files changed

+1873
-2573
lines changed

6 files changed

+1873
-2573
lines changed

Sources/SourceControl/InMemoryGitRepository.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ public final class InMemoryGitRepository {
6060
return Array(tagsMap.keys)
6161
}
6262

63+
/// The list of revisions in the repository.
64+
public var revisions: [RevisionIdentifier] {
65+
return Array(history.keys)
66+
}
67+
6368
/// Indicates whether there are any uncommited changes in the repository.
6469
fileprivate var isDirty = false
6570

@@ -94,7 +99,7 @@ public final class InMemoryGitRepository {
9499
@discardableResult
95100
public func commit() -> String {
96101
// Create a fake hash for thie commit.
97-
let hash = NSUUID().uuidString
102+
let hash = String((NSUUID().uuidString + NSUUID().uuidString).prefix(40))
98103
head.hash = hash
99104
// Store the commit in history.
100105
history[hash] = head.copy()
@@ -230,7 +235,7 @@ extension InMemoryGitRepository: Repository {
230235
}
231236

232237
public func resolveRevision(identifier: String) throws -> Revision {
233-
fatalError("unimplemented")
238+
return Revision(identifier: tagsMap[identifier] ?? identifier)
234239
}
235240

236241
public func exists(revision: Revision) -> Bool {
@@ -253,11 +258,11 @@ extension InMemoryGitRepository: WorkingCheckout {
253258
}
254259

255260
public func hasUnpushedCommits() throws -> Bool {
256-
fatalError("Unimplemented")
261+
return false
257262
}
258263

259264
public func checkout(newBranch: String) throws {
260-
fatalError("Unimplemented")
265+
history[newBranch] = head
261266
}
262267
}
263268

Sources/Workspace/Workspace.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -679,10 +679,12 @@ extension Workspace {
679679
if let path = path {
680680
try fileSystem.createDirectory(editablesPath)
681681
// FIXME: We need this to work with InMem file system too.
682-
try createSymlink(
683-
editablesPath.appending(component: packageName),
684-
pointingAt: path,
685-
relative: false)
682+
if !(fileSystem is InMemoryFileSystem) {
683+
try createSymlink(
684+
editablesPath.appending(component: packageName),
685+
pointingAt: path,
686+
relative: false)
687+
}
686688
}
687689

688690
// Save the new state.

Tests/CommandsTests/PackageToolTests.swift

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,56 @@ final class PackageToolTests: XCTestCase {
435435
}
436436
}
437437

438+
func testSymlinkedDependency() {
439+
mktmpdir { path in
440+
var fs = localFileSystem
441+
let root = path.appending(components: "root")
442+
let dep = path.appending(components: "dep")
443+
let depSym = path.appending(components: "depSym")
444+
445+
// Create root package.
446+
try fs.writeFileContents(root.appending(components: "Sources", "root", "main.swift")) { $0 <<< "" }
447+
try fs.writeFileContents(root.appending(component: "Package.swift")) {
448+
$0 <<< """
449+
// swift-tools-version:4.0
450+
import PackageDescription
451+
let package = Package(
452+
name: "root",
453+
dependencies: [.package(url: "../depSym", from: "1.0.0")],
454+
targets: [.target(name: "root", dependencies: ["dep"])]
455+
)
456+
457+
"""
458+
}
459+
460+
// Create dependency.
461+
try fs.writeFileContents(dep.appending(components: "Sources", "dep", "lib.swift")) { $0 <<< "" }
462+
try fs.writeFileContents(dep.appending(component: "Package.swift")) {
463+
$0 <<< """
464+
// swift-tools-version:4.0
465+
import PackageDescription
466+
let package = Package(
467+
name: "dep",
468+
products: [.library(name: "dep", targets: ["dep"])],
469+
targets: [.target(name: "dep")]
470+
)
471+
"""
472+
}
473+
do {
474+
let depGit = GitRepository(path: dep)
475+
try depGit.create()
476+
try depGit.stageEverything()
477+
try depGit.commit()
478+
try depGit.tag(name: "1.0.0")
479+
}
480+
481+
// Create symlink to the dependency.
482+
try createSymlink(depSym, pointingAt: dep)
483+
484+
_ = try execute(["resolve"], packagePath: root)
485+
}
486+
}
487+
438488
static var allTests = [
439489
("testDescribe", testDescribe),
440490
("testUsage", testUsage),
@@ -452,5 +502,6 @@ final class PackageToolTests: XCTestCase {
452502
("testPackageReset", testPackageReset),
453503
("testPinning", testPinning),
454504
("testPinningBranchAndRevision", testPinningBranchAndRevision),
505+
("testSymlinkedDependency", testSymlinkedDependency),
455506
]
456507
}

0 commit comments

Comments
 (0)