Skip to content

Commit

Permalink
Merge pull request #21 from Carthage/upgrade-dependencies
Browse files Browse the repository at this point in the history
Upgrade dependencies
  • Loading branch information
robrix committed Mar 1, 2015
2 parents 981cf9e + 88b2b3a commit eb37de2
Show file tree
Hide file tree
Showing 14 changed files with 91 additions and 82 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[submodule "Carthage.checkout/LlamaKit"]
path = Carthage/Checkouts/LlamaKit
url = https://github.com/Carthage/LlamaKit.git
url = https://github.com/LlamaKit/LlamaKit.git
[submodule "Carthage.checkout/Nimble"]
path = Carthage/Checkouts/Nimble
url = https://github.com/Quick/Nimble.git
Expand Down
2 changes: 1 addition & 1 deletion Cartfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github "Carthage/LlamaKit" == 0.1.1
github "LlamaKit/LlamaKit" == 0.5
4 changes: 2 additions & 2 deletions Cartfile.private
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
github "Quick/Quick" == 0.2.0
github "Quick/Nimble"
github "Quick/Quick" ~> 0.2
github "Quick/Nimble" ~> 0.3
github "jspahrsummers/xcconfigs" >= 0.6
8 changes: 4 additions & 4 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
github "Carthage/LlamaKit" "carthage-0.1.1"
github "Quick/Nimble" "v0.2.0"
github "Quick/Quick" "v0.2.0"
github "jspahrsummers/xcconfigs" "0.7"
github "LlamaKit/LlamaKit" "v0.5.0"
github "Quick/Nimble" "v0.3.0"
github "Quick/Quick" "v0.2.2"
github "jspahrsummers/xcconfigs" "0.7.2"
2 changes: 1 addition & 1 deletion Carthage/Checkouts/LlamaKit
2 changes: 1 addition & 1 deletion Carthage/Checkouts/Nimble
Submodule Nimble updated 82 files
+18 −0 Nimble.podspec
+163 −57 Nimble.xcodeproj/project.pbxproj
+1 −1 Nimble.xcodeproj/xcshareddata/xcschemes/Nimble-OSX.xcscheme
+5 −0 Nimble/Adapters/AdapterProtocols.swift
+21 −2 Nimble/Adapters/AssertionRecorder.swift
+43 −0 Nimble/DSL+Wait.swift
+5 −33 Nimble/DSL.swift
+6 −2 Nimble/Expectation.swift
+8 −4 Nimble/Expression.swift
+2 −12 Nimble/FailureMessage.swift
+6 −5 Nimble/Matchers/BeAKindOf.swift
+6 −5 Nimble/Matchers/BeAnInstanceOf.swift
+74 −8 Nimble/Matchers/BeCloseTo.swift
+24 −13 Nimble/Matchers/BeEmpty.swift
+9 −7 Nimble/Matchers/BeGreaterThan.swift
+10 −7 Nimble/Matchers/BeGreaterThanOrEqualTo.swift
+9 −13 Nimble/Matchers/BeIdenticalTo.swift
+8 −7 Nimble/Matchers/BeLessThan.swift
+10 −7 Nimble/Matchers/BeLessThanOrEqual.swift
+24 −21 Nimble/Matchers/BeLogical.swift
+3 −4 Nimble/Matchers/BeNil.swift
+0 −12 Nimble/Matchers/BeOneOf.swift
+18 −11 Nimble/Matchers/BeginWith.swift
+21 −16 Nimble/Matchers/Contain.swift
+18 −9 Nimble/Matchers/EndWith.swift
+29 −50 Nimble/Matchers/Equal.swift
+7 −9 Nimble/Matchers/Match.swift
+36 −15 Nimble/Matchers/MatcherProtocols.swift
+16 −4 Nimble/Matchers/RaisesException.swift
+1 −1 Nimble/Utils/Functional.swift
+5 −5 Nimble/Utils/Poll.swift
+6 −6 Nimble/Utils/Stringers.swift
+32 −6 Nimble/Wrappers/AsyncMatcherWrapper.swift
+28 −0 Nimble/Wrappers/BasicMatcherWrapper.swift
+3 −19 Nimble/Wrappers/FullMatcherWrapper.swift
+37 −10 Nimble/Wrappers/MatcherFunc.swift
+56 −0 Nimble/Wrappers/NonNilMatcherWrapper.swift
+63 −9 Nimble/Wrappers/ObjCMatcher.swift
+25 −12 Nimble/objc/DSL.h
+11 −0 Nimble/objc/DSL.m
+1 −1 Nimble/objc/NMBExceptionCapture.h
+33 −8 NimbleTests/Helpers/utils.swift
+4 −3 NimbleTests/Matchers/BeAKindOfTest.swift
+4 −3 NimbleTests/Matchers/BeAnInstanceOfTest.swift
+45 −0 NimbleTests/Matchers/BeCloseToTest.swift
+7 −3 NimbleTests/Matchers/BeEmptyTest.swift
+6 −0 NimbleTests/Matchers/BeGreaterThanOrEqualToTest.swift
+6 −2 NimbleTests/Matchers/BeGreaterThanTest.swift
+14 −0 NimbleTests/Matchers/BeIdenticalToObjectTest.swift
+8 −0 NimbleTests/Matchers/BeLessThanOrEqualToTest.swift
+7 −2 NimbleTests/Matchers/BeLessThanTest.swift
+6 −4 NimbleTests/Matchers/BeLogicalTest.swift
+7 −1 NimbleTests/Matchers/BeginWithTest.swift
+7 −1 NimbleTests/Matchers/ContainTest.swift
+7 −1 NimbleTests/Matchers/EndWithTest.swift
+48 −10 NimbleTests/Matchers/EqualTest.swift
+10 −1 NimbleTests/Matchers/MatchTest.swift
+0 −24 NimbleTests/Matchers/beOneOfTest.swift
+0 −139 NimbleTests/objc/CompatibilityTest.m
+11 −0 NimbleTests/objc/NimbleSpecHelper.h
+53 −0 NimbleTests/objc/ObjCAsyncTest.m
+34 −0 NimbleTests/objc/ObjCBeAnInstanceOfTest.m
+36 −0 NimbleTests/objc/ObjCBeCloseToTest.m
+24 −0 NimbleTests/objc/ObjCBeFalseTest.m
+28 −0 NimbleTests/objc/ObjCBeFalsyTest.m
+33 −0 NimbleTests/objc/ObjCBeGreaterThanOrEqualToTest.m
+33 −0 NimbleTests/objc/ObjCBeGreaterThanTest.m
+36 −0 NimbleTests/objc/ObjCBeIdenticalToTest.m
+34 −0 NimbleTests/objc/ObjCBeKindOfTest.m
+33 −0 NimbleTests/objc/ObjCBeLessThanOrEqualToTest.m
+33 −0 NimbleTests/objc/ObjCBeLessThanTest.m
+24 −0 NimbleTests/objc/ObjCBeNilTest.m
+25 −0 NimbleTests/objc/ObjCBeTrueTest.m
+28 −0 NimbleTests/objc/ObjCBeTruthyTest.m
+37 −0 NimbleTests/objc/ObjCBeginWithTest.m
+50 −0 NimbleTests/objc/ObjCContainTest.m
+37 −0 NimbleTests/objc/ObjCEndWithTest.m
+35 −0 NimbleTests/objc/ObjCEqualTest.m
+33 −0 NimbleTests/objc/ObjCMatchTest.m
+30 −0 NimbleTests/objc/ObjCRaiseExceptionTest.m
+124 −15 README.md
+2 −1 test
2 changes: 1 addition & 1 deletion Carthage/Checkouts/Quick
2 changes: 1 addition & 1 deletion Carthage/Checkouts/xcconfigs
2 changes: 1 addition & 1 deletion Commandant/ArgumentParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public final class ArgumentParser {
///
/// If a value is found, the key and the value are both removed from the
/// list of arguments remaining to be parsed.
internal func consumeValueForKey(key: String) -> Result<String?> {
internal func consumeValueForKey(key: String) -> Result<String?, CommandantError> {
let oldArguments = rawArguments
rawArguments.removeAll()

Expand Down
8 changes: 4 additions & 4 deletions Commandant/Command.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public protocol CommandType {
var function: String { get }

/// Runs this subcommand in the given mode.
func run(mode: CommandMode) -> Result<()>
func run(mode: CommandMode) -> Result<(), CommandantError>
}

/// Describes the "mode" in which a command should run.
Expand Down Expand Up @@ -56,7 +56,7 @@ public final class CommandRegistry {
/// arguments.
///
/// Returns the results of the execution, or nil if no such command exists.
public func runCommand(verb: String, arguments: [String]) -> Result<()>? {
public func runCommand(verb: String, arguments: [String]) -> Result<(), CommandantError>? {
return self[verb]?.run(.Arguments(ArgumentParser(arguments)))
}

Expand All @@ -81,7 +81,7 @@ extension CommandRegistry {
/// If a matching command could not be found, a helpful error message will
/// be written to `stderr`, then the process will exit with a failure error
/// code.
@noreturn public func main(#defaultCommand: CommandType, errorHandler: NSError -> ()) {
@noreturn public func main(#defaultCommand: CommandType, errorHandler: CommandantError -> ()) {
var arguments = Process.arguments
assert(arguments.count >= 1)

Expand All @@ -100,7 +100,7 @@ extension CommandRegistry {
exit(EXIT_SUCCESS)

case let .Some(.Failure(error)):
errorHandler(error)
errorHandler(error.unbox)
exit(EXIT_FAILURE)

case .None:
Expand Down
83 changes: 46 additions & 37 deletions Commandant/Errors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,41 @@

import Foundation

/// The domain for all errors originating within Commandant.
public let CommandantErrorDomain: NSString = "org.carthage.Commandant"
/// Possible errors that can originate from Commandant.
public enum CommandantError {
/// An option was used incorrectly.
case UsageError(description: String)

/// Creates an NSError that represents the receiver.
public func toNSError() -> NSError {
let domain = "org.carthage.Commandant"

switch self {
case let .UsageError(description):
return NSError(domain: domain, code: 0, userInfo: [ NSLocalizedDescriptionKey: description ])
}
}
}

/// Possible error codes within `CommandantErrorDomain`.
public enum CommandantError: Int {
/// One or more arguments was invalid.
case InvalidArgument
extension CommandantError: Printable {
public var description: String {
switch self {
case let .UsageError(description):
return description
}
}
}

/// Constructs an `InvalidArgument` error that indicates a missing value for
/// the argument by the given name.
internal func missingArgumentError(argumentName: String) -> NSError {
internal func missingArgumentError(argumentName: String) -> CommandantError {
let description = "Missing argument for \(argumentName)"
return NSError(domain: CommandantErrorDomain, code: CommandantError.InvalidArgument.rawValue, userInfo: [ NSLocalizedDescriptionKey: description ])
return CommandantError.UsageError(description: description)
}

/// Constructs an `InvalidArgument` error that describes how to use the
/// option, with the given example of key (and value, if applicable) usage.
internal func informativeUsageError<T>(keyValueExample: String, option: Option<T>) -> NSError {
/// Constructs an error that describes how to use the option, with the given
/// example of key (and value, if applicable) usage.
internal func informativeUsageError<T>(keyValueExample: String, option: Option<T>) -> CommandantError {
var description = ""

if option.defaultValue != nil {
Expand All @@ -43,13 +59,12 @@ internal func informativeUsageError<T>(keyValueExample: String, option: Option<T
.reduce(""){ previous, value in
return previous + "\n\t" + value
}

return NSError(domain: CommandantErrorDomain, code: CommandantError.InvalidArgument.rawValue, userInfo: [ NSLocalizedDescriptionKey: description ])
return CommandantError.UsageError(description: description)
}

/// Constructs an `InvalidArgument` error that describes how to use the
/// option.
internal func informativeUsageError<T: ArgumentType>(option: Option<T>) -> NSError {
/// Constructs an error that describes how to use the option.
internal func informativeUsageError<T: ArgumentType>(option: Option<T>) -> CommandantError {
var example = ""

if let key = option.key {
Expand All @@ -70,9 +85,8 @@ internal func informativeUsageError<T: ArgumentType>(option: Option<T>) -> NSErr
return informativeUsageError(example, option)
}

/// Constructs an `InvalidArgument` error that describes how to use the
/// given boolean option.
internal func informativeUsageError(option: Option<Bool>) -> NSError {
/// Constructs an error that describes how to use the given boolean option.
internal func informativeUsageError(option: Option<Bool>) -> CommandantError {
precondition(option.key != nil)

let key = option.key!
Expand All @@ -84,23 +98,18 @@ internal func informativeUsageError(option: Option<Bool>) -> NSError {
}
}

/// Combines the text of the two errors, if they're both `InvalidArgument`
/// errors. Otherwise, uses whichever one is not (biased toward the left).
internal func combineUsageErrors(left: NSError, right: NSError) -> NSError {
let combinedDescription = "\(left.localizedDescription)\n\n\(right.localizedDescription)"
let combinedError = NSError(domain: CommandantErrorDomain, code: CommandantError.InvalidArgument.rawValue, userInfo: [ NSLocalizedDescriptionKey: combinedDescription ])

func isUsageError(error: NSError) -> Bool {
return error.domain == combinedError.domain && error.code == combinedError.code
}

if isUsageError(left) {
if isUsageError(right) {
return combinedError
} else {
return right
}
} else {
return left
/// Combines the text of the two errors, if they're both `UsageError`s.
/// Otherwise, uses whichever one is not (biased toward the left).
internal func combineUsageErrors(lhs: CommandantError, rhs: CommandantError) -> CommandantError {
switch (lhs, rhs) {
case let (.UsageError(left), .UsageError(right)):
let combinedDescription = "\(left)\n\n\(right)"
return CommandantError.UsageError(description: combinedDescription)

case (.UsageError, _):
return rhs

case (_, .UsageError), (_, _):
return lhs
}
}
4 changes: 2 additions & 2 deletions Commandant/HelpCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public struct HelpCommand: CommandType {
self.registry = registry
}

public func run(mode: CommandMode) -> Result<()> {
public func run(mode: CommandMode) -> Result<(), CommandantError> {
return HelpOptions.evaluate(mode)
.flatMap { options in
if let verb = options.verb {
Expand Down Expand Up @@ -68,7 +68,7 @@ private struct HelpOptions: OptionsType {
return self(verb: (verb == "" ? nil : verb))
}

static func evaluate(m: CommandMode) -> Result<HelpOptions> {
static func evaluate(m: CommandMode) -> Result<HelpOptions, CommandantError> {
return create
<*> m <| Option(defaultValue: "", usage: "the command to display help for")
}
Expand Down
22 changes: 11 additions & 11 deletions Commandant/Option.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public protocol OptionsType {
///
/// Returns the parsed options, or an `InvalidArgument` error containing
/// usage information.
class func evaluate(m: CommandMode) -> Result<Self>
class func evaluate(m: CommandMode) -> Result<Self, CommandantError>
}

/// Describes an option that can be provided on the command line.
Expand Down Expand Up @@ -74,9 +74,9 @@ public struct Option<T> {

/// Constructs an `InvalidArgument` error that describes how the option was
/// used incorrectly. `value` should be the invalid value given by the user.
private func invalidUsageError(value: String) -> NSError {
private func invalidUsageError(value: String) -> CommandantError {
let description = "Invalid value for '\(self)': \(value)"
return NSError(domain: CommandantErrorDomain, code: CommandantError.InvalidArgument.rawValue, userInfo: [ NSLocalizedDescriptionKey: description ])
return CommandantError.UsageError(description: description)
}
}

Expand Down Expand Up @@ -154,24 +154,24 @@ infix operator <| {
///
/// In the context of command-line option parsing, this is used to chain
/// together the parsing of multiple arguments. See OptionsType for an example.
public func <*><T, U>(f: T -> U, value: Result<T>) -> Result<U> {
public func <*><T, U>(f: T -> U, value: Result<T, CommandantError>) -> Result<U, CommandantError> {
return value.map(f)
}

/// Applies the function in `f` to the value in the given result.
///
/// In the context of command-line option parsing, this is used to chain
/// together the parsing of multiple arguments. See OptionsType for an example.
public func <*><T, U>(f: Result<(T -> U)>, value: Result<T>) -> Result<U> {
public func <*><T, U>(f: Result<(T -> U), CommandantError>, value: Result<T, CommandantError>) -> Result<U, CommandantError> {
switch (f, value) {
case let (.Failure(left), .Failure(right)):
return failure(combineUsageErrors(left, right))
return failure(combineUsageErrors(left.unbox, right.unbox))

case let (.Failure(left), .Success):
return failure(left)
return failure(left.unbox)

case let (.Success, .Failure(right)):
return failure(right)
return failure(right.unbox)

case let (.Success(f), .Success(value)):
let newValue = f.unbox(value.unbox)
Expand All @@ -183,7 +183,7 @@ public func <*><T, U>(f: Result<(T -> U)>, value: Result<T>) -> Result<U> {
///
/// If parsing command line arguments, and no value was specified on the command
/// line, the option's `defaultValue` is used.
public func <|<T: ArgumentType>(mode: CommandMode, option: Option<T>) -> Result<T> {
public func <|<T: ArgumentType>(mode: CommandMode, option: Option<T>) -> Result<T, CommandantError> {
switch mode {
case let .Arguments(arguments):
var stringValue: String?
Expand All @@ -193,7 +193,7 @@ public func <|<T: ArgumentType>(mode: CommandMode, option: Option<T>) -> Result<
stringValue = value.unbox

case let .Failure(error):
return failure(error)
return failure(error.unbox)
}
} else {
stringValue = arguments.consumePositionalArgument()
Expand All @@ -220,7 +220,7 @@ public func <|<T: ArgumentType>(mode: CommandMode, option: Option<T>) -> Result<
///
/// If parsing command line arguments, and no value was specified on the command
/// line, the option's `defaultValue` is used.
public func <|(mode: CommandMode, option: Option<Bool>) -> Result<Bool> {
public func <|(mode: CommandMode, option: Option<Bool>) -> Result<Bool, CommandantError> {
precondition(option.key != nil)

switch mode {
Expand Down
30 changes: 15 additions & 15 deletions CommandantTests/OptionSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,62 +15,62 @@ import Quick
class OptionsTypeSpec: QuickSpec {
override func spec() {
describe("CommandMode.Arguments") {
func tryArguments(arguments: String...) -> Result<TestOptions> {
func tryArguments(arguments: String...) -> Result<TestOptions, CommandantError> {
return TestOptions.evaluate(.Arguments(ArgumentParser(arguments)))
}

it("should fail if a required argument is missing") {
expect(tryArguments().isSuccess()).to(beFalsy())
expect(tryArguments().isSuccess).to(beFalsy())
}

it("should fail if an option is missing a value") {
expect(tryArguments("required", "--intValue").isSuccess()).to(beFalsy())
expect(tryArguments("required", "--intValue").isSuccess).to(beFalsy())
}

it("should succeed without optional arguments") {
let value = tryArguments("required").value()
let value = tryArguments("required").value
let expected = TestOptions(intValue: 42, stringValue: "foobar", optionalFilename: "filename", requiredName: "required", enabled: false)
expect(value).to(equal(expected))
}

it("should succeed with some optional arguments") {
let value = tryArguments("required", "--intValue", "3", "fuzzbuzz").value()
let value = tryArguments("required", "--intValue", "3", "fuzzbuzz").value
let expected = TestOptions(intValue: 3, stringValue: "foobar", optionalFilename: "fuzzbuzz", requiredName: "required", enabled: false)
expect(value).to(equal(expected))
}

it("should override previous optional arguments") {
let value = tryArguments("required", "--intValue", "3", "--stringValue", "fuzzbuzz", "--intValue", "5", "--stringValue", "bazbuzz").value()
let value = tryArguments("required", "--intValue", "3", "--stringValue", "fuzzbuzz", "--intValue", "5", "--stringValue", "bazbuzz").value
let expected = TestOptions(intValue: 5, stringValue: "bazbuzz", optionalFilename: "filename", requiredName: "required", enabled: false)
expect(value).to(equal(expected))
}

it("should enable a boolean flag") {
let value = tryArguments("required", "--enabled", "--intValue", "3", "fuzzbuzz").value()
let value = tryArguments("required", "--enabled", "--intValue", "3", "fuzzbuzz").value
let expected = TestOptions(intValue: 3, stringValue: "foobar", optionalFilename: "fuzzbuzz", requiredName: "required", enabled: true)
expect(value).to(equal(expected))
}

it("should re-disable a boolean flag") {
let value = tryArguments("required", "--enabled", "--no-enabled", "--intValue", "3", "fuzzbuzz").value()
let value = tryArguments("required", "--enabled", "--no-enabled", "--intValue", "3", "fuzzbuzz").value
let expected = TestOptions(intValue: 3, stringValue: "foobar", optionalFilename: "fuzzbuzz", requiredName: "required", enabled: false)
expect(value).to(equal(expected))
}

it("should treat -- as the end of valued options") {
let value = tryArguments("--", "--intValue").value()
let value = tryArguments("--", "--intValue").value
let expected = TestOptions(intValue: 42, stringValue: "foobar", optionalFilename: "filename", requiredName: "--intValue", enabled: false)
expect(value).to(equal(expected))
}
}

describe("CommandMode.Usage") {
it("should return an error containing usage information") {
let error = TestOptions.evaluate(.Usage).error()!
expect(error.localizedDescription).to(contain("intValue"))
expect(error.localizedDescription).to(contain("stringValue"))
expect(error.localizedDescription).to(contain("name you're required to"))
expect(error.localizedDescription).to(contain("optionally specify"))
let error = TestOptions.evaluate(.Usage).error
expect(error?.description).to(contain("intValue"))
expect(error?.description).to(contain("stringValue"))
expect(error?.description).to(contain("name you're required to"))
expect(error?.description).to(contain("optionally specify"))
}
}
}
Expand All @@ -87,7 +87,7 @@ struct TestOptions: OptionsType, Equatable {
return self(intValue: a, stringValue: b, optionalFilename: d, requiredName: c, enabled: e)
}

static func evaluate(m: CommandMode) -> Result<TestOptions> {
static func evaluate(m: CommandMode) -> Result<TestOptions, CommandantError> {
return create
<*> m <| Option(key: "intValue", defaultValue: 42, usage: "Some integer value")
<*> m <| Option(key: "stringValue", defaultValue: "foobar", usage: "Some string value")
Expand Down

0 comments on commit eb37de2

Please sign in to comment.