Skip to content

Commit 43ffe7a

Browse files
authored
Merge pull request #264 from CodaFi/futureshock
Try an update to Xcode 9.3
2 parents ae61bed + b6b4bc6 commit 43ffe7a

24 files changed

+89
-550
lines changed

.swift-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4.0
1+
4.1

.travis.yml

+9-18
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ matrix:
55
include:
66
- os: osx
77
language: objective-c
8-
osx_image: xcode9
8+
osx_image: xcode9.3
99
before_install:
1010
- git submodule update --init --recursive
1111
- pushd Utilities
@@ -16,7 +16,7 @@ matrix:
1616
- carthage build --no-skip-current
1717
- os: osx
1818
language: objective-c
19-
osx_image: xcode9
19+
osx_image: xcode9.3
2020
before_install:
2121
- git submodule update --init --recursive
2222
- pushd Utilities
@@ -25,29 +25,20 @@ matrix:
2525
script:
2626
- set -o pipefail
2727
- xcodebuild test -scheme SwiftCheck | xcpretty -c
28-
# -- Start iOS --
29-
# !!!: Make sure desired device name & OS version are suitable for the Xcode version installed on osx_image
30-
- iOS_DEVICE_NAME="iPad Pro (12.9-inch) (2nd generation)"
31-
- iOS_RUNTIME_VERSION="11.0"
32-
# Get simulator identifier for desired device/runtime pair
33-
- SIMULATOR_ID=$(xcrun instruments -s | grep -o "${iOS_DEVICE_NAME} (${iOS_RUNTIME_VERSION}) \[.*\]" | grep -o "\[.*\]" | sed "s/^\[\(.*\)\]$/\1/")
34-
- echo $SIMULATOR_ID
35-
- echo $iOS_DEVICE_NAME
36-
- echo $iOS_RUNTIME_VERSION
37-
- xcodebuild build-for-testing -scheme SwiftCheck-iOS -destination "platform=iOS Simulator,name=${iOS_DEVICE_NAME},OS=${iOS_RUNTIME_VERSION}" | xcpretty -c
38-
- xcodebuild test -scheme SwiftCheck-iOS -destination "platform=iOS Simulator,name=${iOS_DEVICE_NAME},OS=${iOS_RUNTIME_VERSION}" | xcpretty -c
39-
- xcodebuild build-for-testing -scheme SwiftCheck-tvOS -destination 'platform=tvOS Simulator,name=Apple TV 1080p' | xcpretty -c
40-
- xcodebuild test -scheme SwiftCheck-tvOS -destination 'platform=tvOS Simulator,name=Apple TV 1080p' | xcpretty -c
28+
- xcodebuild build-for-testing -scheme SwiftCheck-iOS -destination "platform=iOS Simulator,name=iPad Pro (12.9-inch) (2nd generation)" | xcpretty -c
29+
- xcodebuild test -scheme SwiftCheck-iOS -destination "platform=iOS Simulator,name=iPad Pro (12.9-inch) (2nd generation)" | xcpretty -c
30+
- xcodebuild build-for-testing -scheme SwiftCheck-tvOS -destination 'platform=tvOS Simulator,name=Apple TV 4K (at 1080p)' | xcpretty -c
31+
- xcodebuild test -scheme SwiftCheck-tvOS -destination 'platform=tvOS Simulator,name=Apple TV 4K (at 1080p)' | xcpretty -c
4132
- os: linux
4233
language: generic
4334
sudo: required
4435
dist: trusty
4536
before_install:
4637
- git submodule update --init --recursive
4738
- wget -q -O - https://swift.org/keys/all-keys.asc | gpg --import -
48-
- wget https://swift.org/builds/swift-4.0-release/ubuntu1404/swift-4.0-RELEASE/swift-4.0-RELEASE-ubuntu14.04.tar.gz
49-
- tar xzf swift-4.0-RELEASE-ubuntu14.04.tar.gz
50-
- export PATH=${PWD}/swift-4.0-RELEASE-ubuntu14.04/usr/bin:"${PATH}"
39+
- wget https://swift.org/builds/swift-4.1-release/ubuntu1404/swift-4.1-RELEASE/swift-4.1-RELEASE-ubuntu14.04.tar.gz
40+
- tar xzf swift-4.1-RELEASE-ubuntu14.04.tar.gz
41+
- export PATH=${PWD}/swift-4.1-RELEASE-ubuntu14.04/usr/bin:"${PATH}"
5142
- pushd Utilities
5243
- ./compile.sh
5344
- popd

