Skip to content

Commit

Permalink
beta5 updates
Browse files Browse the repository at this point in the history
  • Loading branch information
heckj committed Jul 30, 2019
1 parent b015971 commit 789e2e0
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 94 deletions.
Expand Up @@ -6,7 +6,7 @@
"repositoryURL": "https://github.com/tcldr/Entwine.git",
"state": {
"branch": "master",
"revision": "ce59b544794b5adafe751b9cda8dde495ea69dd0",
"revision": "d6b60871f28f37d9789007634bd1a34845c1b3cf",
"version": null
}
}
Expand Down
103 changes: 54 additions & 49 deletions UsingCombineTests/BreakpointPublisherTests.swift
Expand Up @@ -15,7 +15,12 @@ class BreakpointPublisherTests: XCTestCase {
case invalidServerResponse
}

func testBreakpointOnError() {
/* NOTE(heckj):
- these tests have all been prefixed with SKIP_ so they won't be run automatically with a whole
project validation. They explicitly drop breakpoints into the debugger, which is great when
you're actively debugging, but a complete PITA when you're trying to see a whole test sequence run.
*/
func SKIP_testBreakpointOnError() {

let publisher = PassthroughSubject<String?, Error>()

Expand All @@ -40,59 +45,59 @@ class BreakpointPublisherTests: XCTestCase {
XCTAssertNotNil(cancellable)
}

func testBreakpointOnSubscription() {
func SKIP_testBreakpointOnSubscription() {

let publisher = PassthroughSubject<String?, Error>()
let publisher = PassthroughSubject<String?, Error>()

// this sets up the chain of whatever it's going to do
let cancellable = publisher
.breakpoint(receiveSubscription: { subscription in
return true // triggers breakpoint
}, receiveOutput: { value in
return false
}, receiveCompletion: { completion in
return false
})
.sink(
receiveCompletion: { completion in
print("sink captured the completion of \(String(describing: completion))")
},
receiveValue: { aValue in
print("sink captured the result of \(String(describing: aValue))")
}
)
// this sets up the chain of whatever it's going to do
let cancellable = publisher
.breakpoint(receiveSubscription: { subscription in
return true // triggers breakpoint
}, receiveOutput: { value in
return false
}, receiveCompletion: { completion in
return false
})
.sink(
receiveCompletion: { completion in
print("sink captured the completion of \(String(describing: completion))")
},
receiveValue: { aValue in
print("sink captured the result of \(String(describing: aValue))")
}
)

publisher.send("DATA IN")
publisher.send(completion: .finished)
XCTAssertNotNil(cancellable)
}
publisher.send("DATA IN")
publisher.send(completion: .finished)
XCTAssertNotNil(cancellable)
}

func testBreakpointOnData() {
func SKIP_testBreakpointOnData() {

let publisher = PassthroughSubject<String?, Error>()
let cancellable = publisher
.breakpoint(receiveSubscription: { subscription in
return false
}, receiveOutput: { value in
return true // triggers breakpoint
}, receiveCompletion: { completion in
return false
})
.map {
$0 // does nothing, but can be convenient to hang a debugger breakpoint on to see the data
let publisher = PassthroughSubject<String?, Error>()
let cancellable = publisher
.breakpoint(receiveSubscription: { subscription in
return false
}, receiveOutput: { value in
return true // triggers breakpoint
}, receiveCompletion: { completion in
return false
})
.map {
$0 // does nothing, but can be convenient to hang a debugger breakpoint on to see the data
}
.sink(
// sink captures and terminates the pipeline of operators
receiveCompletion: { completion in
print("sink captured the completion of \(String(describing: completion))")
},
receiveValue: { aValue in
print("sink captured the result of \(String(describing: aValue))")
}
.sink(
// sink captures and terminates the pipeline of operators
receiveCompletion: { completion in
print("sink captured the completion of \(String(describing: completion))")
},
receiveValue: { aValue in
print("sink captured the result of \(String(describing: aValue))")
}
)
)

publisher.send("DATA IN")
publisher.send(completion: .finished)
XCTAssertNotNil(cancellable)
}
publisher.send("DATA IN")
publisher.send(completion: .finished)
XCTAssertNotNil(cancellable)
}
}
9 changes: 5 additions & 4 deletions UsingCombineTests/EncodeDecodeTests.swift
Expand Up @@ -102,7 +102,7 @@ class EncodeDecodeTests: XCTestCase {
XCTAssertNotNil(cancellable)
}

func testSimpleEncodeError() {
func testSimpleEncodeNil() {
// setup
let dataProvider = PassthroughSubject<PostmanEchoTimeStampCheckResponse?, Never>()

Expand All @@ -117,15 +117,16 @@ class EncodeDecodeTests: XCTestCase {
break
case .failure(let anError):
print("received error: ", anError)
XCTAssertEqual("The data couldn’t be written because it isn’t in the correct format.", anError.localizedDescription)
XCTFail("shouldn't receive a finished with this sample")
break
}
}, receiveValue: { data in
print(".sink() data received \(data)")
XCTFail("shouldn't receive any data with this sample")
let resultingString = String(data: data, encoding: .utf8)
XCTAssertEqual(resultingString, "null")
})

dataProvider.send(nil)
XCTAssertNotNil(cancellable)
}

}
95 changes: 55 additions & 40 deletions UsingCombineTests/PublisherTests.swift
Expand Up @@ -11,9 +11,23 @@ import Combine

