Skip to content

[SR-1589] Add non-throwing testCase() wrapper function. #116

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

Merged
merged 1 commit into from
May 24, 2016

Conversation

ddunbar
Copy link
Contributor

@ddunbar ddunbar commented May 24, 2016

  • This is useful in clients which would like to use Swift type inference to
    define the allTests array. If none of the tests in the class throw, Swift
    will infer the type of that array as (String, (T) -> () -> ()) which is not
    convertible to the type expected by the testCase method.
  • Resolves: https://bugs.swift.org/browse/SR-1589

@ddunbar ddunbar changed the title Add non-throwing testCase() wrapper function. [SR-1589] Add non-throwing testCase() wrapper function. May 24, 2016
return (T.self, tests)
}

private func test<T: XCTestCase>(_ testFunc: (T) -> () -> Void) -> (XCTestCase) throws -> Void {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's necessary to add this overload, because the type conversion should allow the existing test(_:) function to be used (no tuples involved in the argument type).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, good point. Fixed and rebased (c65b335).

@briancroom
Copy link
Contributor

Thanks for the PR @ddunbar! This is a nice improvement. I left one minor comment on the code.

A little testing seems to indicate that the alternative allTests form can be used in all cases, including when mixing throwing and non-throwing tests. So I wonder if we should actually update our tests and change the recommended form to use this now?

class FooTests: XCTestCase {
  func testFoo() {}
  // Notice use of type inference to avoid boilerplate.
  static var allTests = {
    ("testFoo", testFoo)
  }()
}

@briancroom
Copy link
Contributor

@swift-ci please test

@ddunbar
Copy link
Contributor Author

ddunbar commented May 24, 2016

Yes, the alternative form will work in all cases now, because either of the types Swift infers will work. I think it would be a good idea to update to this as the standard recommendation as it reduces some of the redundant boilerplate that currently needs to be copied and then modified (to change the test case name).

I can follow up on that.

 - This is useful in clients which would like to use Swift type inference to
   define the `allTests` array. If none of the tests in the class throw, Swift
   will infer the type of that array as `(String, (T) -> () -> ())` which is not
   convertible to the type expected by the `testCase` method.

 - Resolves: https://bugs.swift.org/browse/SR-1589
@ddunbar
Copy link
Contributor Author

ddunbar commented May 24, 2016

@swift-ci please test

@briancroom
Copy link
Contributor

The Linux test failure is caused by the ongoing issues with Foundation's test suite. I tested it locally and it looks good to go.

@ddunbar If you don't have time, I have no problem updating the other tests and docs here myself. Thanks for bringing this up!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants