Skip to content

Commit

Permalink
Merge pull request #20 from DenHeadless/master
Browse files Browse the repository at this point in the history
Migrate to Swift 2.2, get almost everything to compile
  • Loading branch information
atermenji committed Apr 4, 2016
2 parents 0740f2f + d7528db commit 9ec3e6d
Show file tree
Hide file tree
Showing 34 changed files with 223 additions and 213 deletions.
5 changes: 4 additions & 1 deletion Sample/Sample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@
31BCD715196AF43A0023B154 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0600;
LastSwiftMigration = 0730;
LastSwiftUpdateCheck = 0730;
LastUpgradeCheck = 0730;
ORGANIZATIONNAME = Railsware;
TargetAttributes = {
31BCD71C196AF43A0023B154 = {
Expand Down Expand Up @@ -160,6 +162,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_OPTIMIZATION_LEVEL = 0;
Expand Down
4 changes: 2 additions & 2 deletions Sample/Sample/Library.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ class Library {
return size() > 0
}

func filterBy(#author: String) -> [Book] {
func filterBy(author author: String) -> [Book] {
return books.filter { $0.author == author }
}

func filterBy(#title: String) -> [Book] {
func filterBy(title title: String) -> [Book] {
return books.filter {
$0.title.rangeOfString(title) != nil
}
Expand Down
4 changes: 2 additions & 2 deletions Sample/Sample/LibrarySpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class LibrarySpec : SleipnirSpec {
swiftBook = Book(title: "Introduction to Swift", author: "Apple Inc.")
}

itShouldBehaveLike("a non-nil object", { ["object" : swiftBook] })
itShouldBehaveLike("a non-nil object", sharedContext: { ["object" : swiftBook] })

it("has title") {
expect(swiftBook!.title).to(equal("Introduction to Swift"))
Expand All @@ -51,7 +51,7 @@ class LibrarySpec : SleipnirSpec {
swiftLibrary = nil
}

itShouldBehaveLike("a non-nil object", { ["object" : swiftLibrary] })
itShouldBehaveLike("a non-nil object", sharedContext: { ["object" : swiftLibrary] })

describe("empty") {
it("has no books") {
Expand Down
2 changes: 1 addition & 1 deletion Sleipnir/Sleipnir-OSX/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.railsware.${PRODUCT_NAME:rfc1034identifier}</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand Down
2 changes: 1 addition & 1 deletion Sleipnir/Sleipnir-iOS/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.railsware.${PRODUCT_NAME:rfc1034identifier}</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand Down
9 changes: 8 additions & 1 deletion Sleipnir/Sleipnir.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,9 @@
46718B4E194B6A2C006E8A18 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0600;
LastSwiftMigration = 0730;
LastSwiftUpdateCheck = 0730;
LastUpgradeCheck = 0730;
ORGANIZATIONNAME = railsware;
TargetAttributes = {
314AE5C0196D78DA00CA7ED7 = {
Expand Down Expand Up @@ -901,6 +903,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
METAL_ENABLE_DEBUG_INFO = YES;
PRODUCT_BUNDLE_IDENTIFIER = "com.railsware.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_MODULE_NAME = Sleipnir;
PRODUCT_NAME = Sleipnir;
SDKROOT = iphoneos;
Expand All @@ -925,6 +928,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
METAL_ENABLE_DEBUG_INFO = NO;
PRODUCT_BUNDLE_IDENTIFIER = "com.railsware.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_MODULE_NAME = Sleipnir;
PRODUCT_NAME = Sleipnir;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -954,6 +958,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
METAL_ENABLE_DEBUG_INFO = YES;
PRODUCT_BUNDLE_IDENTIFIER = "com.railsware.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_MODULE_NAME = Sleipnir;
PRODUCT_NAME = Sleipnir;
SKIP_INSTALL = YES;
Expand All @@ -976,6 +981,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
METAL_ENABLE_DEBUG_INFO = NO;
PRODUCT_BUNDLE_IDENTIFIER = "com.railsware.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_MODULE_NAME = Sleipnir;
PRODUCT_NAME = Sleipnir;
SKIP_INSTALL = YES;
Expand Down Expand Up @@ -1003,6 +1009,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_OPTIMIZATION_LEVEL = 0;
Expand Down
6 changes: 3 additions & 3 deletions Sleipnir/Sleipnir/Examples/Example.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,16 @@ class Example : ExampleBase {
}

public func it(label: String, block: SleipnirBlock?) {
var example = Example(label, block)
let example = Example(label, block)
SpecTable.handleExample(example)
}

public func fit(label: String, block: SleipnirBlock) {
var example = Example(label, block)
let example = Example(label, block)
example.focused = true
SpecTable.handleExample(example)
}

public func xit(label: String, block: SleipnirBlock) {
it(label, PENDING)
it(label, block: PENDING)
}
5 changes: 2 additions & 3 deletions Sleipnir/Sleipnir/Examples/ExampleBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Foundation

enum ExampleState : Printable {
enum ExampleState : CustomStringConvertible {
case Incomplete
case Skipped
case Pending
Expand All @@ -24,7 +24,6 @@ enum ExampleState : Printable {
case .Passed: return "Passed"
case .Failed: return "Failed"
case .Error: return "Error"
default: return "ExampleState"
}
}
}
Expand Down Expand Up @@ -53,7 +52,7 @@ class ExampleBase {

func shouldRun() -> Bool {
let shouldOnlyRunFocused = Runner.shouldOnlyRunFocused
var parentShouldRun = parent != nil && parent!.shouldRun()
let parentShouldRun = parent != nil && parent!.shouldRun()
return !shouldOnlyRunFocused || (self.focused || parentShouldRun)
}
}
12 changes: 6 additions & 6 deletions Sleipnir/Sleipnir/Examples/ExampleGroup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,33 +142,33 @@ public func afterEach(block: SleipnirBlock) {
}

public func describe(label: String, block: SleipnirBlock) {
var group = ExampleGroup(label, block)
let group = ExampleGroup(label, block)
SpecTable.handleGroup(group)
}

public func fdescribe(label: String, block: SleipnirBlock) {
var group = ExampleGroup(label, block)
let group = ExampleGroup(label, block)
group.focused = true
SpecTable.handleGroup(group)
}

public func xdescribe(label: String, block: SleipnirBlock) {
var group = ExampleGroup(label, { it("is pending", PENDING) })
let group = ExampleGroup(label, { it("is pending", block: PENDING) })
SpecTable.handleGroup(group)
}

public func context(label: String, block: SleipnirBlock) {
var group = ExampleGroup(label, block)
let group = ExampleGroup(label, block)
SpecTable.handleGroup(group)
}

public func fcontext(label: String, block: SleipnirBlock) {
var group = ExampleGroup(label, block)
let group = ExampleGroup(label, block)
group.focused = true
SpecTable.handleGroup(group)
}

public func xcontext(label: String, block: SleipnirBlock) {
var group = ExampleGroup(label, { it("is pending", PENDING) })
let group = ExampleGroup(label, { it("is pending", block: PENDING) })
SpecTable.handleGroup(group)
}
8 changes: 4 additions & 4 deletions Sleipnir/Sleipnir/Internals/Dumper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ public struct Dumper {
printWithPadding("examples: \(group.examples.count)", level: level)

for exampleGroup in group.childGroups {
println()
print("", terminator: "")
dumpExampleGroup(exampleGroup, level: level + 1)
}
}

private static func printWithPadding(string: String, level: Int) {
var spaces = level * 2
var padding = String(count: spaces, repeatedValue: Character(" "))
println(padding + string)
let spaces = level * 2
let padding = String(count: spaces, repeatedValue: Character(" "))
print(padding + string, terminator: "")
}
}
2 changes: 1 addition & 1 deletion Sleipnir/Sleipnir/Internals/Runner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public struct Runner {
static var shouldOnlyRunFocused = false

public static func run(runOrder: RunOrder = RunOrder.Random, seed: Int? = nil) {
let specSeed = setUpRandomSeed(seed: seed)
let specSeed = setUpRandomSeed(seed)

if (runOrder == RunOrder.Random) {
shuffleExamples(&SpecTable.topLevelGroups)
Expand Down
2 changes: 1 addition & 1 deletion Sleipnir/Sleipnir/Internals/SharedExampleGroup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public func sharedExamplesFor(label: String, block: SleipnirBlock) {
}

public func sharedExamplesFor(label: String, block: SharedExampleBlock) {
SharedExampleGroup.handleSharedExampleGroup(label, block)
SharedExampleGroup.handleSharedExampleGroup(label, block: block)
}

public func itShouldBehaveLike(label: String, sharedContext: SharedContext) {
Expand Down
2 changes: 1 addition & 1 deletion Sleipnir/Sleipnir/Internals/SleipnirSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@

import Foundation

@objc public class SleipnirSpec {
public class SleipnirSpec {
public init() {}
}
2 changes: 1 addition & 1 deletion Sleipnir/Sleipnir/Internals/SpecFailure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ class SpecFailure {
var lines: [String] = (reason as NSString).componentsSeparatedByString("\n") as [String]
let whitespace = NSCharacterSet.whitespaceAndNewlineCharacterSet()
lines = lines.map { line in line.stringByTrimmingCharactersInSet(whitespace) }
return "".join(lines)
return lines.joinWithSeparator("")
}
}
8 changes: 4 additions & 4 deletions Sleipnir/Sleipnir/Matchers/ActualValue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class ActualValue<T> {
}

private func fail(reason: String) {
var specFailure = SpecFailure(reasonRaw: reason, fileName: fileName, lineNumber: lineNumber)
let specFailure = SpecFailure(reasonRaw: reason, fileName: fileName, lineNumber: lineNumber)
Runner.currentExample!.specFailure = specFailure
Runner.currentExample!.setState(ExampleState.Failed)
}
Expand All @@ -62,15 +62,15 @@ public class ActualValue<T> {
}
}

public func expect<T>(expression: @autoclosure () -> T?, file: String = __FILE__, line: Int = __LINE__) -> ActualValue<T> {
public func expect<T>(@autoclosure expression: () -> T?, file: String = #file, line: Int = #line) -> ActualValue<T> {
return ActualValue(value: expression(), fileName: file, lineNumber: line)
}

public func expect<T>(file: String = __FILE__, line: Int = __LINE__, expression: () -> T?) -> ActualValue<T> {
public func expect<T>(file: String = #file, line: Int = #line, expression: () -> T?) -> ActualValue<T> {
return ActualValue(value: expression(), fileName: file, lineNumber: line)
}

public func fail(message: String, file: String = __FILE__, line: Int = __LINE__) {
public func fail(message: String, file: String = #file, line: Int = #line) {
let specFailure = SpecFailure(reasonRaw: message, fileName: file, lineNumber: line)
Runner.currentExample!.specFailure = specFailure
Runner.currentExample!.setState(ExampleState.Failed)
Expand Down
2 changes: 1 addition & 1 deletion Sleipnir/Sleipnir/Matchers/BeFalse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class BeFalse<T>: BaseMatcher<T> {
}

override func match(actual: T?) -> Bool {
return !(actual as Bool)
return !(actual as? Bool ?? true)
}

override func failureMessageEnd() -> String {
Expand Down
2 changes: 1 addition & 1 deletion Sleipnir/Sleipnir/Matchers/BeTrue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class BeTrue<T>: BaseMatcher<T> {
}

override func match(actual: T?) -> Bool {
return actual as Bool
return actual as? Bool ?? false
}

override func failureMessageEnd() -> String {
Expand Down
10 changes: 5 additions & 5 deletions Sleipnir/Sleipnir/Matchers/Container/BeginWith.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ public class BeginWith<S: SequenceType, T: Equatable where S.Generator.Element =
}

if (actual is String && stringItem != nil) {
return matchString(actual as String, item: stringItem!)
return matchString(actual as! String, item: stringItem!)
} else {
return matchSequence(actual!, item: item!)
}
}

override func failureMessageEnd() -> String {
var textItem = (item != nil) ? stringify(item) : stringify(stringItem)
let textItem = (item != nil) ? stringify(item) : stringify(stringItem)
return "begin with <\(textItem)>"
}

Expand All @@ -59,6 +59,6 @@ public func beginWith<S: SequenceType, T: Equatable where S.Generator.Element ==
return BeginWith(item: item)
}

public func beginWith(item: String) -> BeginWith<String, Character> {
return BeginWith(stringItem: item)
}
//public func beginWith(item: String) -> BeginWith<String, Character> {
// return BeginWith(stringItem: item)
//}
12 changes: 6 additions & 6 deletions Sleipnir/Sleipnir/Matchers/Container/Contain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ public class Contain<S: SequenceType, T: Equatable where S.Generator.Element ==
}

if (actual is String && stringItem != nil) {
return matchString(actual as String, item: stringItem!)
return matchString(actual as! String, item: stringItem!)
} else {
return matchSequence(actual!, item: item!)
}
}

override func failureMessageEnd() -> String {
var textItem = (item != nil) ? stringify(item) : stringify(stringItem)
let textItem = (item != nil) ? stringify(item) : stringify(stringItem)
return "contain <\(textItem)>"
}

Expand All @@ -45,14 +45,14 @@ public class Contain<S: SequenceType, T: Equatable where S.Generator.Element ==
}

private func matchSequence(actual: S, item: T) -> Bool {
return contains(actual, item)
return actual.contains(item)
}
}

public func contain<S: SequenceType, T: Equatable where S.Generator.Element == T>(item: T) -> Contain<S, T> {
return Contain(item: item)
}

public func contain(item: String) -> Contain<String, Character> {
return Contain(stringItem: item)
}
//public func contain(item: String) -> Contain<String, Character> {
// return Contain(stringItem: item)
//}
Loading

0 comments on commit 9ec3e6d

Please sign in to comment.