class PublisherTests: XCTestCase {

struct HoldingStruct {
@Published var username: String = ""
}
// struct HoldingStruct {
// @Published var username: String = ""
// }

/* NOTE(heckj):
The above stanza (as of beta5) is now explicitly disallowed from the compiler, although it's
not reported very clearly in Xcode. The compiler error from the above lines:
<unknown>:0: error: 'wrappedValue' is unavailable: @Published is only available on properties of classes
Combine.Published:5:16: note: 'wrappedValue' has been explicitly marked unavailable here
public var wrappedValue: Value { get set }
^
Given that it's explicitly marked as unavailable, I'm presuming that the @Published annotation is
only to be used with properties on reference types (classes), and commenting out the tests that had
previously attempting to use it within a value type (struct).
*/

class HoldingClass {
@Published var username: String = ""
Expand All @@ -28,18 +42,18 @@ class PublisherTests: XCTestCase {
@objc dynamic var boolValue: Bool = false
}

func testPublishedOnStruct() {
let expectation = XCTestExpectation(description: self.debugDescription)
let foo = HoldingStruct()

let cancellable = foo.$username
.sink { someString in
print("value of username updated to: >>\(someString)<<")
expectation.fulfill()
}
wait(for: [expectation], timeout: 5.0)
XCTAssertNotNil(cancellable)
}
// func testPublishedOnStruct() {
// let expectation = XCTestExpectation(description: self.debugDescription)
// let foo = HoldingStruct()
//
// let cancellable = foo.$username
// .sink { someString in
// print("value of username updated to: >>\(someString)<<")
// expectation.fulfill()
// }
// wait(for: [expectation], timeout: 5.0)
// XCTAssertNotNil(cancellable)
// }

func testPublishedOnClassInstance() {
let expectation = XCTestExpectation(description: "async sink test")
Expand All @@ -53,31 +67,32 @@ class PublisherTests: XCTestCase {
wait(for: [expectation], timeout: 5.0)
XCTAssertNotNil(cancellable)
}

func testPublishedOnStructWithChange() {
// NOTE(heckj) this test succeeded on beta 2, but fails on beta3 and beta4.
// documented to Apple as FB6608729
// beta2: ✅
// beta3: ❌
// beta4: ❌
let expectation = XCTestExpectation(description: self.debugDescription)
var foo = HoldingStruct()
let q = DispatchQueue(label: self.debugDescription)

let cancellable = foo.$username
.sink { someString in
print("value of username updated to: >>\(someString)<<")
if someString == "redfish" {
expectation.fulfill()
}
}
q.async {
print("Updating to redfish on background queue")
foo.username = "redfish"
}
wait(for: [expectation], timeout: 5.0)
XCTAssertNotNil(cancellable)
}
//
// func testPublishedOnStructWithChange() {
// // NOTE(heckj) this test succeeded on beta 2, but fails on beta3 and beta4.
// // documented to Apple as FB6608729
// // beta2: ✅
// // beta3: ❌
// // beta4: ❌
// // beta5: ❌ - compiler error
// let expectation = XCTestExpectation(description: self.debugDescription)
// var foo = HoldingStruct()
// let q = DispatchQueue(label: self.debugDescription)
//
// let cancellable = foo.$username
// .sink { someString in
// print("value of username updated to: >>\(someString)<<")
// if someString == "redfish" {
// expectation.fulfill()
// }
// }
// q.async {
// print("Updating to redfish on background queue")
// foo.username = "redfish"
// }
// wait(for: [expectation], timeout: 5.0)
// XCTAssertNotNil(cancellable)
// }

func testPublishedOnClassWithChange() {
let expectation = XCTestExpectation(description: self.debugDescription)
Expand Down

0 comments on commit 789e2e0

Please sign in to comment.