Skip to content

Add stub for Testing module #5077

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 2 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -323,24 +323,31 @@ let package = Package(
.swiftLanguageMode(.v6)
]
),
.target(
// swift-corelibs-foundation has a copy of XCTest's sources so:
// (1) we do not depend on the toolchain's XCTest, which depends on toolchain's Foundation, which we cannot pull in at the same time as a Foundation package
// (2) we do not depend on a swift-corelibs-xctest Swift package, which depends on Foundation, which causes a circular dependency in swiftpm
// We believe Foundation is the only project that needs to take this rather drastic measure.
// We also have a stub for swift-testing for the same purpose, but without an implementation since this package has no swift-testing style tests
.target(
name: "XCTest",
dependencies: [
"Foundation"
],
path: "Sources/XCTest"
),
.target(
name: "Testing",
dependencies: [],
path: "Sources/Testing"
),
.testTarget(
name: "TestFoundation",
dependencies: [
"Foundation",
"FoundationXML",
"FoundationNetworking",
"XCTest",
"Testing",
.target(name: "xdgTestHelper", condition: .when(platforms: [.linux]))
],
resources: [
Expand Down
25 changes: 25 additions & 0 deletions Sources/Testing/Testing.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2024 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//

#if canImport(Glibc)
import Glibc
#elseif canImport(Musl)
import Musl
#elseif os(WASI)
import WASILibc
#elseif canImport(CRT)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit I think we should might as well add #if canImport(Bionic) here as well. But def none blocking

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair point - I'm not sure if we've tried running SwiftPM tests on android for this repo yet so I'll follow up with that later once we try to do that

Copy link
Member

Choose a reason for hiding this comment

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

Submitted in #5149

import CRT
#endif


// This function is used to mimic a bare minimum of the swift-testing library. Since this package has no swift-testing tests, we simply exit.
// The test runner will automatically call this function when running tests, so it must exit gracefully rather than using `fatalError()`.
public func __swiftPMEntryPoint(passing _: (any Sendable)? = nil) async -> Never {
exit(0)
}