|
11 | 11 | import XCTest
|
12 | 12 |
|
13 | 13 | import TSCBasic
|
| 14 | +import TSCUtility |
14 | 15 | import PackageLoading
|
15 | 16 | import PackageModel
|
16 | 17 | import PackageGraph
|
@@ -478,4 +479,62 @@ class RepositoryPackageContainerProviderTests: XCTestCase {
|
478 | 479 | )
|
479 | 480 | }
|
480 | 481 | }
|
| 482 | + |
| 483 | + func testMissingBranchDiagnostics() { |
| 484 | + mktmpdir { tmpDir in |
| 485 | + // Create a repository. |
| 486 | + let packageDir = tmpDir.appending(component: "SomePackage") |
| 487 | + try localFileSystem.createDirectory(packageDir) |
| 488 | + initGitRepo(packageDir) |
| 489 | + let packageRepo = GitRepository(path: packageDir) |
| 490 | + |
| 491 | + // Create a package manifest in it (it only needs the `swift-tools-version` part, because we'll supply the manifest later). |
| 492 | + let manifestFile = packageDir.appending(component: "Package.swift") |
| 493 | + try localFileSystem.writeFileContents(manifestFile, bytes: ByteString("// swift-tools-version:4.2")) |
| 494 | + |
| 495 | + // Commit it and tag it. |
| 496 | + try packageRepo.stage(file: "Package.swift") |
| 497 | + try packageRepo.commit(message: "Initial") |
| 498 | + try packageRepo.tag(name: "1.0.0") |
| 499 | + |
| 500 | + // Rename the `master` branch to `main`. |
| 501 | + try systemQuietly([Git.tool, "-C", packageDir.pathString, "branch", "-m", "main"]) |
| 502 | + |
| 503 | + // Create a repository manager for it. |
| 504 | + let repoProvider = GitRepositoryProvider() |
| 505 | + let repositoryManager = RepositoryManager(path: packageDir, provider: repoProvider, delegate: nil, fileSystem: localFileSystem) |
| 506 | + |
| 507 | + // Create a container provider, configured with a mock manifest loader that will return the package manifest. |
| 508 | + let manifest = Manifest.createV4Manifest( |
| 509 | + name: packageDir.basename, |
| 510 | + path: packageDir.pathString, |
| 511 | + url: packageDir.pathString, |
| 512 | + packageKind: .root, |
| 513 | + targets: [ |
| 514 | + TargetDescription(name: packageDir.basename, path: packageDir.pathString) |
| 515 | + ] |
| 516 | + ) |
| 517 | + let containerProvider = RepositoryPackageContainerProvider(repositoryManager: repositoryManager, manifestLoader: MockManifestLoader(manifests: [.init(url: packageDir.pathString, version: nil) : manifest])) |
| 518 | + |
| 519 | + // Get a hold of the container for the test package. |
| 520 | + let packageRef = PackageReference(identity: "somepackage", path: packageDir.pathString) |
| 521 | + let container = try await { containerProvider.getContainer(for: packageRef, completion: $0) } as! RepositoryPackageContainer |
| 522 | + |
| 523 | + // Simulate accessing a fictitious dependency on the `master` branch, and check that we get back the expected error. |
| 524 | + do { _ = try container.getDependencies(at: "master") } |
| 525 | + catch let error as RepositoryPackageContainer.GetDependenciesErrorWrapper { |
| 526 | + // We expect to get an error message about `master` with a suggestion to use `main`. |
| 527 | + XCTAssertEqual("\(error.underlyingError)", "could not find a branch named ‘master’") |
| 528 | + XCTAssertEqual(error.suggestion, "did you mean ‘main’?") |
| 529 | + } |
| 530 | + |
| 531 | + // Simulate accessing a fictitious dependency on some random commit that doesn't exist, and check that we get back the expected error. |
| 532 | + do { _ = try container.getDependencies(at: "535f4cb5b4a0872fa691473e82d7b27b9894df00") } |
| 533 | + catch let error as RepositoryPackageContainer.GetDependenciesErrorWrapper { |
| 534 | + // We expect to get an error message about the commit SHA, but without a suggestion. |
| 535 | + XCTAssertMatch("\(error.underlyingError)", "could not find the commit 535f4cb5b4a0872fa691473e82d7b27b9894df00") |
| 536 | + XCTAssertEqual(error.suggestion, nil) |
| 537 | + } |
| 538 | + } |
| 539 | + } |
481 | 540 | }
|
0 commit comments