Skip to content

Commit 407c762

Browse files
committed
[Build] Add test for '@_implementationOnly' import of 'Foundation.Bundle'.
1 parent 6f05199 commit 407c762

File tree

7 files changed

+57
-1
lines changed

7 files changed

+57
-1
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// swift-tools-version:5.7
2+
import PackageDescription
3+
4+
let package = Package(
5+
name: "AppPkg",
6+
dependencies: [
7+
.package(path: "../UtilsPkg"),
8+
],
9+
targets: [
10+
.executableTarget(
11+
name: "App",
12+
dependencies: [
13+
.product(name: "Utils", package: "UtilsPkg")
14+
],
15+
path: "./Sources/App"),
16+
]
17+
)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import Utils
2+
// Note the lack of 'import Foundation'
3+
4+
print(FooUtils.foo.trimmingCharacters(in: .whitespaces))
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// swift-tools-version:5.7
2+
import PackageDescription
3+
4+
let package = Package(
5+
name: "UtilsPkg",
6+
products: [
7+
.library(name: "Utils", targets: ["Utils"]),
8+
],
9+
targets: [
10+
.target(name: "Utils", dependencies: [], resources: [
11+
.copy("foo.txt"),
12+
]),
13+
]
14+
)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@frozen
2+
public enum FooUtils { }
3+
4+
extension FooUtils {
5+
public static let foo: String = "Hello, World!"
6+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
foo

Sources/Build/BuildPlan.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ public final class SwiftTargetBuildDescription {
791791

792792
let stream = BufferedOutputByteStream()
793793
stream <<< """
794-
\(toolsVersion > .v5_7 ? "@_implementationOnly import" : "import") class Foundation.Bundle
794+
\(toolsVersion >= .v5_7 ? "@_implementationOnly import" : "import") class Foundation.Bundle
795795
796796
extension Foundation.Bundle {
797797
static var module: Bundle = {

Tests/FunctionalTests/ResourcesTests.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,18 @@ class ResourcesTests: XCTestCase {
8888
}
8989
}
9090
}
91+
92+
func testFoundationlessClient() throws {
93+
try fixture(name: "Resources/FoundationlessClient") { fixturePath in
94+
#if os(Linux) && swift(>=5.7)
95+
let pkgPath = fixturePath.appending(components: "AppPkg")
96+
guard let failure = XCTAssertBuildFails(pkgPath) else {
97+
XCTFail("missing expected command execution error")
98+
return
99+
}
100+
// Check that the following code expectedly doesn't compile for lack of 'import Foundation'
101+
XCTAssertMatch(failure.stdout, .contains("print(FooUtils.foo.trimmingCharacters(in: .whitespaces))"))
102+
#endif
103+
}
104+
}
91105
}

0 commit comments

Comments
 (0)