Skip to content

[WorkspaceTests] Migrate Workspace tests to new testing infrastructur… #1345

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions Sources/SourceControl/InMemoryGitRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ public final class InMemoryGitRepository {
return Array(tagsMap.keys)
}

/// The list of revisions in the repository.
public var revisions: [RevisionIdentifier] {
return Array(history.keys)
}

/// Indicates whether there are any uncommited changes in the repository.
fileprivate var isDirty = false

Expand Down Expand Up @@ -94,7 +99,7 @@ public final class InMemoryGitRepository {
@discardableResult
public func commit() -> String {
// Create a fake hash for thie commit.
let hash = NSUUID().uuidString
let hash = String((NSUUID().uuidString + NSUUID().uuidString).prefix(40))
head.hash = hash
// Store the commit in history.
history[hash] = head.copy()
Expand Down Expand Up @@ -230,7 +235,7 @@ extension InMemoryGitRepository: Repository {
}

public func resolveRevision(identifier: String) throws -> Revision {
fatalError("unimplemented")
return Revision(identifier: tagsMap[identifier] ?? identifier)
}

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

public func hasUnpushedCommits() throws -> Bool {
fatalError("Unimplemented")
return false
}

public func checkout(newBranch: String) throws {
fatalError("Unimplemented")
history[newBranch] = head
}
}

Expand Down
10 changes: 6 additions & 4 deletions Sources/Workspace/Workspace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -679,10 +679,12 @@ extension Workspace {
if let path = path {
try fileSystem.createDirectory(editablesPath)
// FIXME: We need this to work with InMem file system too.
try createSymlink(
editablesPath.appending(component: packageName),
pointingAt: path,
relative: false)
if !(fileSystem is InMemoryFileSystem) {
try createSymlink(
editablesPath.appending(component: packageName),
pointingAt: path,
relative: false)
}
}

// Save the new state.
Expand Down
51 changes: 51 additions & 0 deletions Tests/CommandsTests/PackageToolTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,56 @@ final class PackageToolTests: XCTestCase {
}
}

func testSymlinkedDependency() {
mktmpdir { path in
var fs = localFileSystem
let root = path.appending(components: "root")
let dep = path.appending(components: "dep")
let depSym = path.appending(components: "depSym")

// Create root package.
try fs.writeFileContents(root.appending(components: "Sources", "root", "main.swift")) { $0 <<< "" }
try fs.writeFileContents(root.appending(component: "Package.swift")) {
$0 <<< """
// swift-tools-version:4.0
import PackageDescription
let package = Package(
name: "root",
dependencies: [.package(url: "../depSym", from: "1.0.0")],
targets: [.target(name: "root", dependencies: ["dep"])]
)

"""
}

// Create dependency.
try fs.writeFileContents(dep.appending(components: "Sources", "dep", "lib.swift")) { $0 <<< "" }
try fs.writeFileContents(dep.appending(component: "Package.swift")) {
$0 <<< """
// swift-tools-version:4.0
import PackageDescription
let package = Package(
name: "dep",
products: [.library(name: "dep", targets: ["dep"])],
targets: [.target(name: "dep")]
)
"""
}
do {
let depGit = GitRepository(path: dep)
try depGit.create()
try depGit.stageEverything()
try depGit.commit()
try depGit.tag(name: "1.0.0")
}

// Create symlink to the dependency.
try createSymlink(depSym, pointingAt: dep)

_ = try execute(["resolve"], packagePath: root)
}
}

static var allTests = [
("testDescribe", testDescribe),
("testUsage", testUsage),
Expand All @@ -452,5 +502,6 @@ final class PackageToolTests: XCTestCase {
("testPackageReset", testPackageReset),
("testPinning", testPinning),
("testPinningBranchAndRevision", testPinningBranchAndRevision),
("testSymlinkedDependency", testSymlinkedDependency),
]
}
Loading