Skip to content

Commit

Permalink
Merge pull request #10 from antitypical/swift-2
Browse files Browse the repository at this point in the history
Swift 2
  • Loading branch information
robrix committed Jun 10, 2015
2 parents 472e3ea + e39c4cd commit 91020eb
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 19 deletions.
8 changes: 7 additions & 1 deletion Assertions.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@
D4F1C3EF1A8FE39F0087648A /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0630;
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0700;
ORGANIZATIONNAME = "Rob Rix";
TargetAttributes = {
D4C2EDE01A98DD7D00054FAA = {
Expand Down Expand Up @@ -503,7 +504,9 @@
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_BITCODE = YES;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_OPTIMIZATION_LEVEL = 0;
Expand All @@ -522,6 +525,7 @@
MACOSX_DEPLOYMENT_TARGET = 10.9;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
PRODUCT_BUNDLE_IDENTIFIER = "com.antitypical.$(PRODUCT_NAME:rfc1034identifier)";
SDKROOT = macosx;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
VERSIONING_SYSTEM = "apple-generic";
Expand Down Expand Up @@ -549,6 +553,7 @@
COPY_PHASE_STRIP = YES;
CURRENT_PROJECT_VERSION = 1;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_BITCODE = YES;
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
Expand All @@ -561,6 +566,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MACOSX_DEPLOYMENT_TARGET = 10.9;
MTL_ENABLE_DEBUG_INFO = NO;
PRODUCT_BUNDLE_IDENTIFIER = "com.antitypical.$(PRODUCT_NAME:rfc1034identifier)";
SDKROOT = macosx;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0630"
LastUpgradeVersion = "0700"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -62,6 +62,8 @@
ReferencedContainer = "container:Assertions.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
Expand All @@ -71,6 +73,7 @@
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0630"
LastUpgradeVersion = "0700"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -62,6 +62,8 @@
ReferencedContainer = "container:Assertions.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
Expand All @@ -71,6 +73,7 @@
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
Expand Down
26 changes: 13 additions & 13 deletions Assertions/Assertions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/// This is useful for asserting the equality of collections which only define equality for Equatable element types.
///
/// assert(x, ==, y)
public func assert<T>(@autoclosure expression1: () -> T?, test: (T, T) -> Bool, @autoclosure expression2: () -> T, message: String = "", file: String = __FILE__, line: UInt = __LINE__) -> T? {
public func assert<T>(@autoclosure expression1: () -> T?, _ test: (T, T) -> Bool, @autoclosure _ expression2: () -> T, message: String = "", file: String = __FILE__, line: UInt = __LINE__) -> T? {
return assertExpected(expression1(), test, expression2(), message, file, line)
}

Expand All @@ -16,7 +16,7 @@ public func assert<T>(@autoclosure expression1: () -> T?, test: (T, T) -> Bool,
/// This is useful for asserting the equality of collections which only define equality for Equatable element types.
///
/// assert(x, ==, y)
public func assert<T, U>(@autoclosure expression1: () -> T, test: (T, U) -> Bool, @autoclosure expression2: () -> U, message: String = "", file: String = __FILE__, line: UInt = __LINE__) -> T? {
public func assert<T, U>(@autoclosure expression1: () -> T, _ test: (T, U) -> Bool, @autoclosure _ expression2: () -> U, message: String = "", file: String = __FILE__, line: UInt = __LINE__) -> T? {
return assertExpected(expression1(), test, expression2(), message, file, line)
}

Expand All @@ -25,7 +25,7 @@ public func assert<T, U>(@autoclosure expression1: () -> T, test: (T, U) -> Bool
/// This is useful for asserting that some method applies to the receiver on the left and the operand on the right.
///
/// assert(Set([ 1, 2, 3 ]), Set.contains, 3)
public func assert<T, U>(@autoclosure expression1: () -> T?, test: T -> U -> Bool, @autoclosure expression2: () -> U, message: String = "", file: String = __FILE__, line: UInt = __LINE__) -> T? {
public func assert<T, U>(@autoclosure expression1: () -> T?, _ test: T -> U -> Bool, @autoclosure _ expression2: () -> U, message: String = "", file: String = __FILE__, line: UInt = __LINE__) -> T? {
return assertExpected(expression1(), { x, y in test(x)(y) }, expression2(), message, file, line)
}

Expand All @@ -34,7 +34,7 @@ public func assert<T, U>(@autoclosure expression1: () -> T?, test: T -> U -> Boo
/// This is useful for asserting that a value has some property or other.
///
/// assert("", { $0.isEmpty })
public func assert<T>(@autoclosure expression: () -> T?, message: String = "", file: String = __FILE__, line: UInt = __LINE__, test: T -> Bool) -> T? {
public func assert<T>(@autoclosure expression: () -> T?, message: String = "", file: String = __FILE__, line: UInt = __LINE__, _ test: T -> Bool) -> T? {
return assertPredicate(expression(), test, message, file, line)
}

Expand All @@ -44,23 +44,23 @@ public func assert<T>(@autoclosure expression: () -> T?, message: String = "", f
/// Asserts the equality of two Equatable values.
///
/// Returns the value, if equal and non-nil.
public func assertEqual<T: Equatable>(@autoclosure expression1: () -> T?, @autoclosure expression2: () -> T?, _ message: String = "", _ file: String = __FILE__, _ line: UInt = __LINE__) -> T? {
public func assertEqual<T: Equatable>(@autoclosure expression1: () -> T?, @autoclosure _ expression2: () -> T?, _ message: String = "", _ file: String = __FILE__, _ line: UInt = __LINE__) -> T? {
return assertExpected(expression1(), { $0 == $1 }, expression2(), message, file, line)
}


/// Asserts the equality of two arrays of Equatable values.
///
/// Returns the array, if equal and non-nil.
public func assertEqual<T: Equatable>(@autoclosure expression1: () -> [T]?, @autoclosure expression2: () -> [T]?, _ message: String = "", _ file: String = __FILE__, _ line: UInt = __LINE__) -> [T]? {
public func assertEqual<T: Equatable>(@autoclosure expression1: () -> [T]?, @autoclosure _ expression2: () -> [T]?, _ message: String = "", _ file: String = __FILE__, _ line: UInt = __LINE__) -> [T]? {
return assertExpected(expression1(), ==, expression2(), message, file, line)
}


/// Asserts the equality of two dictionaries of Equatable values.
///
/// Returns the dictionary, if equal and non-nil.
public func assertEqual<T: Hashable, U: Equatable>(@autoclosure expression1: () -> [T: U]?, @autoclosure expression2: () -> [T: U]?, _ message: String = "", _ file: String = __FILE__, _ line: UInt = __LINE__) -> [T: U]? {
public func assertEqual<T: Hashable, U: Equatable>(@autoclosure expression1: () -> [T: U]?, @autoclosure _ expression2: () -> [T: U]?, _ message: String = "", _ file: String = __FILE__, _ line: UInt = __LINE__) -> [T: U]? {
return assertExpected(expression1(), ==, expression2(), message, file, line)
}

Expand All @@ -69,7 +69,7 @@ public func assertEqual<T: Hashable, U: Equatable>(@autoclosure expression1: ()

/// Asserts that a value is nil.
public func assertNil<T>(@autoclosure expression: () -> T?, _ message: String = "", file: String = __FILE__, line: UInt = __LINE__) -> Bool {
return expression().map { failure("\(toDebugString($0)) is not nil. " + message, file: file, line: line) } ?? true
return expression().map { failure("\(String(reflecting: $0)) is not nil. " + message, file: file, line: line) } ?? true
}

/// Asserts that a value is not nil.
Expand Down Expand Up @@ -99,7 +99,7 @@ public func failure(message: String, file: String = __FILE__, line: UInt = __LIN

// MARK: - Implementation details

private func assertPredicate<T>(actual: T?, predicate: T -> Bool, message: String, file: String, line: UInt) -> T? {
private func assertPredicate<T>(actual: T?, _ predicate: T -> Bool, _ message: String, _ file: String, _ line: UInt) -> T? {
switch actual {
case let .Some(x) where predicate(x):
return actual
Expand All @@ -108,18 +108,18 @@ private func assertPredicate<T>(actual: T?, predicate: T -> Bool, message: Strin
}
}

private func assertExpected<T, U>(actual: T?, match: (T, U) -> Bool, expected: U?, message: String, file: String, line: UInt) -> T? {
private func assertExpected<T, U>(actual: T?, _ match: (T, U) -> Bool, _ expected: U?, _ message: String, _ file: String, _ line: UInt) -> T? {
switch (actual, expected) {
case (.None, .None):
return actual
case let (.Some(x), .Some(y)) where match(x, y):
return actual
case let (.Some(x), .Some(y)):
return failure("\(toDebugString(x)) did not match \(toDebugString(y)). " + message, file: file, line: line)
return failure("\(String(reflecting: x)) did not match \(String(reflecting: y)). " + message, file: file, line: line)
case let (.Some(x), .None):
return failure("\(toDebugString(x)) did not match nil. " + message, file: file, line: line)
return failure("\(String(reflecting: x)) did not match nil. " + message, file: file, line: line)
case let (.None, .Some(y)):
return failure("nil did not match \(toDebugString(y)). " + message, file: file, line: line)
return failure("nil did not match \(String(reflecting: y)). " + message, file: file, line: line)
}
}

Expand Down
2 changes: 1 addition & 1 deletion Assertions/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>com.antitypical.$(PRODUCT_NAME:rfc1034identifier)</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand Down
4 changes: 2 additions & 2 deletions AssertionsTests/AssertionsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ final class AssertionsTests: XCTestCase {
// MARK: Testing assertion failures

/// Assert that `test` causes an assertion failure.
func assertFailure(file: String = __FILE__, line: UInt = __LINE__, @noescape _ test: () -> ()) -> (message: String, file: String, line: UInt, expected: Bool)? {
func assertFailure<T>(file: String = __FILE__, line: UInt = __LINE__, @noescape _ test: () -> T) -> (message: String, file: String, line: UInt, expected: Bool)? {
let previous = expectFailure
expectFailure = true
test()
Expand All @@ -104,7 +104,7 @@ final class AssertionsTests: XCTestCase {
private var expectFailure: Bool = false
private var failure: (message: String, file: String, line: UInt, expected: Bool)? = nil

override func recordFailureWithDescription(message: String!, inFile file: String!, atLine line: UInt, expected: Bool) {
override func recordFailureWithDescription(message: String, inFile file: String, atLine line: UInt, expected: Bool) {
if expectFailure {
failure = (message: message, file: file, line: line, expected: expected)
} else {
Expand Down

0 comments on commit 91020eb

Please sign in to comment.