├── .gitattributes ├── .gitignore ├── LICENSE.txt ├── Package.resolved ├── Package.swift ├── QuickSwiftCheck.podspec ├── README.md └── Sources ├── It.swift └── To.swift /.gitattributes: -------------------------------------------------------------------------------- 1 | # .gitattributes 2 | # Copyright © 2020 Adrian Kashivskyy. All rights reserved. 3 | 4 | Package.swift linguist-detectable=false 5 | Package.resolved linguist-detectable=false 6 | 7 | QuickSwiftCheck.podspec linguist-detectable=false 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # .gitignore 2 | # Copyright © 2020 Adrian Kashivskyy. All rights reserved. 3 | 4 | .DS_Store 5 | .Trashes 6 | .localized 7 | 8 | xcuserdata 9 | *.mode1v3 10 | *.mode2v3 11 | *.perspectivev3 12 | *.pbxuser 13 | *.xccheckout 14 | *.xcscmblueprint 15 | *.xcuserstate 16 | *.xctimeline 17 | *.moved-aside 18 | *.hmap 19 | *.o 20 | *.ipa 21 | *.dSYM.zip 22 | 23 | .build 24 | .swiftpm 25 | 26 | Pods 27 | Carthage 28 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright © 2020 Adrian Kashivskyy. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Package.resolved: -------------------------------------------------------------------------------- 1 | { 2 | "object": { 3 | "pins": [ 4 | { 5 | "package": "Chalk", 6 | "repositoryURL": "https://github.com/mxcl/Chalk.git", 7 | "state": { 8 | "branch": null, 9 | "revision": "9aa9f348b86db3cf6702a3e43c081ecec80cf3c7", 10 | "version": "0.4.0" 11 | } 12 | }, 13 | { 14 | "package": "CwlCatchException", 15 | "repositoryURL": "https://github.com/mattgallagher/CwlCatchException.git", 16 | "state": { 17 | "branch": null, 18 | "revision": "f809deb30dc5c9d9b78c872e553261a61177721a", 19 | "version": "2.0.0" 20 | } 21 | }, 22 | { 23 | "package": "CwlPreconditionTesting", 24 | "repositoryURL": "https://github.com/mattgallagher/CwlPreconditionTesting.git", 25 | "state": { 26 | "branch": null, 27 | "revision": "0630439888c94657a235ffcd5977d6047ef3c87b", 28 | "version": "2.0.1" 29 | } 30 | }, 31 | { 32 | "package": "FileCheck", 33 | "repositoryURL": "https://github.com/llvm-swift/FileCheck.git", 34 | "state": { 35 | "branch": null, 36 | "revision": "0dc8a5bff1a7f01e1d7bcc20c79e2127b2ea3eeb", 37 | "version": "0.2.5" 38 | } 39 | }, 40 | { 41 | "package": "Nimble", 42 | "repositoryURL": "https://github.com/Quick/Nimble", 43 | "state": { 44 | "branch": null, 45 | "revision": "c93f16c25af5770f0d3e6af27c9634640946b068", 46 | "version": "9.2.1" 47 | } 48 | }, 49 | { 50 | "package": "Quick", 51 | "repositoryURL": "https://github.com/Quick/Quick", 52 | "state": { 53 | "branch": null, 54 | "revision": "f9d519828bb03dfc8125467d8f7b93131951124c", 55 | "version": "5.0.1" 56 | } 57 | }, 58 | { 59 | "package": "swift-argument-parser", 60 | "repositoryURL": "https://github.com/apple/swift-argument-parser", 61 | "state": { 62 | "branch": null, 63 | "revision": "92646c0cdbaca076c8d3d0207891785b3379cbff", 64 | "version": "0.3.1" 65 | } 66 | }, 67 | { 68 | "package": "SwiftCheck", 69 | "repositoryURL": "https://github.com/typelift/SwiftCheck", 70 | "state": { 71 | "branch": null, 72 | "revision": "077c096c3ddfc38db223ac8e525ad16ffb987138", 73 | "version": "0.12.0" 74 | } 75 | } 76 | ] 77 | }, 78 | "version": 1 79 | } 80 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:5.0 2 | // Package.swift 3 | // Copyright © 2020 Adrian Kashivskyy. All rights reserved. 4 | 5 | import PackageDescription 6 | 7 | let package = Package( 8 | name: "QuickSwiftCheck", 9 | platforms: [ 10 | .macOS(.v10_10), .iOS(.v9), .tvOS(.v9), 11 | ], 12 | products: [ 13 | .library(name: "QuickSwiftCheck", targets: ["QuickSwiftCheck"]), 14 | ], 15 | dependencies: [ 16 | .package(url: "https://github.com/Quick/Nimble", from: "9.0.0"), 17 | .package(url: "https://github.com/Quick/Quick", from: "5.0.0"), 18 | .package(url: "https://github.com/typelift/SwiftCheck", from: "0.12.0"), 19 | ], 20 | targets: [ 21 | .target( 22 | name: "QuickSwiftCheck", 23 | dependencies: ["Nimble", "Quick", "SwiftCheck"], 24 | path: "Sources" 25 | ) 26 | ] 27 | ) 28 | -------------------------------------------------------------------------------- /QuickSwiftCheck.podspec: -------------------------------------------------------------------------------- 1 | # QuickSwiftCheck.podspec 2 | # Copyright © 2020 Adrian Kashivskyy. All rights reserved. 3 | 4 | Pod::Spec.new do |spec| 5 | 6 | spec.name = 'QuickSwiftCheck' 7 | spec.version = '3.4.0' 8 | spec.summary = 'Quick + Nimble + SwiftCheck' 9 | spec.homepage = 'https://github.com/akashivskyy/quick-swift-check' 10 | 11 | spec.authors = 'Adrian Kashivskyy' 12 | spec.social_media_url = 'https://twitter.com/akashivskyy' 13 | 14 | spec.license = { 15 | type: 'MIT', 16 | file: 'LICENSE.txt' 17 | } 18 | 19 | spec.source = { 20 | git: 'https://github.com/akashivskyy/quick-swift-check.git', 21 | tag: spec.version.to_s 22 | } 23 | 24 | spec.source_files = 'Sources' 25 | 26 | spec.dependency 'Nimble', '~> 9.0' 27 | spec.dependency 'Quick', '~> 5.0' 28 | spec.dependency 'SwiftCheck', '~> 0.12' 29 | 30 | spec.frameworks = 'XCTest' 31 | 32 | spec.swift_version = '5.0' 33 | spec.requires_arc = true 34 | 35 | spec.osx.deployment_target = '10.10' 36 | spec.ios.deployment_target = '9.0' 37 | spec.tvos.deployment_target = '9.0' 38 | 39 | spec.deprecated = true 40 | spec.deprecated_in_favor_of = 'Swift Package Manager' 41 | 42 | end 43 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # QuickSwiftCheck 2 | 3 | [![](https://img.shields.io/github/release/akashivskyy/quick-swift-check.svg)](https://github.com/akashivskyy/quick-swift-check/releases) 4 | [![](https://img.shields.io/badge/swiftpm-compatible-green.svg)](https://github.com/apple/swift-package-manager) 5 | [![](https://img.shields.io/badge/cocoapods-deprecated-red.svg)](https://cocoapods.org) 6 | 7 | Interoperability between [Quick](https://github.com/Quick/Quick), [Nimble](https://github.com/Quick/Nimble) and [SwiftCheck](https://github.com/typelift/SwiftCheck). 8 | 9 | ## Warning 10 | 11 | **This project is no longer maintained. Please fork this repository if you want to make changes or reach out to me if you're interested in taking it over.** 12 | 13 | ## Requirements 14 | 15 | QuickSwiftCheck supports **iOS 9.0+**, **macOS 10.10+**, **tvOS 9.0+** and **Linux**. 16 | 17 | ## Usage 18 | 19 | QuickSwiftCheck adds `sc_` variants to `it`, `fit`, `xit`, `to` and `toNot` functions, so that the original functions remain not overloaded. This means you can use `it` to create a regular test example and `to` to create a regular expectation: 20 | 21 | ```swift 22 | it("integer addition is commutative") { 23 | expect(2 + 3).to(equal(3 + 2)) 24 | } 25 | ``` 26 | 27 | ```swift 28 | sc_it("integer addition is commutative") { 29 | forAll { (a: Int, b: Int) in 30 | expect(a + b).sc_to(equal(b + a)) 31 | } 32 | } 33 | ``` 34 | 35 | ## Installation 36 | 37 | In Xcode, select File → Add Packages and use the on-screen UI to search for the following Package URL: 38 | 39 | ```none 40 | https://github.com/akashivskyy/quick-swift-check 41 | ``` 42 | 43 | If you're using [Swift Package Manager](https://github.com/apple/swift-package-manager) directly, add the following dependency to your `Package.swift`: 44 | 45 | ```none 46 | .package(url: "https://github.com/akashivskyy/quick-swift-check", from: "X.Y.Z"), 47 | ``` 48 | 49 | ## Roadmap 50 | 51 | #### Version 3.x 52 | 53 | These minor releases will keep QuickSwiftCheck up-to-date with latest versions of Quick, Nimble, SwiftCheck and Swift itself. 54 | 55 | ## About 56 | 57 | This project is made and maintained with ♡ by [Adrian Kashivskyy](https://github.com/akashivskyy). 58 | 59 | ### License 60 | 61 | The project is licensed under the [MIT License](LICENSE.txt). 62 | -------------------------------------------------------------------------------- /Sources/It.swift: -------------------------------------------------------------------------------- 1 | // It.swift 2 | // Copyright © 2020 Adrian Kashivskyy. All rights reserved. 3 | 4 | import Quick 5 | import SwiftCheck 6 | 7 | /// Wrap a SwiftCheck `Property` in a Quick example. This makes it possible to 8 | /// write property tests inside Quick specs. 9 | /// 10 | /// ``` 11 | /// sc_it("integer addition is commutative") { 12 | /// forAll { (a: Int, b: Int) in 13 | /// expect(a + b).sc_to(equal(b + a)) 14 | /// } 15 | /// } 16 | /// ``` 17 | /// 18 | /// - Parameters: 19 | /// - description: Description of the example. 20 | /// - arguments: Checker arguments for replaying tests. 21 | /// - flags: Flags to filter examples or example groups. 22 | /// - closure: Closure containing a property test. 23 | public func sc_it(_ description: String, arguments: CheckerArguments? = nil, file: StaticString = #file, line: UInt = #line, _ closure: @escaping () -> Property) { 24 | #if SWIFT_PACKAGE 25 | it(description, file: file, line: line) { 26 | property(description, arguments: arguments, file: file, line: line) <- closure() 27 | } 28 | #else 29 | it(description, file: String(describing: file), line: line) { 30 | property(description, arguments: arguments, file: file, line: line) <- closure() 31 | } 32 | #endif 33 | } 34 | 35 | /// Wrap a SwiftCheck `Property` in a focused Quick example. This makes it 36 | /// possible to write property tests inside Quick specs. 37 | public func sc_fit(_ description: String, arguments: CheckerArguments? = nil, file: StaticString = #file, line: UInt = #line, _ closure: @escaping () -> Property) { 38 | #if SWIFT_PACKAGE 39 | fit(description, file: file, line: line) { 40 | property(description, arguments: arguments, file: file, line: line) <- closure() 41 | } 42 | #else 43 | fit(description, file: String(describing: file), line: line) { 44 | property(description, arguments: arguments, file: file, line: line) <- closure() 45 | } 46 | #endif 47 | } 48 | 49 | /// Wrap a SwiftCheck `Property` in a pending Quick example. This makes it 50 | /// possible to write property tests inside Quick specs. 51 | public func sc_xit(_ description: String, arguments: CheckerArguments? = nil, file: StaticString = #file, line: UInt = #line, _ closure: @escaping () -> Property) { 52 | #if SWIFT_PACKAGE 53 | xit(description, file: file, line: line) { 54 | property(description, arguments: arguments, file: file, line: line) <- closure() 55 | } 56 | #else 57 | xit(description, file: String(describing: file), line: line) { 58 | property(description, arguments: arguments, file: file, line: line) <- closure() 59 | } 60 | #endif 61 | } 62 | -------------------------------------------------------------------------------- /Sources/To.swift: -------------------------------------------------------------------------------- 1 | // To.swift 2 | // Copyright © 2020 Adrian Kashivskyy. All rights reserved. 3 | 4 | import Nimble 5 | import SwiftCheck 6 | 7 | extension Expectation { 8 | 9 | /// Evaluate the given `predicate` with the expected expression and wrap 10 | /// the result in a SwiftCheck `Testable`. This makes it possible to use 11 | /// Nimble matchers inside a property test. 12 | public func sc_to(_ predicate: Predicate, description: String? = nil) -> Testable { 13 | testable(predicate: predicate, description: description, style: .toMatch, to: "to") 14 | } 15 | 16 | /// Evaluate the given `predicate` with the expected expression and wrap 17 | /// the result in a SwiftCheck `Testable`. This makes it possible to use 18 | /// Nimble matchers inside a property test. 19 | public func sc_toNot(_ predicate: Predicate, description: String? = nil) -> Testable { 20 | testable(predicate: predicate, description: description, style: .toNotMatch, to: "to not") 21 | } 22 | 23 | /// Create `Testable` result by evaluating the expectation with the given 24 | /// `predicate`, user `description` and `style`. 25 | private func testable(predicate: Predicate, description: String?, style: ExpectationStyle, to: String) -> TestResult { 26 | do { 27 | let result = try predicate.satisfies(expression) 28 | if result.toBoolean(expectation: style) { 29 | return .succeeded 30 | } else { 31 | let actual = try "<\(stringify(expression.evaluate()))>" 32 | if let description = description, !description.isEmpty { 33 | return .failed("\(description); " + result.message.toString(actual: actual, to: to)) 34 | } else { 35 | return .failed(result.message.toString(actual: actual, to: to)) 36 | } 37 | } 38 | } catch { 39 | return .failed("unexpected error thrown: <\(error)>") 40 | } 41 | } 42 | 43 | } 44 | --------------------------------------------------------------------------------