Skip to content
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
3 changes: 3 additions & 0 deletions Sources/SwiftDependencyUpdaterLibrary/Dependency.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ struct Dependency {

static func loadDependencies(from folder: URL) throws -> [Dependency] {
let packageDescription = try PackageDescription.loadPackageDescription(from: folder)
if packageDescription.dependencies.isEmpty {
return []
}
let resolvedPackage = try ResolvedPackage.loadResolvedPackage(from: folder)
let swiftPackageUpdates = try SwiftPackageUpdate.checkUpdates(in: folder)
return try mergeDependencies(packageDescription: packageDescription, resolvedPackage: resolvedPackage, swiftPackageUpdates: swiftPackageUpdates)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct SwiftPackageUpdate {
return output
} catch {
let error = error as! ShellOutError // swiftlint:disable:this force_cast
throw PackageDescriptionError.loadingFailed(error.message)
throw SwiftPackageUpdateError.loadingFailed(error.message)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ extension XCTestCase {
return folder
}

func createEmptySwiftPackage() -> URL {
let folder = emptyFolderURL()
let packageSwift = temporaryFileURL(in: folder, name: "Package.swift")
createFile(at: packageSwift, content: TestUtils.emptyPackageSwiftFileContent)
let packageResolved = temporaryFileURL(in: folder, name: "Package.resolved")
createFile(at: packageResolved, content: TestUtils.emptyPackageResolvedFileContent)
let sourceFile = temporaryFileURL(in: folder.appendingPathComponent("Sources/Name"), name: "Name.swift")
createFile(at: sourceFile, content: "")

return folder
}

func assert<T, E: Error & Equatable>(_ expression: @autoclosure () throws -> T, throws expectedError: E, in file: StaticString = #file, line: UInt = #line) {
var caughtError: Error?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class GitHubCommandTests: XCTestCase {
func testInvalidPackage() {
let folder = emptyFolderURL()
let packageSwift = temporaryFileURL(in: folder, name: "Package.swift")
createFile(at: packageSwift, content: TestUtils.emptyPackageSwiftFileContent)
createFile(at: packageSwift, content: "// swift-tools-version:5.4")
let packageResolved = temporaryFileURL(in: folder, name: "Package.resolved")
createFile(at: packageResolved, content: TestUtils.emptyPackageResolvedFileContent)
let result = outputFromExecutionWith(arguments: ["github", folder.path])
Expand Down Expand Up @@ -266,16 +266,4 @@ class GitHubCommandTests: XCTestCase {
enforceOrder: true)
}

func createEmptySwiftPackage() -> URL {
let folder = emptyFolderURL()
let packageSwift = temporaryFileURL(in: folder, name: "Package.swift")
createFile(at: packageSwift, content: TestUtils.emptyPackageSwiftFileContent)
let packageResolved = temporaryFileURL(in: folder, name: "Package.resolved")
createFile(at: packageResolved, content: TestUtils.emptyPackageResolvedFileContent)
let sourceFile = temporaryFileURL(in: folder.appendingPathComponent("Sources/Name"), name: "Name.swift")
createFile(at: sourceFile, content: "")

return folder
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ListCommandTests: XCTestCase {
func testInvalidPackage() {
let folder = emptyFolderURL()
let packageSwift = temporaryFileURL(in: folder, name: "Package.swift")
createFile(at: packageSwift, content: TestUtils.emptyPackageSwiftFileContent)
createFile(at: packageSwift, content: "// swift-tools-version:5.4")
let packageResolved = temporaryFileURL(in: folder, name: "Package.resolved")
createFile(at: packageResolved, content: TestUtils.emptyPackageResolvedFileContent)
let result = outputFromExecutionWith(arguments: ["list", folder.path])
Expand Down Expand Up @@ -55,16 +55,4 @@ class ListCommandTests: XCTestCase {
XCTAssertEqual(result.output, "No dependencies found.")
}

func createEmptySwiftPackage() -> URL {
let folder = emptyFolderURL()
let packageSwift = temporaryFileURL(in: folder, name: "Package.swift")
createFile(at: packageSwift, content: TestUtils.emptyPackageSwiftFileContent)
let packageResolved = temporaryFileURL(in: folder, name: "Package.resolved")
createFile(at: packageResolved, content: TestUtils.emptyPackageResolvedFileContent)
let sourceFile = temporaryFileURL(in: folder.appendingPathComponent("Sources/Name"), name: "Name.swift")
createFile(at: sourceFile, content: "")

return folder
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class UpdateCommandTests: XCTestCase {
func testInvalidPackage() {
let folder = emptyFolderURL()
let packageSwift = temporaryFileURL(in: folder, name: "Package.swift")
createFile(at: packageSwift, content: TestUtils.emptyPackageSwiftFileContent)
createFile(at: packageSwift, content: "// swift-tools-version:5.4")
let packageResolved = temporaryFileURL(in: folder, name: "Package.resolved")
createFile(at: packageResolved, content: TestUtils.emptyPackageResolvedFileContent)
let result = outputFromExecutionWith(arguments: ["update", folder.path])
Expand Down Expand Up @@ -55,16 +55,4 @@ class UpdateCommandTests: XCTestCase {
XCTAssertEqual(result.output, "Everything is already up-to-date!")
}

func createEmptySwiftPackage() -> URL {
let folder = emptyFolderURL()
let packageSwift = temporaryFileURL(in: folder, name: "Package.swift")
createFile(at: packageSwift, content: TestUtils.emptyPackageSwiftFileContent)
let packageResolved = temporaryFileURL(in: folder, name: "Package.resolved")
createFile(at: packageResolved, content: TestUtils.emptyPackageResolvedFileContent)
let sourceFile = temporaryFileURL(in: folder.appendingPathComponent("Sources/Name"), name: "Name.swift")
createFile(at: sourceFile, content: "")

return folder
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,17 @@ class SwiftPackageUpdateTests: XCTestCase {
Rainbow.enabled = originalValue
}

func testCheckUpdatesEmptyFolder() {
let folder = emptyFolderURL()
assert(
try SwiftPackageUpdate.checkUpdates(in: folder),
throws: SwiftPackageUpdateError.loadingFailed("error: root manifest not found")
)
}

func testCheckUpdatesEmptySwiftPackage() {
let folder = createEmptySwiftPackage()
XCTAssert(try! SwiftPackageUpdate.checkUpdates(in: folder).isEmpty)
}

}