Package.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:4.0
1+
// swift-tools-version:4.1
22

33
import PackageDescription
44

README.md

+6-9
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,7 @@ For a less contrived example, here is a program property that tests whether
4343
Array identity holds under double reversal:
4444

4545
```swift
46-
// Because Swift doesn't allow us to implement `Arbitrary` for certain types,
47-
// SwiftCheck instead implements 'modifier' types that wrap them. Here,
48-
// `ArrayOf<T : Arbitrary>` generates random arrays of values of type `T`.
49-
property("The reverse of the reverse of an array is that array") <- forAll { (xs : ArrayOf<Int>) in
46+
property("The reverse of the reverse of an array is that array") <- forAll { (xs : [Int]) in
5047
// This property is using a number of SwiftCheck's more interesting
5148
// features. `^&&^` is the conjunction operator for properties that turns
5249
// both properties into a larger property that only holds when both sub-properties
@@ -56,22 +53,22 @@ property("The reverse of the reverse of an array is that array") <- forAll { (xs
5653
// *** Passed 100 tests
5754
// (100% , Right identity, Left identity)
5855
return
59-
(xs.getArray.reverse().reverse() == xs.getArray) <?> "Left identity"
56+
(xs.reverse().reverse() == xs) <?> "Left identity"
6057
^&&^
61-
(xs.getArray == xs.getArray.reverse().reverse()) <?> "Right identity"
58+
(xs == xs.reverse().reverse()) <?> "Right identity"
6259
}
6360
```
6461

6562
Because SwiftCheck doesn't require tests to return `Bool`, just `Testable`, we
6663
can produce tests for complex properties with ease:
6764

