Skip to content

Commit ffdc0c0

Browse files
authored
Tests: Run packageInitExecutable test on all platforms for native build system (#8527)
### Motivation: Increase code coverage for our integration tests. This is an issue I introduced in #8454 while ignoring `--build-system swiftbuild` issues on Windows (i.e., actually this specific issue #8514). I accidentally skipped the packageInitExecutable test for `--build-system native` as well (which should be green). This PR fixes that. ### Modifications: Swift Testing currently doesn't support combining *conditional traits* (e.g.,`skipHostOS(.windows)`) with *parametric tests*. So the 2nd best approach is to split the tests as I just did.
1 parent 2bc3390 commit ffdc0c0

File tree

1 file changed

+32
-23
lines changed

1 file changed

+32
-23
lines changed

IntegrationTests/Tests/IntegrationTests/SwiftPMTests.swift

+32-23
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,15 @@ private struct SwiftPMTests {
7575
}
7676

7777
@Test(
78-
.requireHostOS(.windows, when: false),
78+
.requireThreadSafeWorkingDirectory,
79+
arguments: [BuildSystemProvider.native]
80+
)
81+
func packageInitExecutable(_ buildSystemProvider: BuildSystemProvider) throws {
82+
try _packageInitExecutable(buildSystemProvider)
83+
}
84+
85+
@Test(
86+
.skipHostOS(.windows),
7987
.requireThreadSafeWorkingDirectory,
8088
.bug(
8189
"https://github.com/swiftlang/swift-package-manager/issues/8416",
@@ -85,30 +93,31 @@ private struct SwiftPMTests {
8593
"https://github.com/swiftlang/swift-package-manager/issues/8514",
8694
"[Windows] Integration test SwiftPMTests.packageInitExecutable with --build-system swiftbuild is skipped"
8795
),
88-
arguments: BuildSystemProvider.allCases
96+
arguments: [BuildSystemProvider.swiftbuild]
8997
)
90-
func packageInitExecutable(_ buildSystemProvider: BuildSystemProvider) throws {
91-
// Executable
92-
do {
93-
try withTemporaryDirectory { tmpDir in
94-
let packagePath = tmpDir.appending(component: "foo")
95-
try localFileSystem.createDirectory(packagePath)
96-
try sh(swiftPackage, "--package-path", packagePath, "init", "--type", "executable")
97-
try sh(swiftBuild, "--package-path", packagePath, "--build-system", buildSystemProvider.rawValue)
98-
99-
try withKnownIssue("Error while loading shared libraries: libswiftCore.so: cannot open shared object file: No such file or directory") {
100-
// The 'native' build system uses 'swiftc' as the linker driver, which adds an RUNPATH to the swift runtime libraries in the SDK.
101-
// 'swiftbuild' directly calls clang, which does not add the extra RUNPATH, so runtime libraries cannot be found.
102-
let (stdout, stderr) = try sh(
103-
swiftRun, "--package-path", packagePath, "--build-system", buildSystemProvider.rawValue
104-
)
105-
#expect(!stderr.contains("error:"))
106-
#expect(stdout.contains("Hello, world!"))
107-
} when: {
108-
buildSystemProvider == .swiftbuild && ProcessInfo.hostOperatingSystem == .linux
109-
}
98+
func packageInitExecutablSkipWindows(_ buildSystemProvider: BuildSystemProvider) throws {
99+
try _packageInitExecutable(buildSystemProvider)
100+
}
101+
102+
private func _packageInitExecutable(_ buildSystemProvider: BuildSystemProvider) throws {
103+
try withTemporaryDirectory { tmpDir in
104+
let packagePath = tmpDir.appending(component: "foo")
105+
try localFileSystem.createDirectory(packagePath)
106+
try sh(swiftPackage, "--package-path", packagePath, "init", "--type", "executable")
107+
try sh(swiftBuild, "--package-path", packagePath, "--build-system", buildSystemProvider.rawValue)
108+
109+
try withKnownIssue("Error while loading shared libraries: libswiftCore.so: cannot open shared object file: No such file or directory") {
110+
// The 'native' build system uses 'swiftc' as the linker driver, which adds an RUNPATH to the swift runtime libraries in the SDK.
111+
// 'swiftbuild' directly calls clang, which does not add the extra RUNPATH, so runtime libraries cannot be found.
112+
let (stdout, stderr) = try sh(
113+
swiftRun, "--package-path", packagePath, "--build-system", buildSystemProvider.rawValue
114+
)
115+
#expect(!stderr.contains("error:"))
116+
#expect(stdout.contains("Hello, world!"))
117+
} when: {
118+
buildSystemProvider == .swiftbuild && ProcessInfo.hostOperatingSystem == .linux
119+
}
110120
}
111-
}
112121
}
113122

114123
@Test(

0 commit comments

Comments
 (0)