Skip to content
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

[SR-1589] Add testCase variant taking non-throwing functions #387

Closed
ddunbar opened this issue May 23, 2016 · 6 comments
Closed

[SR-1589] Add testCase variant taking non-throwing functions #387

ddunbar opened this issue May 23, 2016 · 6 comments
Assignees

Comments

@ddunbar
Copy link
Member

ddunbar commented May 23, 2016

Previous ID SR-1589
Radar None
Original Reporter @ddunbar
Type Bug
Status Closed
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s XCTest
Labels Bug
Assignee @ddunbar
Priority Medium

md5: c858676023ccc3bab722fe07f764cb24

Issue Description:

I would like to write Linux tests as:

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

but type inference will fail with something like:

swiftpm/Tests/Basic/XCTestManifests.swift:17:28: error: cannot convert value of type '[(String, JSONTests -> () -> ())]' to expected argument type '[(String, (XCTestCase) -> () throws -> Void)\
]'
        testCase(JSONTests.allTests),
                 ~~~~~~~~~~^~~~~~~~

It would be nice if Linux XCTest would accept throwing and non-throwing variants of the testCase function.

@ddunbar
Copy link
Member Author

ddunbar commented May 23, 2016

CC @modocache @briancroom

@belkadan
Copy link

I think this just comes down to "tuples don't behave covariantly", which is tracked somewhere else.

import Foundation
let x = (NSDate(), NSDate())
let y: (NSObject, NSObject) = x
error: cannot express tuple conversion '(NSDate, NSDate)' to '(NSObject, NSObject)'

@ddunbar
Copy link
Member Author

ddunbar commented May 23, 2016

In this specific case we can just provide a workaround in XCTest, though.

@belkadan
Copy link

Actually, wait, that's not even covariant. JSONTests is a subtype of XCTestCase.

@ddunbar
Copy link
Member Author

ddunbar commented May 23, 2016

PR: #116

@briancroom
Copy link
Collaborator

The diagnostic there is a little misleading, because the function being called is actually generic with a constraint of <T: XCTestCase>, so it would also be fair to say that the failed conversion is from [(String, (JSONTests) -> () -> Void)] to [(String, (JSONTests) -> () throws -> Void)], at which point I believe that @belkadan's covariance analysis is correct.

Regardless, I agree with @ddunbar that adding an overload in XCTest to handle this case is an appropriate course of action at this point.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 9, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants