💚 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]
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
/// - linkPackagesGlobally: A Boolean value indicating whether installing the packages of the Mintfile globally.
/// - Returns: Up instance to install Mint packages.
public static func mint(linkPackagesGlobally: Bool = false) -> Up {
return UpMint(linkPackagesGlobally: linkPackagesGlobally)
}
public static func mint(linkPackagesGlobally: Bool = false) -> Up {
return UpMint(linkPackagesGlobally: linkPackagesGlobally)
}
public static func == (_: Up, _: Up) -> Bool {
fatalError("Subclasses should override this method")

View File

@ -2,7 +2,7 @@ import Foundation
/// Up that installs Mint and packages.
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
/// Initializes the Mint up.

View File

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

View File

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

View File

@ -38,7 +38,7 @@ public final class MockSystem: Systeming {
if stub.exitstatus != 0 {
throw TuistSupport.SystemError.terminated(command: arguments.first!, code: 1)
}
calls.append(command)
calls.append(command)
}
public func run(_ arguments: String...) throws {
@ -65,7 +65,7 @@ public final class MockSystem: Systeming {
if stub.exitstatus != 0 {
throw TuistSupport.SystemError.terminated(command: arguments.first!, code: 1)
}
calls.append(command)
calls.append(command)
return stub.stdout ?? ""
}
@ -101,7 +101,7 @@ public final class MockSystem: Systeming {
}
throw TuistSupport.SystemError.terminated(command: arguments.first!, code: 1)
}
calls.append(command)
calls.append(command)
}
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.onCompleted()
self.calls.append(command)
self.calls.append(command)
return Disposables.create()
}
}
@ -147,7 +147,7 @@ public final class MockSystem: Systeming {
if stub.exitstatus != 0 {
throw TuistSupport.SystemError.terminated(command: arguments.first!, code: 1)
}
calls.append(command)
calls.append(command)
}
public func swiftVersion() throws -> String? {

View File

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