6865
```swift
69-
property("Shrunken lists of integers always contain [] or [0]") <- forAll { (l : ArrayOf<Int>) in
66+
property("Shrunken lists of integers always contain [] or [0]") <- forAll { (l : [Int]) in
7067
// Here we use the Implication Operator `==>` to define a precondition for
7168
// this test. If the precondition fails the test is discarded. If it holds
7269
// the test proceeds.
73-
return (!l.getArray.isEmpty && l.getArray != [0]) ==> {
74-
let ls = self.shrinkArbitrary(l).map { $0.getArray }
70+
return (!l.isEmpty && l != [0]) ==> {
71+
let ls = self.shrinkArbitrary(l)
7572
return (ls.filter({ $0 == [] || $0 == [0] }).count >= 1)
7673
}
7774
}

Sources/SwiftCheck/Arbitrary.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
/// implementation of `shrink` is provided, SwiftCheck will default to an empty
2424
/// one - that is, no shrinking will occur.
2525
///
26-
/// As an example, take the `ArrayOf` implementation of shrink:
26+
/// As an example, take `Array`'s implementation of shrink:
2727
///
28-
/// Arbitrary.shrink(ArrayOf([1, 2, 3]))
28+
/// Arbitrary.shrink([1, 2, 3])
2929
/// > [[], [2,3], [1,3], [1,2], [0,2,3], [1,0,3], [1,1,3], [1,2,0], [1,2,2]]
3030
///
3131
/// SwiftCheck will search each case forward, one-by-one, and continue shrinking

Sources/SwiftCheck/Modifiers.swift

+2-171
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,6 @@
3737
/// return xs.map(f.getArrow) == xs.map(f.getArrow)
3838
/// }
3939
/// }
40-
///
41-
/// Finally, modifiers nest to allow the generation of intricate structures that
42-
/// would not otherwise be possible due to the limitations above. For example,
43-
/// to generate an Array of Arrays of Dictionaries of Integers and Strings (a
44-
/// type that normally looks like `Array<Array<Dictionary<String, Int>>>`),
45-
/// would look like this:
46-
///
47-
/// property("Generating monstrous data types is possible") <- forAll { (xs : ArrayOf<ArrayOf<DictionaryOf<String, Int>>>) in
48-
/// /// We're gonna need a bigger boat.
49-
/// }
5040

5141
/// For types that either do not have a `CustomStringConvertible` instance or
5242
/// that wish to have no description to print, Blind will create a default
@@ -115,48 +105,6 @@ extension Static : CoArbitrary {
115105
}
116106
}
117107

118-
/// Generates an array of arbitrary values of type A.
119-
public struct ArrayOf<A : Arbitrary> : Arbitrary, CustomStringConvertible {
120-
/// Retrieves the underlying array of values.
121-
public let getArray : [A]
122-
123-
/// Retrieves the underlying array of values as a contiguous array.
124-
public var getContiguousArray : ContiguousArray<A> {
125-
return ContiguousArray(self.getArray)
126-
}
127-
128-
/// Creates a new `ArrayOf` modifier from an underlying array of values.
129-
public init(_ array : [A]) {
130-
self.getArray = array
131-
}
132-
133-
/// A textual representation of `self`.
134-
public var description : String {
135-
return "\(self.getArray)"
136-
}
137-
138-
/// Returns a generator of `ArrayOf` values.
139-
public static var arbitrary : Gen<ArrayOf<A>> {
140-
return Array<A>.arbitrary.map(ArrayOf.init)
141-
}
142-
143-
/// The default shrinking function for an `ArrayOf` values.
144-
public static func shrink(_ bl : ArrayOf<A>) -> [ArrayOf<A>] {
145-
return Array<A>.shrink(bl.getArray).map(ArrayOf.init)
146-
}
147-
}
148-
149-
extension ArrayOf : CoArbitrary {
150-
/// Uses the underlying array of values to perturb a generator.
151-
public static func coarbitrary<C>(_ x : ArrayOf) -> ((Gen<C>) -> Gen<C>) {
152-
let a = x.getArray
153-
if a.isEmpty {
154-
return { $0.variant(0) }
155-
}
156-
return comp({ $0.variant(1) }, ArrayOf.coarbitrary(ArrayOf([A](a[1..<a.endIndex]))))
157-
}
158-
}
159-
160108
/// Generates a sorted array of arbitrary values of type A.
161109
public struct OrderedArrayOf<A : Arbitrary & Comparable> : Arbitrary, CustomStringConvertible {
162110
/// Retrieves the underlying sorted array of values.
@@ -193,121 +141,6 @@ public struct OrderedArrayOf<A : Arbitrary & Comparable> : Arbitrary, CustomStri
193141
}
194142
}
195143

196-
197-
/// Generates an dictionary of arbitrary keys and values.
198-
public struct DictionaryOf<K : Hashable & Arbitrary, V : Arbitrary> : Arbitrary, CustomStringConvertible {
199-
/// Retrieves the underlying dictionary of values.
200-
public let getDictionary : Dictionary<K, V>
201-
202-
/// Creates a new `DictionaryOf` modifier from an underlying dictionary of
203-
/// key-value pairs.
204-
public init(_ dict : Dictionary<K, V>) {
205-
self.getDictionary = dict
206-
}
207-
208-
/// A textual representation of `self`.
209-
public var description : String {
210-
return "\(self.getDictionary)"
211-
}
212-
213-
/// Returns a generator for a `DictionaryOf` values.
214-
public static var arbitrary : Gen<DictionaryOf<K, V>> {
215-
return Dictionary<K, V>.arbitrary.map(DictionaryOf.init)
216-
}
217-
218-
/// The default shrinking function for a `DictionaryOf` values.
219-
public static func shrink(_ d : DictionaryOf<K, V>) -> [DictionaryOf<K, V>] {
220-
return Dictionary.shrink(d.getDictionary).map(DictionaryOf.init)
221-
}
222-
}
223-
224-
extension DictionaryOf : CoArbitrary {
225-
/// Uses the underlying array of values to perturb a generator.
226-
public static func coarbitrary<C>(_ x : DictionaryOf) -> ((Gen<C>) -> Gen<C>) {
227-
return Dictionary.coarbitrary(x.getDictionary)
228-
}
229-
}
230-
231-
/// Generates an Optional of arbitrary values of type A.
232-
public struct OptionalOf<A : Arbitrary> : Arbitrary, CustomStringConvertible {
233-
/// Retrieves the underlying optional value.
234-
public let getOptional : A?
235-
236-
/// Creates a new `OptionalOf` modifier from an underlying `Optional` value.
237-
public init(_ opt : A?) {
238-
self.getOptional = opt
239-
}
240-
241-
/// A textual representation of `self`.
242-
public var description : String {
243-
return "\(String(describing: self.getOptional))"
244-
}
245-
246-
/// Returns a generator for `OptionalOf` values.
247-
public static var arbitrary : Gen<OptionalOf<A>> {
248-
return Optional<A>.arbitrary.map(OptionalOf.init)
249-
}
250-
251-
/// The default shrinking function for `OptionalOf` values.
252-
public static func shrink(_ bl : OptionalOf<A>) -> [OptionalOf<A>] {
253-
return Optional<A>.shrink(bl.getOptional).map(OptionalOf.init)
254-
}
255-
}
256-
257-
extension OptionalOf : CoArbitrary {
258-
/// Uses the underlying presence or lack of a value to perturb a generator.
259-
public static func coarbitrary<C>(_ x : OptionalOf) -> ((Gen<C>) -> Gen<C>) {
260-
if let _ = x.getOptional {
261-
return { $0.variant(0) }
262-
}
263-
return { $0.variant(1) }
264-
}
265-
}
266-
267-
/// Generates a set of arbitrary values of type A.
268-
public struct SetOf<A : Hashable & Arbitrary> : Arbitrary, CustomStringConvertible {
269-
/// Retrieves the underlying set of values.
270-
public let getSet : Set<A>
271-
272-
/// Creates a new `SetOf` modifier from an underlying set of values.
273-
public init(_ set : Set<A>) {
274-
self.getSet = set
275-
}
276-
277-
/// A textual representation of `self`.
278-
public var description : String {
279-
return "\(self.getSet)"
280-
}
281-
282-
/// Returns a generator for a `SetOf` values.
283-
public static var arbitrary : Gen<SetOf<A>> {
284-
return Gen.sized { n in
285-
return Gen<Int>.choose((0, n)).flatMap { k in
286-
if k == 0 {
287-
return Gen.pure(SetOf(Set([])))
288-
}
289-
290-
return sequence(Array((0...k)).map { _ in A.arbitrary }).map(comp(SetOf.init, Set.init))
291-
}
292-
}
293-
}
294-
295-
/// The default shrinking function for a `SetOf` values.
296-
public static func shrink(_ s : SetOf<A>) -> [SetOf<A>] {
297-
return ArrayOf.shrink(ArrayOf([A](s.getSet))).map({ SetOf(Set($0.getArray)) })
298-
}
299-
}
300-
301-
extension SetOf : CoArbitrary {
302-
/// Uses the underlying set of values to perturb a generator.
303-
public static func coarbitrary<C>(_ x : SetOf) -> ((Gen<C>) -> Gen<C>) {
304-
if x.getSet.isEmpty {
305-
return { $0.variant(0) }
306-
}
307-
return { $0.variant(1) }
308-
}
309-
}
310-
311144
/// Generates pointers of varying size of random values of type T.
312145
public struct PointerOf<T : Arbitrary> : Arbitrary, CustomStringConvertible {
313146
fileprivate let _impl : PointerOfImpl<T>
@@ -663,10 +496,8 @@ private final class PointerOfImpl<T : Arbitrary> : Arbitrary {
663496
}
664497

665498
deinit {
666-
if self.size > 0 && self.ptr != nil {
667-
self.ptr?.deallocate(capacity: self.size)
668-
self.ptr = nil
669-
}
499+
self.ptr?.deallocate()
500+
self.ptr = nil
670501
}
671502

672503
static var arbitrary : Gen<PointerOfImpl<T>> {

Sources/SwiftCheck/Testable.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ extension Bool : Testable {
7979
}
8080
}
8181

82-
extension Gen /*: Testable*/ where A : Testable {
82+
extension Gen : Testable where A : Testable {
8383
public var property : Property {
8484
return Property(self.flatMap { $0.property.unProperty })
8585
}

0 commit comments

Comments
 (0)