-
Notifications
You must be signed in to change notification settings - Fork 263
Various minor changes to XCTest-files. #80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0d912f3
bdeb15b
6ff1cb0
cfdf9fb
30c1133
da99bbb
17a2b03
e0f34a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
// | ||
// | ||
// XCTestFiltering.swift | ||
// This provides utilities for executing only a subset of the tests provided to XCTMain | ||
// This provides utilities for executing only a subset of the tests provided to `XCTMain` | ||
// | ||
|
||
internal typealias TestFilter = (XCTestCase.Type, String) -> Bool | ||
|
@@ -21,15 +21,10 @@ internal struct TestFiltering { | |
} | ||
|
||
var selectedTestFilter: TestFilter { | ||
if let selectedTestName = selectedTestName { | ||
if let selectedTest = SelectedTest(selectedTestName: selectedTestName) { | ||
return selectedTest.matches | ||
} else { | ||
return excludeAllFilter() | ||
} | ||
} else { | ||
return includeAllFilter() | ||
} | ||
guard let selectedTestName = selectedTestName else { return includeAllFilter() } | ||
guard let selectedTest = SelectedTest(selectedTestName: selectedTestName) else { return excludeAllFilter() } | ||
|
||
return selectedTest.matches | ||
} | ||
|
||
private func excludeAllFilter() -> TestFilter { | ||
|
@@ -42,12 +37,12 @@ internal struct TestFiltering { | |
|
||
static func filterTests(entries: [XCTestCaseEntry], filter: TestFilter) -> [XCTestCaseEntry] { | ||
return entries | ||
.map({ testCase, tests in | ||
return (testCase, tests.filter({ filter(testCase, $0.0) })) | ||
}) | ||
.filter({ testCase, tests in | ||
.map { testCase, tests in | ||
return (testCase, tests.filter { filter(testCase, $0.0) } ) | ||
} | ||
.filter { testCase, tests in | ||
return !tests.isEmpty | ||
}) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @briancroom Same here. I don't have a strong opinion, I think either way of writing it is fine. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm pretty ambivalent about this one. I've been pretty happy following the Rule of Kevin in my Swift code, but I don't have a strong opinion. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, I've searched some files in swift/stdlib/public/core to try to find occurrences of the string
... I'm not quite sure in terms of consistency, when it comes to use of trailing closures. |
||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,25 +52,19 @@ private enum _XCTAssertionResult { | |
case UnexpectedFailure(ErrorProtocol) | ||
|
||
var expected: Bool { | ||
switch (self) { | ||
case .UnexpectedFailure(_): | ||
return false | ||
default: | ||
return true | ||
switch self { | ||
case .UnexpectedFailure(_): return false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In #79, you made changes that placed a line break after a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried to explain my intent in the commit. I use this style in my own projects, as it's consistent, but also reduces the size of switches, with short expressions in each case. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense to me. Thanks, and sorry I didn't realize you had already explained in the commit messages! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool. |
||
default: return true | ||
} | ||
} | ||
|
||
func failureDescription(assertion: _XCTAssertion) -> String { | ||
let explanation: String | ||
switch (self) { | ||
case .Success: | ||
explanation = "passed" | ||
case .ExpectedFailure(let details?): | ||
explanation = "failed: \(details)" | ||
case .ExpectedFailure(_): | ||
explanation = "failed" | ||
case .UnexpectedFailure(let error): | ||
explanation = "threw error \"\(error)\"" | ||
switch self { | ||
case .Success: explanation = "passed" | ||
case .ExpectedFailure(let details?): explanation = "failed: \(details)" | ||
case .ExpectedFailure(_): explanation = "failed" | ||
case .UnexpectedFailure(let error): explanation = "threw error \"\(error)\"" | ||
} | ||
|
||
if let name = assertion.name { | ||
|
@@ -92,23 +86,22 @@ private func _XCTEvaluateAssertion(assertion: _XCTAssertion, @autoclosure messag | |
switch result { | ||
case .Success: | ||
return | ||
|
||
default: | ||
if let handler = XCTFailureHandler { | ||
handler(XCTFailure(message: message(), failureDescription: result.failureDescription(assertion), expected: result.expected, file: file, line: line)) | ||
} | ||
} | ||
} | ||
|
||
/// This function emits a test failure if the general Bool expression passed | ||
/// to it evaluates to false. | ||
/// This function emits a test failure if the general `Boolean` expression passed | ||
/// to it evaluates to `false`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would suggest either keeping it "Bool" and adding the backticks since that is a type name or changing to Boolean and not adding the backpacks since then it's just prose... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand your point. What I don't understand though is: if This code was taken from XCTAssert.swift There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're absolutely right! I forgot about the Boolean protocol as distinct from the Bool concrete type. Never mind! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Possibly contributing to the confusion is the fact that this was previously named BooleanType before the recent Swift 3 stdlib naming changes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I see. I haven't been aware of that name change. |
||
/// | ||
/// - Requires: This and all other XCTAssert* functions must be called from | ||
/// within a test method, as passed to `XCTMain`. | ||
/// Assertion failures that occur outside of a test method will *not* be | ||
/// reported as failures. | ||
/// | ||
/// - Parameter expression: A boolean test. If it evaluates to false, the | ||
/// - Parameter expression: A boolean test. If it evaluates to `false`, the | ||
/// assertion fails and emits a test failure. | ||
/// - Parameter message: An optional message to use in the failure if the | ||
/// assertion fails. If no message is supplied a default message is used. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@briancroom Any opinions here? I find both equally readable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this change! The flatter structure is nice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Me too. Shorter and less nested.