Skip to content
This repository has been archived by the owner on Aug 29, 2022. It is now read-only.

Commit

Permalink
Merge pull request #212 from bignerdranch/zwaldowski/improve-mirror
Browse files Browse the repository at this point in the history
Improve debug printing, mustFill reporting
  • Loading branch information
zwaldowski authored Mar 26, 2018
2 parents ab80653 + 10f3c19 commit 511df74
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 15 deletions.
11 changes: 7 additions & 4 deletions Sources/Deferred/Future.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,14 @@ extension FutureProtocol {

/// Return the `Mirror` for `self`.
public var customMirror: Mirror {
guard Value.self != Void.self, let value = peek() else {
return Mirror(self, children: [ "isFilled": peek() != nil ], displayStyle: .tuple)
let child: Mirror.Child
switch peek() {
case let value? where Value.self != Void.self:
child = (label: "value", value: value)
case let other:
child = (label: "isFilled", value: other != nil)
}

return Mirror(self, unlabeledChildren: [ value ], displayStyle: .optional)
return Mirror(self, children: CollectionOfOne(child), displayStyle: .optional, ancestorRepresentation: .suppressed)
}
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/Deferred/Promise.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ extension PromiseProtocol {
/// is a serious programming error. The optimizer may assume that it is
/// not possible.
@_transparent
public func mustFill(with value: Value) {
public func mustFill(with value: Value, file: StaticString = #file, line: UInt = #line) {
if !fill(with: value) {
preconditionFailure("Cannot fill an already-filled \(type(of: self))")
preconditionFailure("Cannot fill an already-filled \(type(of: self))", file: file, line: line)
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions Sources/Deferred/Protected.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ extension Protected: CustomDebugStringConvertible, CustomReflectable {
}

public var customMirror: Mirror {
return lock.withAttemptedReadLock {
Mirror(self, unlabeledChildren: [ unsafeValue ], displayStyle: .optional)
} ?? Mirror(self, children: [ "locked": true ], displayStyle: .tuple)
let child: Mirror.Child = lock.withAttemptedReadLock {
(label: "value", value: unsafeValue)
} ?? (label: "isLocked", value: true)
return Mirror(self, children: CollectionOfOne(child), displayStyle: .optional)

}
}
4 changes: 2 additions & 2 deletions Tests/DeferredTests/DeferredTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ class DeferredTests: XCTestCase {
let deferred = Deferred<Int>()

let magicMirror = Mirror(reflecting: deferred)
XCTAssertEqual(magicMirror.displayStyle, .tuple)
XCTAssertEqual(magicMirror.displayStyle, .optional)
XCTAssertNil(magicMirror.superclassMirror)
XCTAssertEqual(magicMirror.descendant("isFilled") as? Bool, false)
}
Expand All @@ -394,7 +394,7 @@ class DeferredTests: XCTestCase {
let deferred = Deferred<Void>(filledWith: ())

let magicMirror = Mirror(reflecting: deferred)
XCTAssertEqual(magicMirror.displayStyle, .tuple)
XCTAssertEqual(magicMirror.displayStyle, .optional)
XCTAssertNil(magicMirror.superclassMirror)
XCTAssertEqual(magicMirror.descendant("isFilled") as? Bool, true)
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/DeferredTests/ExistentialFutureTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class ExistentialFutureTests: XCTestCase {
let future = Future<Int>()

let magicMirror = Mirror(reflecting: future)
XCTAssertEqual(magicMirror.displayStyle, .tuple)
XCTAssertEqual(magicMirror.displayStyle, .optional)
XCTAssertNil(magicMirror.superclassMirror)
XCTAssertEqual(magicMirror.descendant("isFilled") as? Bool, false)
}
Expand All @@ -132,7 +132,7 @@ class ExistentialFutureTests: XCTestCase {
let future = Future<Void>(value: ())

let magicMirror = Mirror(reflecting: future)
XCTAssertEqual(magicMirror.displayStyle, .tuple)
XCTAssertEqual(magicMirror.displayStyle, .optional)
XCTAssertNil(magicMirror.superclassMirror)
XCTAssertEqual(magicMirror.descendant("isFilled") as? Bool, true)
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/DeferredTests/ProtectedTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ class ProtectedTests: XCTestCase {
defer { customLock.unlock() }

let magicMirror = Mirror(reflecting: protected)
XCTAssertEqual(magicMirror.displayStyle, .tuple)
XCTAssertEqual(magicMirror.displayStyle, .optional)
XCTAssertNil(magicMirror.superclassMirror)
XCTAssertEqual(magicMirror.descendant("locked") as? Bool, true)
XCTAssertEqual(magicMirror.descendant("isLocked") as? Bool, true)
}

}

0 comments on commit 511df74

Please sign in to comment.