Skip to content

Commit 1932a1b

Browse files
authored
Add missing Foundation imports to fix test build errors on iOS with MemberImportVisibility enabled (#1108)
This fixes several instances of a build error when attempting to build this package for iOS, or any non-macOS Apple platform. Here's one example ``` error: instance method 'contains' is not available due to missing import of defining module 'Foundation' Tests/TestingTests/SwiftPMTests.swift:370:5: note: in expansion of macro 'expect' here #expect(testIDs.allSatisfy { $0.contains(".swift:") }) ``` This general kind of build error is being emitted because we adopted [SE-0444: Member import visibility](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0444-member-import-visibility.md) by enabling the `MemberImportVisibility` experimental feature in #1020. In that PR, I fixed several instances of missing imports, including some for `Foundation` in test files. But these errors are from usages of `String.contains()`, and it turns out there are multiple overloads of that function, with an older one in `Foundation` and a newer one directly in the stdlib `Swift` module. The latter has newer, iOS 13.0-aligned API availability, and when building our tests for macOS this issue was not noticed previously because SwiftPM artificially raises the deployment target of macOS test targets to match the testing frameworks included in Xcode (when the testing libraries are being used from the installed copy of Xcode). ### Checklist: - [x] Code and documentation should follow the style of the [Style Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md). - [x] If public symbols are renamed or modified, DocC references should be updated.
1 parent 3ad851e commit 1932a1b

File tree

5 files changed

+20
-0
lines changed

5 files changed

+20
-0
lines changed

Tests/TestingTests/ConfirmationTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010

1111
@testable @_spi(Experimental) @_spi(ForToolsIntegrationOnly) import Testing
1212

13+
#if canImport(Foundation)
14+
private import Foundation
15+
#endif
16+
1317
@Suite("Confirmation Tests")
1418
struct ConfirmationTests {
1519
@Test("Successful confirmations")

Tests/TestingTests/MiscellaneousTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
@_spi(Experimental) @_spi(ForToolsIntegrationOnly) import _TestDiscovery
1313
private import _TestingInternals
1414

15+
#if canImport(Foundation)
16+
private import Foundation
17+
#endif
18+
1519
@Test(/* name unspecified */ .hidden)
1620
@Sendable func freeSyncFunction() {}
1721
@Sendable func freeAsyncFunction() async {}

Tests/TestingTests/SwiftPMTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
@testable @_spi(Experimental) @_spi(ForToolsIntegrationOnly) import Testing
1212
private import _TestingInternals
1313

14+
#if canImport(Foundation)
15+
private import Foundation
16+
#endif
17+
1418
private func configurationForEntryPoint(withArguments args: [String]) throws -> Configuration {
1519
let args = try parseCommandLineArguments(from: args)
1620
return try configurationForEntryPoint(from: args)

Tests/TestingTests/Traits/TagListTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
@testable @_spi(Experimental) @_spi(ForToolsIntegrationOnly) import Testing
1212
private import _TestingInternals
1313

14+
#if canImport(Foundation)
15+
private import Foundation
16+
#endif
17+
1418
@Suite("Tag/Tag List Tests", .tags(.traitRelated))
1519
struct TagListTests {
1620
@Test(".tags() factory method with one tag")

Tests/TestingTests/Traits/TimeLimitTraitTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010

1111
@testable @_spi(Experimental) @_spi(ForToolsIntegrationOnly) import Testing
1212

13+
#if canImport(Foundation)
14+
private import Foundation
15+
#endif
16+
1317
@Suite("TimeLimitTrait Tests", .tags(.traitRelated))
1418
struct TimeLimitTraitTests {
1519
@available(_clockAPI, *)

0 commit comments

Comments
 (0)