💚 Fix formatting

This commit is contained in:
Daniel Jankowski 2020-03-23 09:34:35 +01:00
parent 0acd515100
commit 21502b94ca
7 changed files with 133 additions and 133 deletions

View File

@ -41,15 +41,15 @@ public class Up: Codable, Equatable {
let platforms = platforms ?? [.iOS, .macOS, .tvOS, .watchOS] let platforms = platforms ?? [.iOS, .macOS, .tvOS, .watchOS]
return UpCarthage(platforms: platforms) return UpCarthage(platforms: platforms)
} }
/// Returns an up that installs Mint packages specified in the Mintfile. /// Returns an up that installs Mint packages specified in the Mintfile.
/// ///
/// - Parameters /// - Parameters
/// - linkPackagesGlobally: A Boolean value indicating whether installing the packages of the Mintfile globally. /// - linkPackagesGlobally: A Boolean value indicating whether installing the packages of the Mintfile globally.
/// - Returns: Up instance to install Mint packages. /// - Returns: Up instance to install Mint packages.
public static func mint(linkPackagesGlobally: Bool = false) -> Up { public static func mint(linkPackagesGlobally: Bool = false) -> Up {
return UpMint(linkPackagesGlobally: linkPackagesGlobally) return UpMint(linkPackagesGlobally: linkPackagesGlobally)
} }
public static func == (_: Up, _: Up) -> Bool { public static func == (_: Up, _: Up) -> Bool {
fatalError("Subclasses should override this method") fatalError("Subclasses should override this method")

View File

@ -2,7 +2,7 @@ import Foundation
/// Up that installs Mint and packages. /// Up that installs Mint and packages.
class UpMint: Up { class UpMint: Up {
/// A Boolean value indicating whether installing the packages of the Mintfile globally. /// A Boolean value indicating whether installing the packages of the Mintfile globally.
let linkPackagesGlobally: Bool let linkPackagesGlobally: Bool
/// Initializes the Mint up. /// Initializes the Mint up.

View File

@ -74,9 +74,9 @@ class Up: Upping {
return try UpHomebrewTap(dictionary: dictionary, projectPath: projectPath) return try UpHomebrewTap(dictionary: dictionary, projectPath: projectPath)
} else if type == "carthage" { } else if type == "carthage" {
return try UpCarthage(dictionary: dictionary, projectPath: projectPath) return try UpCarthage(dictionary: dictionary, projectPath: projectPath)
} else if type == "mint" { } else if type == "mint" {
return try UpMint(dictionary: dictionary, projectPath: projectPath) return try UpMint(dictionary: dictionary, projectPath: projectPath)
} }
return nil return nil
} }

View File

@ -6,13 +6,13 @@ import TuistSupport
class UpMint: Up, GraphInitiatable { class UpMint: Up, GraphInitiatable {
/// A Boolean value indicating whether installing the packages of the Mintfile globally. /// A Boolean value indicating whether installing the packages of the Mintfile globally.
let linkPackagesGlobally: Bool let linkPackagesGlobally: Bool
/// Up homebrew for installing Mint. /// Up homebrew for installing Mint.
let upHomebrew: Upping let upHomebrew: Upping
init(linkPackagesGlobally: Bool, upHomebrew: Upping = UpHomebrew(packages: ["mint"])) { init(linkPackagesGlobally: Bool, upHomebrew: Upping = UpHomebrew(packages: ["mint"])) {
self.linkPackagesGlobally = linkPackagesGlobally self.linkPackagesGlobally = linkPackagesGlobally
self.upHomebrew = upHomebrew self.upHomebrew = upHomebrew
super.init(name: "Mint") super.init(name: "Mint")
} }
@ -23,8 +23,8 @@ class UpMint: Up, GraphInitiatable {
/// - projectPath: Absolute path to the folder that contains the manifest. /// - projectPath: Absolute path to the folder that contains the manifest.
/// This is useful to obtain absolute paths from the relative paths provided in the manifest by the user. /// This is useful to obtain absolute paths from the relative paths provided in the manifest by the user.
/// - Throws: A decoding error if an expected property is missing or has an invalid value. /// - Throws: A decoding error if an expected property is missing or has an invalid value.
required convenience init(dictionary: JSON, projectPath _: AbsolutePath) throws { required convenience init(dictionary: JSON, projectPath _: AbsolutePath) throws {
let linkPackagesGlobally: Bool = try dictionary.get("linkPackagesGlobally") let linkPackagesGlobally: Bool = try dictionary.get("linkPackagesGlobally")
self.init(linkPackagesGlobally: linkPackagesGlobally) self.init(linkPackagesGlobally: linkPackagesGlobally)
} }
@ -35,24 +35,24 @@ class UpMint: Up, GraphInitiatable {
/// - Returns: True if the command doesn't need to be run. /// - Returns: True if the command doesn't need to be run.
/// - Throws: An error if the check fails. /// - Throws: An error if the check fails.
override func isMet(projectPath: AbsolutePath) throws -> Bool { override func isMet(projectPath: AbsolutePath) throws -> Bool {
if try !upHomebrew.isMet(projectPath: projectPath) { if try !upHomebrew.isMet(projectPath: projectPath) {
return false return false
}
let mintfile = projectPath.appending(component: "Mintfile")
if !FileHandler.shared.exists(mintfile) {
throw MintError.mintfileNotFound(projectPath)
} }
let output = try System.shared.capture(["cat", "\(mintfile.pathString)"]) let mintfile = projectPath.appending(component: "Mintfile")
let packages = output.split(separator: "\n") if !FileHandler.shared.exists(mintfile) {
for package in packages { throw MintError.mintfileNotFound(projectPath)
guard let _ = try? System.shared.capture(["mint", "which", "\(package)"]) else { }
return false
} let output = try System.shared.capture(["cat", "\(mintfile.pathString)"])
} let packages = output.split(separator: "\n")
for package in packages {
return true guard let _ = try? System.shared.capture(["mint", "which", "\(package)"]) else {
return false
}
}
return true
} }
/// When the command is not met, this method runs it. /// When the command is not met, this method runs it.
@ -61,47 +61,47 @@ class UpMint: Up, GraphInitiatable {
/// - projectPath: Path to the directory that contains the project manifest. /// - projectPath: Path to the directory that contains the project manifest.
/// - Throws: An error if any error is thrown while running it. /// - Throws: An error if any error is thrown while running it.
override func meet(projectPath: AbsolutePath) throws { override func meet(projectPath: AbsolutePath) throws {
// Installing Mint // Installing Mint
if try !upHomebrew.isMet(projectPath: projectPath) { if try !upHomebrew.isMet(projectPath: projectPath) {
try upHomebrew.meet(projectPath: projectPath) try upHomebrew.meet(projectPath: projectPath)
} }
let mintfile = projectPath.appending(component: "Mintfile") let mintfile = projectPath.appending(component: "Mintfile")
if !FileHandler.shared.exists(mintfile) { if !FileHandler.shared.exists(mintfile) {
throw MintError.mintfileNotFound(projectPath) throw MintError.mintfileNotFound(projectPath)
} }
var command = ["mint", "bootstrap", "-m", "\(mintfile.pathString)"] var command = ["mint", "bootstrap", "-m", "\(mintfile.pathString)"]
if linkPackagesGlobally { command.append("--link") } if linkPackagesGlobally { command.append("--link") }
try System.shared.runAndPrint(command, verbose: true, environment: System.shared.env) try System.shared.runAndPrint(command, verbose: true, environment: System.shared.env)
} }
} }
extension UpMint { extension UpMint {
public enum MintError: FatalError, Equatable { public enum MintError: FatalError, Equatable {
case mintfileNotFound(AbsolutePath) case mintfileNotFound(AbsolutePath)
public var description: String { public var description: String {
switch self { switch self {
case let .mintfileNotFound(path): case let .mintfileNotFound(path):
return "Mintfile not found at path \(path.pathString)" return "Mintfile not found at path \(path.pathString)"
} }
} }
public var type: ErrorType { public var type: ErrorType {
switch self { switch self {
case .mintfileNotFound: case .mintfileNotFound:
return .abort return .abort
} }
} }
// MARK: - Equatable // MARK: - Equatable
public static func == (lhs: MintError, rhs: MintError) -> Bool { public static func == (lhs: MintError, rhs: MintError) -> Bool {
switch (lhs, rhs) { switch (lhs, rhs) {
case let (.mintfileNotFound(lhsPath), .mintfileNotFound(rhsPath)): case let (.mintfileNotFound(lhsPath), .mintfileNotFound(rhsPath)):
return lhsPath == rhsPath return lhsPath == rhsPath
} }
} }
} }
} }

View File

@ -38,7 +38,7 @@ public final class MockSystem: Systeming {
if stub.exitstatus != 0 { if stub.exitstatus != 0 {
throw TuistSupport.SystemError.terminated(command: arguments.first!, code: 1) throw TuistSupport.SystemError.terminated(command: arguments.first!, code: 1)
} }
calls.append(command) calls.append(command)
} }
public func run(_ arguments: String...) throws { public func run(_ arguments: String...) throws {
@ -65,7 +65,7 @@ public final class MockSystem: Systeming {
if stub.exitstatus != 0 { if stub.exitstatus != 0 {
throw TuistSupport.SystemError.terminated(command: arguments.first!, code: 1) throw TuistSupport.SystemError.terminated(command: arguments.first!, code: 1)
} }
calls.append(command) calls.append(command)
return stub.stdout ?? "" return stub.stdout ?? ""
} }
@ -101,7 +101,7 @@ public final class MockSystem: Systeming {
} }
throw TuistSupport.SystemError.terminated(command: arguments.first!, code: 1) throw TuistSupport.SystemError.terminated(command: arguments.first!, code: 1)
} }
calls.append(command) calls.append(command)
} }
public func observable(_ arguments: [String]) -> Observable<SystemEvent<Data>> { public func observable(_ arguments: [String]) -> Observable<SystemEvent<Data>> {
@ -130,7 +130,7 @@ public final class MockSystem: Systeming {
observer.onNext(.standardOutput(stdout.data(using: .utf8)!)) observer.onNext(.standardOutput(stdout.data(using: .utf8)!))
} }
observer.onCompleted() observer.onCompleted()
self.calls.append(command) self.calls.append(command)
return Disposables.create() return Disposables.create()
} }
} }
@ -147,7 +147,7 @@ public final class MockSystem: Systeming {
if stub.exitstatus != 0 { if stub.exitstatus != 0 {
throw TuistSupport.SystemError.terminated(command: arguments.first!, code: 1) throw TuistSupport.SystemError.terminated(command: arguments.first!, code: 1)
} }
calls.append(command) calls.append(command)
} }
public func swiftVersion() throws -> String? { public func swiftVersion() throws -> String? {

View File

@ -23,13 +23,13 @@ final class UpMintTests: TuistUnitTestCase {
func test_init() throws { func test_init() throws {
let temporaryPath = try self.temporaryPath() let temporaryPath = try self.temporaryPath()
let json = JSON(["linkPackagesGlobally": JSON.bool(true)]) let json = JSON(["linkPackagesGlobally": JSON.bool(true)])
let got = try UpMint(dictionary: json, projectPath: temporaryPath) let got = try UpMint(dictionary: json, projectPath: temporaryPath)
XCTAssertTrue(got.linkPackagesGlobally) XCTAssertTrue(got.linkPackagesGlobally)
} }
func test_isMet_when_homebrew_is_not_met() throws { func test_isMet_when_homebrew_is_not_met() throws {
let subject = UpMint(linkPackagesGlobally: false, upHomebrew: upHomebrew) let subject = UpMint(linkPackagesGlobally: false, upHomebrew: upHomebrew)
let temporaryPath = try self.temporaryPath() let temporaryPath = try self.temporaryPath()
upHomebrew.isMetStub = { _ in false } upHomebrew.isMetStub = { _ in false }
@ -38,121 +38,121 @@ final class UpMintTests: TuistUnitTestCase {
} }
func test_isMet_when_mintfile_doesnt_exist() throws { func test_isMet_when_mintfile_doesnt_exist() throws {
let subject = UpMint(linkPackagesGlobally: false, upHomebrew: upHomebrew) let subject = UpMint(linkPackagesGlobally: false, upHomebrew: upHomebrew)
let temporaryPath = try self.temporaryPath() let temporaryPath = try self.temporaryPath()
upHomebrew.isMetStub = { _ in true } upHomebrew.isMetStub = { _ in true }
XCTAssertThrowsError(try subject.isMet(projectPath: temporaryPath)) { error in XCTAssertThrowsError(try subject.isMet(projectPath: temporaryPath)) { error in
guard let error = error as? UpMint.MintError else { guard let error = error as? UpMint.MintError else {
XCTFail("Unexpected error type") XCTFail("Unexpected error type")
return return
} }
XCTAssertEqual(error.description, "Mintfile not found at path \(temporaryPath.pathString)") XCTAssertEqual(error.description, "Mintfile not found at path \(temporaryPath.pathString)")
XCTAssertEqual(error.type, .abort) XCTAssertEqual(error.type, .abort)
} }
} }
func test_isMet_when_mintfile_is_empty() throws { func test_isMet_when_mintfile_is_empty() throws {
let subject = UpMint(linkPackagesGlobally: false, upHomebrew: upHomebrew) let subject = UpMint(linkPackagesGlobally: false, upHomebrew: upHomebrew)
let temporaryPath = try self.temporaryPath() let temporaryPath = try self.temporaryPath()
let mintfile = temporaryPath.appending(component: "Mintfile") let mintfile = temporaryPath.appending(component: "Mintfile")
try fileHandler.touch(mintfile) try fileHandler.touch(mintfile)
upHomebrew.isMetStub = { _ in true } upHomebrew.isMetStub = { _ in true }
system.succeedCommand(["cat", "\(mintfile.pathString)"]) system.succeedCommand(["cat", "\(mintfile.pathString)"])
XCTAssertTrue(try subject.isMet(projectPath: temporaryPath)) XCTAssertTrue(try subject.isMet(projectPath: temporaryPath))
} }
func test_isMet_when_mint_packages_are_installed() throws { func test_isMet_when_mint_packages_are_installed() throws {
let subject = UpMint(linkPackagesGlobally: false, upHomebrew: upHomebrew) let subject = UpMint(linkPackagesGlobally: false, upHomebrew: upHomebrew)
let temporaryPath = try self.temporaryPath() let temporaryPath = try self.temporaryPath()
let mintfile = temporaryPath.appending(component: "Mintfile") let mintfile = temporaryPath.appending(component: "Mintfile")
try fileHandler.touch(mintfile) try fileHandler.touch(mintfile)
let package = "apple/swift-format@swift-5.1-branch" let package = "apple/swift-format@swift-5.1-branch"
upHomebrew.isMetStub = { _ in true } upHomebrew.isMetStub = { _ in true }
system.succeedCommand(["cat", "\(mintfile.pathString)"], output: package) system.succeedCommand(["cat", "\(mintfile.pathString)"], output: package)
system.succeedCommand(["mint", "which", "\(package)"]) system.succeedCommand(["mint", "which", "\(package)"])
XCTAssertTrue(try subject.isMet(projectPath: temporaryPath)) XCTAssertTrue(try subject.isMet(projectPath: temporaryPath))
} }
func test_isMet_when_mint_packages_are_not_installed() throws { func test_isMet_when_mint_packages_are_not_installed() throws {
let subject = UpMint(linkPackagesGlobally: false, upHomebrew: upHomebrew) let subject = UpMint(linkPackagesGlobally: false, upHomebrew: upHomebrew)
let temporaryPath = try self.temporaryPath() let temporaryPath = try self.temporaryPath()
let mintfile = temporaryPath.appending(component: "Mintfile") let mintfile = temporaryPath.appending(component: "Mintfile")
try fileHandler.touch(mintfile) try fileHandler.touch(mintfile)
let package = "apple/swift-format@swift-5.1-branch" let package = "apple/swift-format@swift-5.1-branch"
upHomebrew.isMetStub = { _ in true } upHomebrew.isMetStub = { _ in true }
system.succeedCommand(["cat", "\(mintfile.pathString)"], output: package) system.succeedCommand(["cat", "\(mintfile.pathString)"], output: package)
system.errorCommand(["mint", "which", "\(package)"]) system.errorCommand(["mint", "which", "\(package)"])
XCTAssertFalse(try subject.isMet(projectPath: temporaryPath)) XCTAssertFalse(try subject.isMet(projectPath: temporaryPath))
} }
func test_meet_when_homebrew_is_not_met() throws { func test_meet_when_homebrew_is_not_met() throws {
let subject = UpMint(linkPackagesGlobally: false, upHomebrew: upHomebrew) let subject = UpMint(linkPackagesGlobally: false, upHomebrew: upHomebrew)
let temporaryPath = try self.temporaryPath() let temporaryPath = try self.temporaryPath()
let mintfile = temporaryPath.appending(component: "Mintfile") let mintfile = temporaryPath.appending(component: "Mintfile")
try fileHandler.touch(mintfile) try fileHandler.touch(mintfile)
upHomebrew.isMetStub = { _ in false } upHomebrew.isMetStub = { _ in false }
upHomebrew.meetStub = { projectPath in upHomebrew.meetStub = { projectPath in
XCTAssertEqual(temporaryPath, projectPath) XCTAssertEqual(temporaryPath, projectPath)
} }
system.succeedCommand(["mint", "bootstrap", "-m", "\(mintfile.pathString)"]) system.succeedCommand(["mint", "bootstrap", "-m", "\(mintfile.pathString)"])
try subject.meet(projectPath: temporaryPath) try subject.meet(projectPath: temporaryPath)
XCTAssertEqual(upHomebrew.meetCallCount, 1) XCTAssertEqual(upHomebrew.meetCallCount, 1)
} }
func test_meet_when_mintfile_doesnt_exist() throws { func test_meet_when_mintfile_doesnt_exist() throws {
let subject = UpMint(linkPackagesGlobally: false, upHomebrew: upHomebrew) let subject = UpMint(linkPackagesGlobally: false, upHomebrew: upHomebrew)
let temporaryPath = try self.temporaryPath() let temporaryPath = try self.temporaryPath()
upHomebrew.isMetStub = { _ in true } upHomebrew.isMetStub = { _ in true }
XCTAssertThrowsError(try subject.isMet(projectPath: temporaryPath)) { error in XCTAssertThrowsError(try subject.isMet(projectPath: temporaryPath)) { error in
guard let error = error as? UpMint.MintError else { guard let error = error as? UpMint.MintError else {
XCTFail("Unexpected error type") XCTFail("Unexpected error type")
return return
} }
XCTAssertEqual(error.description, "Mintfile not found at path \(temporaryPath.pathString)") XCTAssertEqual(error.description, "Mintfile not found at path \(temporaryPath.pathString)")
XCTAssertEqual(error.type, .abort) XCTAssertEqual(error.type, .abort)
} }
} }
func test_meet() throws { func test_meet() throws {
let subject = UpMint(linkPackagesGlobally: false, upHomebrew: upHomebrew) let subject = UpMint(linkPackagesGlobally: false, upHomebrew: upHomebrew)
let temporaryPath = try self.temporaryPath() let temporaryPath = try self.temporaryPath()
let mintfile = temporaryPath.appending(component: "Mintfile") let mintfile = temporaryPath.appending(component: "Mintfile")
try fileHandler.touch(mintfile) try fileHandler.touch(mintfile)
upHomebrew.isMetStub = { _ in true } upHomebrew.isMetStub = { _ in true }
system.succeedCommand(["mint", "bootstrap", "-m", "\(mintfile.pathString)"]) system.succeedCommand(["mint", "bootstrap", "-m", "\(mintfile.pathString)"])
try subject.meet(projectPath: temporaryPath) try subject.meet(projectPath: temporaryPath)
XCTAssertEqual(upHomebrew.meetCallCount, 0) XCTAssertEqual(upHomebrew.meetCallCount, 0)
XCTAssertTrue(system.called("mint bootstrap -m \(mintfile.pathString)")) XCTAssertTrue(system.called("mint bootstrap -m \(mintfile.pathString)"))
} }
func test_meet_linkPackagesGlobally() throws { func test_meet_linkPackagesGlobally() throws {
let subject = UpMint(linkPackagesGlobally: true, upHomebrew: upHomebrew) let subject = UpMint(linkPackagesGlobally: true, upHomebrew: upHomebrew)
let temporaryPath = try self.temporaryPath() let temporaryPath = try self.temporaryPath()
let mintfile = temporaryPath.appending(component: "Mintfile") let mintfile = temporaryPath.appending(component: "Mintfile")
try fileHandler.touch(mintfile) try fileHandler.touch(mintfile)
upHomebrew.isMetStub = { _ in true } upHomebrew.isMetStub = { _ in true }
system.succeedCommand(["mint", "bootstrap", "-m", "\(mintfile.pathString)", "--link"]) system.succeedCommand(["mint", "bootstrap", "-m", "\(mintfile.pathString)", "--link"])
try subject.meet(projectPath: temporaryPath) try subject.meet(projectPath: temporaryPath)
XCTAssertEqual(upHomebrew.meetCallCount, 0) XCTAssertEqual(upHomebrew.meetCallCount, 0)
XCTAssertTrue(system.called("mint bootstrap -m \(mintfile.pathString) --link")) XCTAssertTrue(system.called("mint bootstrap -m \(mintfile.pathString) --link"))
} }
} }

View File

@ -53,15 +53,15 @@ final class UpTests: TuistUnitTestCase {
XCTAssertEqual(got?.name, "Carthage update") XCTAssertEqual(got?.name, "Carthage update")
XCTAssertEqual(got?.platforms, [.macOS]) XCTAssertEqual(got?.platforms, [.macOS])
} }
func test_with_when_mint() throws { func test_with_when_mint() throws {
let temporaryPath = try self.temporaryPath() let temporaryPath = try self.temporaryPath()
let dictionary = JSON([ let dictionary = JSON([
"type": "mint", "type": "mint",
"linkPackagesGlobally": JSON.bool(true) "linkPackagesGlobally": JSON.bool(true),
]) ])
let got = try Up.with(dictionary: dictionary, projectPath: temporaryPath) as? UpMint let got = try Up.with(dictionary: dictionary, projectPath: temporaryPath) as? UpMint
XCTAssertEqual(got?.name, "Mint") XCTAssertEqual(got?.name, "Mint")
XCTAssertEqual(got?.linkPackagesGlobally, true) XCTAssertEqual(got?.linkPackagesGlobally, true)
} }
} }