Skip to content

Commit

Permalink
Merge pull request #647 from Quick/canimport-darwin
Browse files Browse the repository at this point in the history
[refactoring] Use `canImport(Darwin)`
  • Loading branch information
ikesyo authored Apr 12, 2019
2 parents 0246eba + 384c677 commit ca8b130
Show file tree
Hide file tree
Showing 15 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Tests/NimbleTests/Helpers/utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func deferToMainQueue(action: @escaping () -> Void) {
}
}

#if (os(macOS) || os(iOS) || os(tvOS) || os(watchOS)) && !SWIFT_PACKAGE
#if canImport(Darwin) && !SWIFT_PACKAGE
public class NimbleHelper: NSObject {
@objc public class func expectFailureMessage(_ message: NSString, block: () -> Void, file: FileString, line: UInt) {
failsWithErrorMessage(String(describing: message), file: file, line: line, preferOriginalSourceLocation: true, closure: block)
Expand Down
4 changes: 2 additions & 2 deletions Tests/NimbleTests/Matchers/BeAKindOfTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ final class BeAKindOfSwiftTest: XCTestCase, XCTestCaseProvider {

final class BeAKindOfObjCTest: XCTestCase, XCTestCaseProvider {
func testPositiveMatch() {
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
#if canImport(Darwin)
expect(TestNull()).to(beAKindOf(NSNull.self))
expect(NSObject()).to(beAKindOf(NSObject.self))
expect(NSNumber(value: 1)).toNot(beAKindOf(NSDate.self))
#endif
}

func testFailureMessages() {
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
#if canImport(Darwin)
failsWithErrorMessageForNil("expected to not be a kind of NSNull, got <nil>") {
expect(nil as NSNull?).toNot(beAKindOf(NSNull.self))
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/NimbleTests/Matchers/BeAnInstanceOfTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ final class BeAnInstanceOfTest: XCTestCase, XCTestCaseProvider {
failsWithErrorMessageForNil("expected to be an instance of NSString, got <nil>") {
expect(nil as NSString?).to(beAnInstanceOf(NSString.self))
}
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
#if canImport(Darwin)
let numberTypeName = "__NSCFNumber"
#else
let numberTypeName = "NSNumber"
Expand Down
6 changes: 3 additions & 3 deletions Tests/NimbleTests/Matchers/BeEmptyTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ final class BeEmptyTest: XCTestCase, XCTestCaseProvider {
expect([] as Set<Int>).to(beEmpty())
expect([1] as Set<Int>).toNot(beEmpty())

#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
#if canImport(Darwin)
expect(NSDictionary() as? [Int: Int]).to(beEmpty())
expect(NSDictionary(object: 1, forKey: 1 as NSNumber) as? [Int: Int]).toNot(beEmpty())
#endif

expect([Int: Int]()).to(beEmpty())
expect(["hi": 1]).toNot(beEmpty())

#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
#if canImport(Darwin)
expect(NSArray() as? [Int]).to(beEmpty())
expect(NSArray(array: [1]) as? [Int]).toNot(beEmpty())
#endif
Expand Down Expand Up @@ -57,7 +57,7 @@ final class BeEmptyTest: XCTestCase, XCTestCaseProvider {
expect([1] as Set<Int>).to(beEmpty())
}

#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
#if canImport(Darwin)
failsWithErrorMessage("expected to not be empty, got <{()}>") {
expect(NSSet()).toNot(beEmpty())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ final class BeGreaterThanOrEqualToTest: XCTestCase, XCTestCaseProvider {
expect(1).toNot(beGreaterThanOrEqualTo(2))
expect(NSNumber(value: 1)).toNot(beGreaterThanOrEqualTo(2))
expect(NSNumber(value: 2)).to(beGreaterThanOrEqualTo(NSNumber(value: 2)))
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
#if canImport(Darwin)
expect(1).to(beGreaterThanOrEqualTo(NSNumber(value: 0)))
#endif

Expand Down
2 changes: 1 addition & 1 deletion Tests/NimbleTests/Matchers/BeIdenticalToTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ final class BeIdenticalToTest: XCTestCase, XCTestCaseProvider {
let value = NSDate()
expect(value).to(be(value))
expect(NSNumber(value: 1)).toNot(be(NSString(string: "turtles")))
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
#if canImport(Darwin)
expect([1]).toNot(be([1]))
#else
expect(NSArray(array: [NSNumber(value: 1)])).toNot(beIdenticalTo(NSArray(array: [NSNumber(value: 1)])))
Expand Down
2 changes: 1 addition & 1 deletion Tests/NimbleTests/Matchers/BeLessThanOrEqualToTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ final class BeLessThanOrEqualToTest: XCTestCase, XCTestCaseProvider {

expect(NSNumber(value: 2)).to(beLessThanOrEqualTo(10))
expect(NSNumber(value: 2)).toNot(beLessThanOrEqualTo(1))
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
#if canImport(Darwin)
expect(2).to(beLessThanOrEqualTo(NSNumber(value: 10)))
expect(2).toNot(beLessThanOrEqualTo(NSNumber(value: 1)))
#endif
Expand Down
2 changes: 1 addition & 1 deletion Tests/NimbleTests/Matchers/BeginWithTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final class BeginWithTest: XCTestCase, XCTestCaseProvider {
expect(NSString(string: "foobar").description).to(beginWith("foo"))
expect(NSString(string: "foobar").description).toNot(beginWith("oo"))

#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
#if canImport(Darwin)
expect(NSArray(array: ["a", "b"])).to(beginWith("a"))
expect(NSArray(array: ["a", "b"])).toNot(beginWith("b"))
#endif
Expand Down
2 changes: 1 addition & 1 deletion Tests/NimbleTests/Matchers/ContainTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ final class ContainTest: XCTestCase, XCTestCaseProvider {
expect([1, 2, 3] as [CInt]).toNot(contain(4 as CInt))
expect(["foo", "bar", "baz"]).to(contain("baz"))
expect(["foo", "bar", "baz"]).toNot(contain("ba"))
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
#if canImport(Darwin)
expect(NSArray(array: ["a"])).to(contain(NSString(string: "a")))
expect(NSArray(array: ["a"])).toNot(contain(NSString(string: "b")))
expect(NSArray(object: 1) as NSArray?).to(contain(1))
Expand Down
2 changes: 1 addition & 1 deletion Tests/NimbleTests/Matchers/EndWithTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class EndWithTest: XCTestCase, XCTestCaseProvider {
expect(NSString(string: "foobar").description).to(endWith("bar"))
expect(NSString(string: "foobar").description).toNot(endWith("oo"))

#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
#if canImport(Darwin)
expect(NSArray(array: ["a", "b"])).to(endWith("b"))
expect(NSArray(array: ["a", "b"])).toNot(endWith("a"))
expect(NSArray(array: [])).toNot(endWith("a"))
Expand Down
4 changes: 2 additions & 2 deletions Tests/NimbleTests/Matchers/EqualTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ final class EqualTest: XCTestCase, XCTestCaseProvider {
expect(array1).to(equal([1, 2, 3]))
expect(array1).toNot(equal([1, 2] as [Int]))

#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
#if canImport(Darwin)
expect(NSArray(array: [1, 2, 3])).to(equal(NSArray(array: [1, 2, 3])))
#endif

Expand Down Expand Up @@ -119,7 +119,7 @@ final class EqualTest: XCTestCase, XCTestCaseProvider {
expect(actual).to(equal(expected))
expect(actual).toNot(equal(unexpected))

#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
#if canImport(Darwin)
expect(NSDictionary(object: "bar", forKey: "foo" as NSString)).to(equal(["foo": "bar"]))
expect(NSDictionary(object: "bar", forKey: "foo" as NSString) as? [String: String]).to(equal(expected))
#endif
Expand Down
4 changes: 2 additions & 2 deletions Tests/NimbleTests/Matchers/MatchErrorTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ final class MatchErrorTest: XCTestCase, XCTestCaseProvider {
}

func testMatchNSErrorPositive() {
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
#if canImport(Darwin)
let error1 = NSError(domain: "err", code: 0, userInfo: nil)
let error2 = NSError(domain: "err", code: 0, userInfo: nil)

Expand All @@ -45,7 +45,7 @@ final class MatchErrorTest: XCTestCase, XCTestCaseProvider {
expect(CustomDebugStringConvertibleError.a).to(matchError(CustomDebugStringConvertibleError.b))
}

#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
#if canImport(Darwin)
failsWithErrorMessage("expected to match error <Error Domain=err Code=1 \"(null)\">, got <Error Domain=err Code=0 \"(null)\">") {
let error1 = NSError(domain: "err", code: 0, userInfo: nil)
let error2 = NSError(domain: "err", code: 1, userInfo: nil)
Expand Down
2 changes: 1 addition & 1 deletion Tests/NimbleTests/Matchers/PostNotificationTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ final class PostNotificationTest: XCTestCase, XCTestCaseProvider {
}

func testPassesWhenExpectedNotificationEventuallyIsPosted() {
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
#if canImport(Darwin)
let testNotification = Notification(name: Notification.Name("Foo"), object: nil)
expect {
deferToMainQueue {
Expand Down
2 changes: 1 addition & 1 deletion Tests/NimbleTests/Matchers/RaisesExceptionTest.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import XCTest
import Nimble

#if (os(macOS) || os(iOS) || os(tvOS) || os(watchOS)) && !SWIFT_PACKAGE
#if canImport(Darwin) && !SWIFT_PACKAGE

final class RaisesExceptionTest: XCTestCase {
var anException = NSException(name: NSExceptionName("laugh"), reason: "Lulz", userInfo: ["key": "value"])
Expand Down
2 changes: 1 addition & 1 deletion Tests/NimbleTests/Matchers/ThrowAssertionTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Foundation
import XCTest
import Nimble

#if (os(macOS) || os(iOS) || os(tvOS) || os(watchOS)) && !SWIFT_PACKAGE
#if canImport(Darwin) && !SWIFT_PACKAGE

private let error: Error = NSError(domain: "test", code: 0, userInfo: nil)

Expand Down

0 comments on commit ca8b130

Please sign in to comment.