Skip to content

Beta 4 compatibility #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 27, 2014
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
14 changes: 4 additions & 10 deletions Nimble.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
1F14FB64194180C5009F2A08 /* utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F14FB63194180C5009F2A08 /* utils.swift */; };
1F1A742F1940169200FFFC47 /* Nimble.h in Headers */ = {isa = PBXBuildFile; fileRef = 1F1A742E1940169200FFFC47 /* Nimble.h */; settings = {ATTRIBUTES = (Public, ); }; };
1F1A74351940169200FFFC47 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1F1A74291940169200FFFC47 /* Nimble.framework */; };
1F1A744E1940171400FFFC47 /* Nimble-Bridging-Header.h in Headers */ = {isa = PBXBuildFile; fileRef = 1F1A744D1940171400FFFC47 /* Nimble-Bridging-Header.h */; };
1F1B5AD41963E13900CA8BF9 /* BeAKindOfTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F1B5AD31963E13900CA8BF9 /* BeAKindOfTest.swift */; };
1F1B5AD51963E13900CA8BF9 /* BeAKindOfTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F1B5AD31963E13900CA8BF9 /* BeAKindOfTest.swift */; };
1F22D9E5195ED11400CA1480 /* Functional.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F22D9E4195ED11400CA1480 /* Functional.swift */; };
Expand All @@ -29,7 +28,6 @@
1F925EB8195C0D6300ED456B /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1F925EAD195C0D6300ED456B /* Nimble.framework */; };
1F925EC7195C0DD100ED456B /* Nimble.h in Headers */ = {isa = PBXBuildFile; fileRef = 1F1A742E1940169200FFFC47 /* Nimble.h */; settings = {ATTRIBUTES = (Public, ); }; };
1F925EC8195C0DDA00ED456B /* SourceLocation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F2C568D1944FD4F001DF2B4 /* SourceLocation.swift */; };
1F925EE1195C0DF600ED456B /* Nimble-Bridging-Header.h in Headers */ = {isa = PBXBuildFile; fileRef = 1F1A744D1940171400FFFC47 /* Nimble-Bridging-Header.h */; };
1F925EE2195C0DFD00ED456B /* utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F14FB63194180C5009F2A08 /* utils.swift */; };
1F925EE6195C121200ED456B /* AsynchronousTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F925EE5195C121200ED456B /* AsynchronousTest.swift */; };
1F925EE7195C121200ED456B /* AsynchronousTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F925EE5195C121200ED456B /* AsynchronousTest.swift */; };
Expand Down Expand Up @@ -201,7 +199,6 @@
1F1A742E1940169200FFFC47 /* Nimble.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Nimble.h; sourceTree = "<group>"; };
1F1A74341940169200FFFC47 /* NimbleTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = NimbleTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
1F1A743A1940169200FFFC47 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
1F1A744D1940171400FFFC47 /* Nimble-Bridging-Header.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "Nimble-Bridging-Header.h"; sourceTree = "<group>"; };
1F1B5AD31963E13900CA8BF9 /* BeAKindOfTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BeAKindOfTest.swift; sourceTree = "<group>"; };
1F22D9E4195ED11400CA1480 /* Functional.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Functional.swift; sourceTree = "<group>"; };
1F2752D119445B8400052A26 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
Expand Down Expand Up @@ -349,7 +346,6 @@
1FD8CD291968AB07008ED995 /* Wrappers */,
1F2C568C1944FD30001DF2B4 /* Utils */,
1F1A742E1940169200FFFC47 /* Nimble.h */,
1F1A744D1940171400FFFC47 /* Nimble-Bridging-Header.h */,
1F1A742C1940169200FFFC47 /* Supporting Files */,
);
path = Nimble;
Expand Down Expand Up @@ -507,7 +503,6 @@
1FD8CD601968AB07008ED995 /* DSL.h in Headers */,
1FD8CD641968AB07008ED995 /* NMBExceptionCapture.h in Headers */,
1F1A742F1940169200FFFC47 /* Nimble.h in Headers */,
1F1A744E1940171400FFFC47 /* Nimble-Bridging-Header.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -518,7 +513,6 @@
1FD8CD611968AB07008ED995 /* DSL.h in Headers */,
1FD8CD651968AB07008ED995 /* NMBExceptionCapture.h in Headers */,
1F925EC7195C0DD100ED456B /* Nimble.h in Headers */,
1F925EE1195C0DF600ED456B /* Nimble-Bridging-Header.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -977,7 +971,7 @@
PRODUCT_MODULE_NAME = Nimble;
PRODUCT_NAME = Nimble;
SKIP_INSTALL = YES;
SWIFT_OBJC_BRIDGING_HEADER = "Nimble/Nimble-Bridging-Header.h";
SWIFT_OBJC_BRIDGING_HEADER = "";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
};
name = Debug;
Expand Down Expand Up @@ -1006,7 +1000,7 @@
PRODUCT_MODULE_NAME = Nimble;
PRODUCT_NAME = Nimble;
SKIP_INSTALL = YES;
SWIFT_OBJC_BRIDGING_HEADER = "Nimble/Nimble-Bridging-Header.h";
SWIFT_OBJC_BRIDGING_HEADER = "";
};
name = Release;
};
Expand Down Expand Up @@ -1078,7 +1072,7 @@
PRODUCT_NAME = Nimble;
SDKROOT = macosx;
SKIP_INSTALL = YES;
SWIFT_OBJC_BRIDGING_HEADER = "Nimble/Nimble-Bridging-Header.h";
SWIFT_OBJC_BRIDGING_HEADER = "";
};
name = Debug;
};
Expand Down Expand Up @@ -1110,7 +1104,7 @@
PRODUCT_NAME = Nimble;
SDKROOT = macosx;
SKIP_INSTALL = YES;
SWIFT_OBJC_BRIDGING_HEADER = "Nimble/Nimble-Bridging-Header.h";
SWIFT_OBJC_BRIDGING_HEADER = "";
};
name = Release;
};
Expand Down
18 changes: 10 additions & 8 deletions Nimble/Adapters/AssertionRecorder.swift
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import Foundation

struct AssertionRecord {
let success: Bool
let message: String
let location: SourceLocation
public struct AssertionRecord {
public let success: Bool
public let message: String
public let location: SourceLocation
}

class AssertionRecorder : AssertionHandler {
var assertions = [AssertionRecord]()
public class AssertionRecorder : AssertionHandler {
public var assertions = [AssertionRecord]()

func assert(assertion: Bool, message: String, location: SourceLocation) {
public init() {}

public func assert(assertion: Bool, message: String, location: SourceLocation) {
assertions.append(
AssertionRecord(
success: assertion,
Expand All @@ -18,7 +20,7 @@ class AssertionRecorder : AssertionHandler {
}
}

func withAssertionHandler(recorder: AssertionHandler, closure: () -> Void) {
public func withAssertionHandler(recorder: AssertionHandler, closure: () -> Void) {
let oldRecorder = CurrentAssertionHandler
let capturer = NMBExceptionCapture(handler: nil, finally: ({
CurrentAssertionHandler = oldRecorder
Expand Down
2 changes: 1 addition & 1 deletion Nimble/Adapters/Protocols.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

protocol AssertionHandler {
public protocol AssertionHandler {
func assert(assertion: Bool, message: String, location: SourceLocation)
}

Expand Down
14 changes: 7 additions & 7 deletions Nimble/DSL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Foundation

// Begins an assertion on a given value.
// file: and line: can be omitted to default to the current line this function is called on.
func expect<T>(expression: @auto_closure () -> T, file: String = __FILE__, line: Int = __LINE__) -> Expectation<T> {
public func expect<T>(expression: @auto_closure () -> T, file: String = __FILE__, line: Int = __LINE__) -> Expectation<T> {
return Expectation(
expression: Expression(
expression: expression,
Expand All @@ -11,7 +11,7 @@ func expect<T>(expression: @auto_closure () -> T, file: String = __FILE__, line:

// Begins an assertion on a given value.
// file: and line: can be omitted to default to the current line this function is called on.
func expect<T>(file: String = __FILE__, line: Int = __LINE__, expression: () -> T) -> Expectation<T> {
public func expect<T>(file: String = __FILE__, line: Int = __LINE__, expression: () -> T) -> Expectation<T> {
return Expectation(
expression: Expression(
expression: expression,
Expand All @@ -20,7 +20,7 @@ func expect<T>(file: String = __FILE__, line: Int = __LINE__, expression: () ->

// Begins an assertion on a given value.
// file: and line: can be omitted to default to the current line this function is called on.
func waitUntil(#timeout: NSTimeInterval, action: (() -> Void) -> Void, file: String = __FILE__, line: Int = __LINE__) -> Void {
public func waitUntil(#timeout: NSTimeInterval, action: (() -> Void) -> Void, file: String = __FILE__, line: Int = __LINE__) -> Void {
var completed = false
dispatch_async(dispatch_get_main_queue()) {
action() { completed = true }
Expand All @@ -36,18 +36,18 @@ func waitUntil(#timeout: NSTimeInterval, action: (() -> Void) -> Void, file: Str

// Begins an assertion on a given value.
// file: and line: can be omitted to default to the current line this function is called on.
func waitUntil(action: (() -> Void) -> Void, file: String = __FILE__, line: Int = __LINE__) -> Void {
public func waitUntil(action: (() -> Void) -> Void, file: String = __FILE__, line: Int = __LINE__) -> Void {
waitUntil(timeout: 1, action, file: file, line: line)
}

func fail(message: String, #location: SourceLocation) {
public func fail(message: String, #location: SourceLocation) {
CurrentAssertionHandler.assert(false, message: message, location: location)
}

func fail(message: String, file: String = __FILE__, line: Int = __LINE__) {
public func fail(message: String, file: String = __FILE__, line: Int = __LINE__) {
fail(message, location: SourceLocation(file: file, line: line))
}

func fail(file: String = __FILE__, line: Int = __LINE__) {
public func fail(file: String = __FILE__, line: Int = __LINE__) {
fail("fail() always fails")
}
12 changes: 6 additions & 6 deletions Nimble/Expectation.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import Foundation

struct Expectation<T> {
public struct Expectation<T> {
let expression: Expression<T>

func verify(pass: Bool, _ message: String) {
public func verify(pass: Bool, _ message: String) {
CurrentAssertionHandler.assert(pass, message: message, location: expression.location)
}

func to<U where U: Matcher, U.ValueType == T>(matcher: U) {
func toImpl<U where U: BasicMatcher, U.ValueType == T>(matcher: U) {
var msg = FailureMessage()
let pass = matcher.matches(expression, failureMessage: msg)
if msg.actualValue == "" {
Expand All @@ -16,7 +16,7 @@ struct Expectation<T> {
verify(pass, msg.stringValue())
}

func toNot<U where U: Matcher, U.ValueType == T>(matcher: U) {
func toNotImpl<U where U: Matcher, U.ValueType == T>(matcher: U) {
var msg = FailureMessage()
let pass = matcher.doesNotMatch(expression, failureMessage: msg)
if msg.actualValue == "" {
Expand All @@ -25,8 +25,8 @@ struct Expectation<T> {
verify(pass, msg.stringValue())
}

func notTo<U where U: Matcher, U.ValueType == T>(matcher: U) {
toNot(matcher)
func notToImpl<U where U: Matcher, U.ValueType == T>(matcher: U) {
toNotImpl(matcher)
}

// see FullMatcherWrapper and AsyncMatcherWrapper for extensions
Expand Down
18 changes: 9 additions & 9 deletions Nimble/Expression.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,29 @@ func _memoizedClosure<T>(closure: () -> T) -> (Bool) -> T {
})
}

struct Expression<T> {
let _expression: (Bool) -> T
let location: SourceLocation
let _withoutCaching: Bool
var cache: T?
public struct Expression<T> {
public let _expression: (Bool) -> T
public let location: SourceLocation
public let _withoutCaching: Bool
public var cache: T?

init(expression: () -> T, location: SourceLocation) {
public init(expression: () -> T, location: SourceLocation) {
self._expression = _memoizedClosure(expression)
self.location = location
self._withoutCaching = false
}

init(memoizedExpression: (Bool) -> T, location: SourceLocation, withoutCaching: Bool) {
public init(memoizedExpression: (Bool) -> T, location: SourceLocation, withoutCaching: Bool) {
self._expression = memoizedExpression
self.location = location
self._withoutCaching = withoutCaching
}

func evaluate() -> T {
public func evaluate() -> T {
return self._expression(_withoutCaching)
}

func withoutCaching() -> Expression<T> {
public func withoutCaching() -> Expression<T> {
return Expression(memoizedExpression: self._expression, location: location, withoutCaching: true)
}
}
14 changes: 7 additions & 7 deletions Nimble/FailureMessage.swift
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import Foundation

@objc
class FailureMessage {
var expected: String = "expected"
var actualValue: String? = "" // empty string -> use default; nil -> exclude
var to: String = "to"
var postfixMessage: String = "match"
public class FailureMessage {
public var expected: String = "expected"
public var actualValue: String? = "" // empty string -> use default; nil -> exclude
public var to: String = "to"
public var postfixMessage: String = "match"

init() {
public init() {
}

func stringValue() -> String {
public func stringValue() -> String {
var value = "\(expected) \(to) \(postfixMessage)"
if actualValue {
value = "\(expected) \(actualValue) \(to) \(postfixMessage)"
Expand Down
4 changes: 2 additions & 2 deletions Nimble/Matchers/BeAKindOf.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

func beAKindOf(expectedClass: AnyClass) -> MatcherFunc<NSObject?> {
public func beAKindOf(expectedClass: AnyClass) -> MatcherFunc<NSObject?> {
return MatcherFunc { actualExpression, failureMessage in
let instance = actualExpression.evaluate()
if let validInstance = instance {
Expand All @@ -14,7 +14,7 @@ func beAKindOf(expectedClass: AnyClass) -> MatcherFunc<NSObject?> {
}

extension NMBObjCMatcher {
class func beAKindOfMatcher(expected: AnyClass) -> NMBMatcher {
public class func beAKindOfMatcher(expected: AnyClass) -> NMBMatcher {
return NMBObjCMatcher { actualExpression, failureMessage, location in
let expr = Expression(expression: actualExpression, location: location)
return beAKindOf(expected).matches(expr, failureMessage: failureMessage)
Expand Down
4 changes: 2 additions & 2 deletions Nimble/Matchers/BeAnInstanceOf.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

func beAnInstanceOf(expectedClass: AnyClass) -> MatcherFunc<NSObject?> {
public func beAnInstanceOf(expectedClass: AnyClass) -> MatcherFunc<NSObject?> {
return MatcherFunc { actualExpression, failureMessage in
let instance = actualExpression.evaluate()
if let validInstance = instance {
Expand All @@ -14,7 +14,7 @@ func beAnInstanceOf(expectedClass: AnyClass) -> MatcherFunc<NSObject?> {
}

extension NMBObjCMatcher {
class func beAnInstanceOfMatcher(expected: AnyClass) -> NMBMatcher {
public class func beAnInstanceOfMatcher(expected: AnyClass) -> NMBMatcher {
return NMBObjCMatcher { actualExpression, failureMessage, location in
let expr = Expression(expression: actualExpression, location: location)
return beAnInstanceOf(expected).matches(expr, failureMessage: failureMessage)
Expand Down
12 changes: 6 additions & 6 deletions Nimble/Matchers/BeCloseTo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,43 @@ func _isCloseTo(actualValue: Double?, expectedValue: Double, delta: Double, fail
return actualValue && abs(actualValue! - expectedValue) < delta
}

func beCloseTo(expectedValue: Double, within delta: Double = 0.0001) -> MatcherFunc<Double> {
public func beCloseTo(expectedValue: Double, within delta: Double = 0.0001) -> MatcherFunc<Double> {
return MatcherFunc { actualExpression, failureMessage in
return _isCloseTo(actualExpression.evaluate(), expectedValue, delta, failureMessage)
}
}

func beCloseTo(expectedValue: NMBDoubleConvertible, within delta: Double = 0.0001) -> MatcherFunc<NMBDoubleConvertible?> {
public func beCloseTo(expectedValue: NMBDoubleConvertible, within delta: Double = 0.0001) -> MatcherFunc<NMBDoubleConvertible?> {
return MatcherFunc { actualExpression, failureMessage in
return _isCloseTo(actualExpression.evaluate()?.doubleValue, expectedValue.doubleValue, delta, failureMessage)
}
}

@objc class NMBObjCBeCloseToMatcher : NMBMatcher {
@objc public class NMBObjCBeCloseToMatcher : NMBMatcher {
var _expected: NSNumber
var _delta: CDouble
init(expected: NSNumber, within: CDouble) {
_expected = expected
_delta = within
}

func matches(actualExpression: () -> NSObject!, failureMessage: FailureMessage, location: SourceLocation) -> Bool {
public func matches(actualExpression: () -> NSObject!, failureMessage: FailureMessage, location: SourceLocation) -> Bool {
let actualBlock: () -> NMBDoubleConvertible? = ({
return actualExpression() as? NMBDoubleConvertible
})
let expr = Expression(expression: actualBlock, location: location)
return beCloseTo(self._expected, within: self._delta).matches(expr, failureMessage: failureMessage)
}

var within: (CDouble) -> NMBObjCBeCloseToMatcher {
public var within: (CDouble) -> NMBObjCBeCloseToMatcher {
return ({ delta in
return NMBObjCBeCloseToMatcher(expected: self._expected, within: delta)
})
}
}

extension NMBObjCMatcher {
class func beCloseToMatcher(expected: NSNumber, within: CDouble) -> NMBObjCBeCloseToMatcher {
public class func beCloseToMatcher(expected: NSNumber, within: CDouble) -> NMBObjCBeCloseToMatcher {
return NMBObjCBeCloseToMatcher(expected: expected, within: within)
}
}
6 changes: 3 additions & 3 deletions Nimble/Matchers/BeEmpty.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

func beEmpty<S: Sequence>() -> MatcherFunc<S?> {
public func beEmpty<S: Sequence>() -> MatcherFunc<S?> {
return MatcherFunc { actualExpression, failureMessage in
failureMessage.postfixMessage = "be empty"
let actualSeq = actualExpression.evaluate()
Expand All @@ -12,15 +12,15 @@ func beEmpty<S: Sequence>() -> MatcherFunc<S?> {
}
}

func beEmpty() -> MatcherFunc<NSString?> {
public func beEmpty() -> MatcherFunc<NSString?> {
return MatcherFunc { actualExpression, failureMessage in
failureMessage.postfixMessage = "be empty"
let actualString = actualExpression.evaluate()
return actualString == nil || actualString!.length == 0
}
}

func beEmpty() -> MatcherFunc<NMBCollection?> {
public func beEmpty() -> MatcherFunc<NMBCollection?> {
return MatcherFunc { actualExpression, failureMessage in
failureMessage.postfixMessage = "be empty"
let actual = actualExpression.evaluate()
Expand Down
Loading