Commit 4b2f1067 authored by Drew's avatar Drew

Update for Swift 3 Final

* Fix diagnostics
* Remove Swift2 code (close #2)
* Bump version to 1.0
parent 55caa8a8
Pipeline #2614 failed with stages
in 14 minutes and 20 seconds
...@@ -19,12 +19,10 @@ import Glibc ...@@ -19,12 +19,10 @@ import Glibc
#endif #endif
protocol CarolineEngine { protocol CarolineEngine {
@warn_unused_result
func testAll(_ tests: [CarolineTest]) -> Bool func testAll(_ tests: [CarolineTest]) -> Bool
} }
public class CarolineCoreEngine : CarolineEngine { public class CarolineCoreEngine : CarolineEngine {
@warn_unused_result
public func testAll(_ tests: [CarolineTest]) -> Bool { public func testAll(_ tests: [CarolineTest]) -> Bool {
setvbuf(stdout, nil, _IOLBF, 0) setvbuf(stdout, nil, _IOLBF, 0)
for test in tests { for test in tests {
......
...@@ -13,8 +13,7 @@ ...@@ -13,8 +13,7 @@
// limitations under the License. // limitations under the License.
//MARK: Functions //MARK: Functions
#if swift(>=3.0) private func compare<T: Sequence>(_ a: T, _ b: T) -> Bool where T.Iterator.Element: Equatable {
private func compare<T: Sequence where T.Iterator.Element: Equatable>(_ a: T, _ b: T) -> Bool {
var iteratorB = b.makeIterator() var iteratorB = b.makeIterator()
for itemA in a { for itemA in a {
let itemB = iteratorB.next() let itemB = iteratorB.next()
...@@ -26,20 +25,6 @@ private func compare<T: Sequence where T.Iterator.Element: Equatable>(_ a: T, _ ...@@ -26,20 +25,6 @@ private func compare<T: Sequence where T.Iterator.Element: Equatable>(_ a: T, _
if let _ = iteratorB.next() { return false } if let _ = iteratorB.next() { return false }
return true return true
} }
#else
private func compare<T: SequenceType where T.Generator.Element: Equatable>(_ a: T, _ b: T) -> Bool {
var iteratorB = b.generate()
for itemA in a {
let itemB = iteratorB.next()
if itemB != itemA {
return false
}
}
//We've concluded iterating A. Did B have more elements?
if let _ = iteratorB.next() { return false }
return true
}
#endif
private func compareDict<K: Equatable, V: Equatable> (_ a: [K:V], _ b: [K:V]) -> Bool { private func compareDict<K: Equatable, V: Equatable> (_ a: [K:V], _ b: [K:V]) -> Bool {
if a.count != b.count { return false } if a.count != b.count { return false }
...@@ -64,7 +49,6 @@ extension CarolineTest { ...@@ -64,7 +49,6 @@ extension CarolineTest {
state.commit() state.commit()
} }
#if swift(>=3.0)
///Assert a boolean expression ///Assert a boolean expression
///- parameter condition: A condition to assert ///- parameter condition: A condition to assert
///- message: A reason for failure ///- message: A reason for failure
...@@ -73,18 +57,9 @@ extension CarolineTest { ...@@ -73,18 +57,9 @@ extension CarolineTest {
self.fail(message(), file: file, line: line) self.fail(message(), file: file, line: line)
} }
} }
#else
///- noindex: true
public final func assert(@autoclosure _ condition: () -> Bool, @autoclosure _ message: () -> String = "Assertion failed", file: String = #file, line: Int = #line) {
if !condition() {
self.fail(message(), file: file, line: line)
}
}
#endif
//Equatable and SequenceType<Equatable> //Equatable and SequenceType<Equatable>
#if swift(>=3.0)
///Assert that two objects are equal ///Assert that two objects are equal
///- parameter message: A reason for failure ///- parameter message: A reason for failure
public final func assert<T: Equatable>(_ a: T, equals b: T, _ message: @autoclosure () -> String = "Assertion failed", file: String = #file, line: Int = #line) { public final func assert<T: Equatable>(_ a: T, equals b: T, _ message: @autoclosure () -> String = "Assertion failed", file: String = #file, line: Int = #line) {
...@@ -101,14 +76,14 @@ extension CarolineTest { ...@@ -101,14 +76,14 @@ extension CarolineTest {
} }
///Assert that two sequences are equal ///Assert that two sequences are equal
///- parameter message: A reason for failure ///- parameter message: A reason for failure
public final func assert<T:Sequence where T.Iterator.Element: Equatable>(_ a: T, equals b: T, _ message: @autoclosure () -> String = "Assertion failed", file: String = #file, line: Int = #line) { public final func assert<T:Sequence>(_ a: T, equals b: T, _ message: @autoclosure () -> String = "Assertion failed", file: String = #file, line: Int = #line) where T.Iterator.Element: Equatable {
if !compare(a,b) { if !compare(a,b) {
self.fail("\(message()) - \(cdump(a)) != \(cdump(b))", file: file, line: line) self.fail("\(message()) - \(cdump(a)) != \(cdump(b))", file: file, line: line)
} }
} }
///Assert that two sequences aren't equal ///Assert that two sequences aren't equal
///- parameter message: A reason for failure ///- parameter message: A reason for failure
public final func assert<T:Sequence where T.Iterator.Element: Equatable>(_ a: T, notEqual b: T, _ message: @autoclosure () -> String = "Assertion failed", file: String = #file, line: Int = #line) { public final func assert<T:Sequence>(_ a: T, notEqual b: T, _ message: @autoclosure () -> String = "Assertion failed", file: String = #file, line: Int = #line) where T.Iterator.Element: Equatable {
if compare(a,b) { if compare(a,b) {
self.fail("\(message()) - \(cdump(a)) == \(cdump(b))", file: file, line: line) self.fail("\(message()) - \(cdump(a)) == \(cdump(b))", file: file, line: line)
} }
...@@ -116,7 +91,7 @@ extension CarolineTest { ...@@ -116,7 +91,7 @@ extension CarolineTest {
///Assert that two dictionaries are equal ///Assert that two dictionaries are equal
///- parameter mesage: A reason for failure ///- parameter mesage: A reason for failure
public final func assert<K,V where K: Equatable, V: Equatable>(_ a: [K:V], equals b: [K:V], _ message: @autoclosure () -> String = "Assertion failed", file: String = #file, line: Int = #line) { public final func assert<K,V>(_ a: [K:V], equals b: [K:V], _ message: @autoclosure () -> String = "Assertion failed", file: String = #file, line: Int = #line) where K: Equatable, V: Equatable {
if !compareDict(a,b) { if !compareDict(a,b) {
self.fail("\(message()) - \(cdump(a)) != \(cdump(b))", file: file, line: line) self.fail("\(message()) - \(cdump(a)) != \(cdump(b))", file: file, line: line)
} }
...@@ -124,55 +99,13 @@ extension CarolineTest { ...@@ -124,55 +99,13 @@ extension CarolineTest {
///Assert that two dictionaries aren't equal ///Assert that two dictionaries aren't equal
///- parameter mesage: A reason for failure ///- parameter mesage: A reason for failure
public final func assert<K,V where K: Equatable, V: Equatable>(_ a: [K:V], notEqual b: [K:V], _ message: @autoclosure () -> String = "Assertion failed", file: String = #file, line: Int = #line) { public final func assert<K,V>(_ a: [K:V], notEqual b: [K:V], _ message: @autoclosure () -> String = "Assertion failed", file: String = #file, line: Int = #line) where K: Equatable, V: Equatable {
if compareDict(a,b) {
self.fail("\(message()) - \(cdump(a)) == \(cdump(b))", file: file, line: line)
}
}
#else
///- noindex: true
public final func assert<T: Equatable>(_ a: T, equals b: T, @autoclosure _ message: () -> String = "Assertion failed", file: String = #file, line: Int = #line) {
if a != b {
self.fail("\(message()) - \(cdump(a)) != \(cdump(b))", file: file, line: line)
}
}
///- noindex: true
public final func assert<T: Equatable>(_ a: T, notEqual b: T, @autoclosure _ message: () -> String = "Assertion failed", file: String = #file, line: Int = #line) {
if a == b {
self.fail("\(message()) - \(cdump(a)) == \(cdump(b))", file: file, line: line)
}
}
///- noindex: true
public final func assert<T:SequenceType where T.Generator.Element: Equatable>(_ a: T, equals b: T, @autoclosure _ message: () -> String = "Assertion failed", file: String = #file, line: Int = #line) {
if !compare(a,b) {
self.fail("\(message()) - \(cdump(a)) != \(cdump(b))", file: file, line: line)
}
}
///- noindex: true
public final func assert<T:SequenceType where T.Generator.Element: Equatable>(_ a: T, notEqual b: T, @autoclosure _ message: () -> String = "Assertion failed", file: String = #file, line: Int = #line) {
if compare(a,b) {
self.fail("\(message()) - \(cdump(a)) == \(cdump(b))", file: file, line: line)
}
}
///- noindex: true
public final func assert<K,V where K: Equatable, V: Equatable>(_ a: [K:V], equals b: [K:V], @autoclosure _ message: () -> String = "Assertion failed", file: String = #file, line: Int = #line) {
if !compareDict(a,b) {
self.fail("\(message()) - \(cdump(a)) != \(cdump(b))", file: file, line: line)
}
}
///- noindex: true
public final func assert<K,V where K: Equatable, V: Equatable>(_ a: [K:V], notEqual b: [K:V], @autoclosure _ message: () -> String = "Assertion failed", file: String = #file, line: Int = #line) {
if compareDict(a,b) { if compareDict(a,b) {
self.fail("\(message()) - \(cdump(a)) == \(cdump(b))", file: file, line: line) self.fail("\(message()) - \(cdump(a)) == \(cdump(b))", file: file, line: line)
} }
} }
#endif
#if swift(>=3.0)
///Assert that the passed closure doesn't throw ///Assert that the passed closure doesn't throw
///- returns: nil if the calling closure throws, otherwise the return value. ///- returns: nil if the calling closure throws, otherwise the return value.
///It's not okay to force-unwrap this, use a construction like ///It's not okay to force-unwrap this, use a construction like
...@@ -186,18 +119,6 @@ extension CarolineTest { ...@@ -186,18 +119,6 @@ extension CarolineTest {
return nil return nil
} }
} }
#else
///- noindex: true
public final func dontThrow<T>(@autoclosure _ message: () -> String = "Unexpectedly threw", file: String = #file, line: Int = #line, closure: () throws -> T) -> T? {
do {
return try closure()
}
catch {
self.fail(message() + "\(error)", file: file, line: line)
return nil
}
}
#endif
} }
......
(package (package
:name "Caroline" :name "Caroline"
:version "1.0-beta1" :version "1.0"
:external-packages [ :external-packages [
{ {
:version [">=0.1"] :version [">=0.1"]
......
...@@ -117,7 +117,6 @@ func parseXcodeProj(_ fileName: String, targetName: String) -> [String] { ...@@ -117,7 +117,6 @@ func parseXcodeProj(_ fileName: String, targetName: String) -> [String] {
var pbxBuildRefToGroupPath: [String:String] = [:] var pbxBuildRefToGroupPath: [String:String] = [:]
for group in groupRegex.findAll(inString: allGroups) { for group in groupRegex.findAll(inString: allGroups) {
let childSection = try! groupChildSectionRegex.findFirst(inString: group.entireMatch.description)! let childSection = try! groupChildSectionRegex.findFirst(inString: group.entireMatch.description)!
("got child section",childSection)
guard let path = try! pathRegex.findFirst(inString: group.entireMatch.description) else { guard let path = try! pathRegex.findFirst(inString: group.entireMatch.description) else {
continue continue
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment