Skip to content

[tests] Use XCTMain() for Linux tests #66

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
Dec 11, 2015

Conversation

modocache
Copy link
Contributor

XCTMain() is the canonical entry point for XCTest on Linux.
The continued development of swift-corelibs-xctest would be made
simpler if each consumer used this entry point to run their unit tests.

  • Modify Utilities/bootstrap so that it would not include
    main.swift files in test targets when compiling on OS X. These
    files are only necessary on platforms that do not use Objective-C's
    XCTest; they should not be included in Linux builds.
  • Split XCTestCaseProvider out into its own package, which the tests
    depend upon. Each test makes explicit reference to XCTestCaseProvider,
    which means it must be defined on both (1) Linux and (2) OS X, and it must be
    defined on OS X whether running the tests via (2a) Utilities/bootstrap or
    via (2b) the Xcode project. Test dependencies defined in
    Utilities/bootstrap take care of 1, 2, and 2a.
  • Add an XCTestCaseProvider target to the Xcode project, which takes
    care of item 2b from the bullet point above.

(Note that the following isn't included in any commit message in this pull request.)

Another attempt at #28. Read the discussion there for additional context.

// Linux, where it is already defined by swift-corelibs-xctest.
#if os(OSX)
public protocol XCTestCaseProvider {
var allTests : [(String, () -> ())] { get }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should be updated to () -> Void, as per swiftlang/swift-corelibs-xctest#13.

@modocache
Copy link
Contributor Author

Good idea! Building on that idea: we could conditionally define XCTMain() on OS X as a function that calls fatalError, warning that the test suite has been misconfigured.

@ddunbar
Copy link
Contributor

ddunbar commented Dec 11, 2015

Could do, although I have no idea how that would ever happen. Test bundles never run their main code.

`XCTMain()` is the canonical entry point for XCTest on Linux.
The continued development of swift-corelibs-xctest would be made
simpler if each consumer used this entry point to run their unit tests.

- Split XCTestCaseProvider out into its own package, which the tests
  depend upon. Each test makes explicit reference to XCTestCaseProvider,
  which means it must be defined on both (1) Linux and (2) OS X, and it must be
  defined on OS X whether running the tests via (2a) `Utilities/bootstrap` or
  via (2b) the Xcode project. Test dependencies defined in
  `Utilities/bootstrap` take care of 1, 2, and 2a.
- Add an XCTestCaseProvider target to the Xcode project, which takes
  care of item 2b from the bullet point above.
- Also define XCTMain() on OS X in XCTestCaseProvider. This is because
  `Utilities/bootstrap` compiles test packages' main.swift files,
  regardless of whether they are ever executed. These files refer to
  `XCTMain()` (so we need to define it), but it is never run (so its
  implementation raises a fatal error).
var allTests : [(String, () -> ())] { get }
}

public func XCTMain(testCases: [XCTestCaseProvider]) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the pull request such that XCTMain is also conditionally defined. Because we don't depend on XCTest for this shim framework, the function takes an array of XCTestCaseProvider, as opposed to the array of XCTestCase the swift-corelibs-xctest XCTMain function takes.

This wouldn't have worked unless #70 was merged--thanks!!

@modocache
Copy link
Contributor Author

Rebased onto #70 and addressed your comments, @ddunbar! 👋

@ddunbar
Copy link
Contributor

ddunbar commented Dec 11, 2015

Thanks!

ddunbar added a commit that referenced this pull request Dec 11, 2015
[tests] Use XCTMain() for Linux tests
@ddunbar ddunbar merged commit 113fee6 into swiftlang:master Dec 11, 2015
@modocache modocache deleted the use-xctmain branch December 11, 2015 21:31
aciidgh pushed a commit to aciidgh/swift-package-manager that referenced this pull request Jan 11, 2019
…warning

Disable analyzer for `raw_ostream.cpp`
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