Skip to content

Commit 904b4ac

Browse files
committed
Tests: Augment SwiftBuild build provider test coverage
Augment some test to run against the native and swiftbuild build providers to gain extra confidence with the swift build integration. Update Test helpers to use BuildConfiguration in production code instead of configuration Where applicable, create a test swift for the various build configurations to allow to better skip test in specific scenarios.
1 parent e952244 commit 904b4ac

15 files changed

+375
-125
lines changed

IntegrationTests/Tests/IntegrationTests/SwiftPMTests.swift

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,6 @@ private struct SwiftPMTests {
7575
}
7676

7777
@Test(
78-
.requireThreadSafeWorkingDirectory,
79-
arguments: [BuildSystemProvider.native]
80-
)
81-
func packageInitExecutable(_ buildSystemProvider: BuildSystemProvider) throws {
82-
try _packageInitExecutable(buildSystemProvider)
83-
}
84-
85-
@Test(
86-
.skipHostOS(.windows),
8778
.requireThreadSafeWorkingDirectory,
8879
.bug(
8980
"https://github.com/swiftlang/swift-package-manager/issues/8416",
@@ -93,13 +84,9 @@ private struct SwiftPMTests {
9384
"https://github.com/swiftlang/swift-package-manager/issues/8514",
9485
"[Windows] Integration test SwiftPMTests.packageInitExecutable with --build-system swiftbuild is skipped"
9586
),
96-
arguments: [BuildSystemProvider.swiftbuild]
87+
arguments: BuildSystemProvider.allCases
9788
)
98-
func packageInitExecutablSkipWindows(_ buildSystemProvider: BuildSystemProvider) throws {
99-
try _packageInitExecutable(buildSystemProvider)
100-
}
101-
102-
private func _packageInitExecutable(_ buildSystemProvider: BuildSystemProvider) throws {
89+
private func packageInitExecutable(_ buildSystemProvider: BuildSystemProvider) throws {
10390
try withTemporaryDirectory { tmpDir in
10491
let packagePath = tmpDir.appending(component: "foo")
10592
try localFileSystem.createDirectory(packagePath)
@@ -115,16 +102,16 @@ private struct SwiftPMTests {
115102
#expect(!stderr.contains("error:"))
116103
#expect(stdout.contains("Hello, world!"))
117104
} when: {
118-
buildSystemProvider == .swiftbuild && ProcessInfo.hostOperatingSystem == .linux
105+
buildSystemProvider == .swiftbuild && (ProcessInfo.hostOperatingSystem == .linux || ProcessInfo.hostOperatingSystem == .windows)
119106
}
120107
}
121108
}
122109

123110
@Test(
124111
.requireThreadSafeWorkingDirectory,
125-
.bug(id: 0, "SWBINTTODO: Linux: /lib/x86_64-linux-gnu/Scrt1.o:function _start: error:"),
112+
.bug(id: 0, "SwiftBuildTodo: Linux: /lib/x86_64-linux-gnu/Scrt1.o:function _start: error:"),
126113
.bug("https://github.com/swiftlang/swift-package-manager/issues/8380", "lld-link: error: subsystem must be defined"),
127-
.bug(id: 0, "SWBINTTODO: MacOS: Could not find or use auto-linked library 'Testing': library 'Testing' not found"),
114+
.bug(id: 0, "SwiftBuildTodo: MacOS: Could not find or use auto-linked library 'Testing': library 'Testing' not found"),
128115
arguments: BuildSystemProvider.allCases
129116
)
130117
func packageInitLibrary(_ buildSystemProvider: BuildSystemProvider) throws {
Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
1-
import SPMBuildCore
1+
import struct SPMBuildCore.BuildSystemProvider
2+
import enum PackageModel.BuildConfiguration
23
import XCTest
34

45
open class BuildSystemProviderTestCase: XCTestCase {
56
open var buildSystemProvider: BuildSystemProvider.Kind {
67
fatalError("\(self) does not implement \(#function)")
78
}
89
}
10+
11+
open class BuildConfigurationTestCase: BuildSystemProviderTestCase {
12+
open var binPathSuffixes: [String] {
13+
fatalError("\(self) does not implement \(#function)")
14+
}
15+
16+
open var buildConfig: BuildConfiguration {
17+
fatalError("\(self) does not implement \(#function)")
18+
}
19+
20+
}

Sources/_InternalTestSupport/XCTAssertHelpers.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import Basics
1515
import class Foundation.Bundle
1616
#endif
1717
import SPMBuildCore
18+
import enum PackageModel.BuildConfiguration
1819
import TSCTestSupport
1920
import XCTest
2021

@@ -50,6 +51,10 @@ public func XCTSkipIfCI(file: StaticString = #filePath, line: UInt = #line) thro
5051
}
5152
}
5253

54+
public func XCTSkipSwiftBuildTodo(because reason: String) throws {
55+
throw XCTSkip("SwiftBuildTodo: \(reason)")
56+
}
57+
5358
/// An `async`-friendly replacement for `XCTAssertThrowsError`.
5459
public func XCTAssertAsyncThrowsError<T>(
5560
_ expression: @autoclosure () async throws -> T,
@@ -81,7 +86,7 @@ package func XCTAssertAsyncNoThrow<T>(
8186

8287
public func XCTAssertBuilds(
8388
_ path: AbsolutePath,
84-
configurations: Set<Configuration> = [.Debug, .Release],
89+
configurations: Set<BuildConfiguration> = [.debug, .release],
8590
extraArgs: [String] = [],
8691
Xcc: [String] = [],
8792
Xld: [String] = [],
@@ -111,7 +116,7 @@ public func XCTAssertBuilds(
111116

112117
public func XCTAssertSwiftTest(
113118
_ path: AbsolutePath,
114-
configuration: Configuration = .Debug,
119+
configuration: BuildConfiguration = .debug,
115120
extraArgs: [String] = [],
116121
Xcc: [String] = [],
117122
Xld: [String] = [],

Sources/_InternalTestSupport/misc.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ public func getBuildSystemArgs(for buildSystem: BuildSystemProvider.Kind?) -> [S
267267
@discardableResult
268268
public func executeSwiftBuild(
269269
_ packagePath: AbsolutePath?,
270-
configuration: Configuration = .Debug,
270+
configuration: BuildConfiguration = .debug,
271271
extraArgs: [String] = [],
272272
Xcc: [String] = [],
273273
Xld: [String] = [],
@@ -302,7 +302,7 @@ public func skipOnWindowsAsTestCurrentlyFails(because reason: String? = nil) thr
302302
public func executeSwiftRun(
303303
_ packagePath: AbsolutePath?,
304304
_ executable: String?,
305-
configuration: Configuration = .Debug,
305+
configuration: BuildConfiguration = .debug,
306306
extraArgs: [String] = [],
307307
Xcc: [String] = [],
308308
Xld: [String] = [],
@@ -327,7 +327,7 @@ public func executeSwiftRun(
327327
@discardableResult
328328
public func executeSwiftPackage(
329329
_ packagePath: AbsolutePath?,
330-
configuration: Configuration = .Debug,
330+
configuration: BuildConfiguration = .debug,
331331
extraArgs: [String] = [],
332332
Xcc: [String] = [],
333333
Xld: [String] = [],
@@ -349,7 +349,7 @@ public func executeSwiftPackage(
349349
@discardableResult
350350
public func executeSwiftPackageRegistry(
351351
_ packagePath: AbsolutePath?,
352-
configuration: Configuration = .Debug,
352+
configuration: BuildConfiguration = .debug,
353353
extraArgs: [String] = [],
354354
Xcc: [String] = [],
355355
Xld: [String] = [],
@@ -371,7 +371,7 @@ public func executeSwiftPackageRegistry(
371371
@discardableResult
372372
public func executeSwiftTest(
373373
_ packagePath: AbsolutePath?,
374-
configuration: Configuration = .Debug,
374+
configuration: BuildConfiguration = .debug,
375375
extraArgs: [String] = [],
376376
Xcc: [String] = [],
377377
Xld: [String] = [],
@@ -392,7 +392,7 @@ public func executeSwiftTest(
392392
}
393393

394394
private func swiftArgs(
395-
configuration: Configuration,
395+
configuration: BuildConfiguration,
396396
extraArgs: [String],
397397
Xcc: [String],
398398
Xld: [String],
@@ -401,9 +401,9 @@ private func swiftArgs(
401401
) -> [String] {
402402
var args = ["--configuration"]
403403
switch configuration {
404-
case .Debug:
404+
case .debug:
405405
args.append("debug")
406-
case .Release:
406+
case .release:
407407
args.append("release")
408408
}
409409

Tests/CommandsTests/BuildCommandTests.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ class BuildCommandSwiftBuildTests: BuildCommandTestCases {
855855
}
856856

857857
override func testNonReachableProductsAndTargetsFunctional() async throws {
858-
throw XCTSkip("SWBINTTODO: Test failed. This needs to be investigated")
858+
try XCTSkipSwiftBuildTodo(because: "Test failed. This needs to be investigated")
859859
}
860860

861861
override func testParseableInterfaces() async throws {
@@ -877,7 +877,7 @@ class BuildCommandSwiftBuildTests: BuildCommandTestCases {
877877
}
878878

879879
override func testAutomaticParseableInterfacesWithLibraryEvolution() async throws {
880-
throw XCTSkip("SWBINTTODO: Test failed because of missing 'A.swiftmodule/*.swiftinterface' files")
880+
try XCTSkipSwiftBuildTodo(because: "Test failed because of missing 'A.swiftmodule/*.swiftinterface' files")
881881
// TODO: We still need to override this test just like we did for `testParseableInterfaces` above.
882882
}
883883

@@ -896,50 +896,50 @@ class BuildCommandSwiftBuildTests: BuildCommandTestCases {
896896
}
897897

898898
override func testGetTaskAllowEntitlement() async throws {
899-
throw XCTSkip("SWBINTTODO: Test failed because swiftbuild doesn't output precis codesign commands. Once swift run works with swiftbuild the test can be investigated.")
899+
try XCTSkipSwiftBuildTodo(because: "Test failed because swiftbuild doesn't output precis codesign commands. Once swift run works with swiftbuild the test can be investigated.")
900900
}
901901

902902
override func testCodeCoverage() async throws {
903-
throw XCTSkip("SWBINTTODO: Test failed because of missing plugin support in the PIF builder. This can be reinvestigated after the support is there.")
903+
try XCTSkipSwiftBuildTodo(because: "Test failed because of missing plugin support in the PIF builder. This can be reinvestigated after the support is there.")
904904
}
905905

906906
override func testAtMainSupport() async throws {
907907
#if !os(macOS)
908-
throw XCTSkip("SWBINTTODO: File not found or missing libclang errors on non-macOS platforms. This needs to be investigated")
908+
try XCTSkipSwiftBuildTodo(because: "File not found or missing libclang errors on non-macOS platforms. This needs to be investigated")
909909
#else
910910
try await super.testAtMainSupport()
911911
#endif
912912
}
913913

914914
override func testImportOfMissedDepWarning() async throws {
915-
throw XCTSkip("SWBINTTODO: Test fails because the warning message regarding missing imports is expected to be more verbose and actionable at the SwiftPM level with mention of the involved targets. This needs to be investigated. See case targetDiagnostic(TargetDiagnosticInfo) as a message type that may help.")
915+
try XCTSkipSwiftBuildTodo(because: "Test fails because the warning message regarding missing imports is expected to be more verbose and actionable at the SwiftPM level with mention of the involved targets. This needs to be investigated. See case targetDiagnostic(TargetDiagnosticInfo) as a message type that may help.")
916916
}
917917

918918
override func testProductAndTarget() async throws {
919-
throw XCTSkip("SWBINTTODO: Test fails because there isn't a clear warning message about the lib1 being an automatic product and that the default product is being built instead. This needs to be investigated")
919+
try XCTSkipSwiftBuildTodo(because: "Test fails because there isn't a clear warning message about the lib1 being an automatic product and that the default product is being built instead. This needs to be investigated")
920920
}
921921

922922
override func testSwiftGetVersion() async throws {
923-
throw XCTSkip("SWBINTTODO: Test fails because the dummy-swiftc used in the test isn't accepted by swift-build. This needs to be investigated")
923+
try XCTSkipSwiftBuildTodo(because: "Test fails because the dummy-swiftc used in the test isn't accepted by swift-build. This needs to be investigated")
924924
}
925925

926926
override func testSymlink() async throws {
927-
throw XCTSkip("SWBINTTODO: Test fails because of a difference in the build layout. This needs to be updated to the expected path")
927+
try XCTSkipSwiftBuildTodo(because: "Test fails because of a difference in the build layout. This needs to be updated to the expected path")
928928
}
929929

930930
#if !canImport(Darwin)
931931
override func testIgnoresLinuxMain() async throws {
932-
throw XCTSkip("SWBINTTODO: Swift build doesn't currently ignore Linux main when linking on Linux. This needs further investigation.")
932+
try XCTSkipSwiftBuildTodo(because: "Swift build doesn't currently ignore Linux main when linking on Linux. This needs further investigation.")
933933
}
934934
#endif
935935

936936
#if !os(macOS)
937937
override func testBuildStartMessage() async throws {
938-
throw XCTSkip("SWBINTTODO: Swift build produces an error building the fixture for this test.")
938+
try XCTSkipSwiftBuildTodo(because: "Swift build produces an error building the fixture for this test.")
939939
}
940940

941941
override func testSwiftDriverRawOutputGetsNewlines() async throws {
942-
throw XCTSkip("SWBINTTODO: Swift build produces an error building the fixture for this test.")
942+
try XCTSkipSwiftBuildTodo(because: "Swift build produces an error building the fixture for this test.")
943943
}
944944
#endif
945945

@@ -959,7 +959,7 @@ class BuildCommandSwiftBuildTests: BuildCommandTestCases {
959959

960960
override func testBuildCompleteMessage() async throws {
961961
#if os(Linux)
962-
throw XCTSkip("SWBINTTODO: Need to properly set LD_LIBRARY_PATH on linux")
962+
try XCTSkipSwiftBuildTodo(because: "Need to properly set LD_LIBRARY_PATH on linux")
963963
#else
964964
try await super.testBuildCompleteMessage()
965965
#endif

Tests/CommandsTests/MultiRootSupportTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import _InternalTestSupport
1616
import Workspace
1717
import XCTest
1818

19-
final class MultiRootSupportTests: CommandsTestCase {
19+
final class MultiRootSupportTests: XCTestCase {
2020
func testWorkspaceLoader() throws {
2121
let fs = InMemoryFileSystem(emptyFiles: [
2222
"/tmp/test/dep/Package.swift",

Tests/CommandsTests/PackageCommandTests.swift

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,7 +1385,7 @@ class PackageCommandTestCase: CommandsBuildProviderTestCase {
13851385

13861386
func testPackageClean() async throws {
13871387
try await fixture(name: "DependencyResolution/External/Simple") { fixturePath in
1388-
let packageRoot = fixturePath.appending("Bar")
1388+
let packageRoot: AbsolutePath = fixturePath.appending("Bar")
13891389

13901390
// Build it.
13911391
await XCTAssertBuilds(packageRoot)
@@ -1397,6 +1397,8 @@ class PackageCommandTestCase: CommandsBuildProviderTestCase {
13971397
// Clean, and check for removal of the build directory but not Packages.
13981398
_ = try await execute(["clean"], packagePath: packageRoot)
13991399
XCTAssertNoSuchPath(binFile)
1400+
XCTAssertFalse(try localFileSystem.getDirectoryContents(buildPath.appending("repositories")).isEmpty)
1401+
14001402
// Clean again to ensure we get no error.
14011403
_ = try await execute(["clean"], packagePath: packageRoot)
14021404
}
@@ -1412,15 +1414,10 @@ class PackageCommandTestCase: CommandsBuildProviderTestCase {
14121414
let binFile = buildPath.appending(components: try UserToolchain.default.targetTriple.platformBuildPathComponent, "debug", "Bar")
14131415
XCTAssertFileExists(binFile)
14141416
XCTAssert(localFileSystem.isDirectory(buildPath))
1415-
// Clean, and check for removal of the build directory but not Packages.
1416-
1417-
_ = try await execute(["clean"], packagePath: packageRoot)
1418-
XCTAssertNoSuchPath(binFile)
1419-
XCTAssertFalse(try localFileSystem.getDirectoryContents(buildPath.appending("repositories")).isEmpty)
14201417

14211418
// Fully clean.
14221419
_ = try await execute(["reset"], packagePath: packageRoot)
1423-
XCTAssertFalse(localFileSystem.isDirectory(buildPath))
1420+
XCTAssertFalse(localFileSystem.exists(buildPath))
14241421

14251422
// Test that we can successfully run reset again.
14261423
_ = try await execute(["reset"], packagePath: packageRoot)
@@ -3898,15 +3895,15 @@ class PackageCommandSwiftBuildTests: PackageCommandTestCase {
38983895
}
38993896

39003897
override func testCommandPluginBuildingCallbacks() async throws {
3901-
throw XCTSkip("SWBINTTODO: Test fails as plugins are not currenty supported")
3898+
try XCTSkipSwiftBuildTodo(because: "Test fails as plugins are not currenty supported")
39023899
}
39033900
override func testCommandPluginBuildTestability() async throws {
3904-
throw XCTSkip("SWBINTTODO: Test fails as plugins are not currenty supported")
3901+
try XCTSkipSwiftBuildTodo(because: "Test fails as plugins are not currenty supported")
39053902
}
39063903

39073904
#if !os(macOS)
39083905
override func testCommandPluginTestingCallbacks() async throws {
3909-
throw XCTSkip("SWBINTTODO: Test fails on inability to find libclang on Linux. Also, plugins are not currently supported")
3906+
try XCTSkipSwiftBuildTodo(because: "Test fails on inability to find libclang on Linux. Also, plugins are not currently supported")
39103907
}
39113908
#endif
39123909
}

Tests/CommandsTests/RunCommandTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,18 +255,18 @@ class RunCommandSwiftBuildTests: RunCommandTestCase {
255255
}
256256

257257
override func testMultipleExecutableAndExplicitExecutable() async throws {
258-
throw XCTSkip("SWBINTTODO: https://github.com/swiftlang/swift-package-manager/issues/8279: Swift run using Swift Build does not output executable content to the terminal")
258+
try XCTSkipSwiftBuildTodo(because: "https://github.com/swiftlang/swift-package-manager/issues/8279: Swift run using Swift Build does not output executable content to the terminal")
259259
}
260260

261261
override func testUnknownProductAndArgumentPassing() async throws {
262-
throw XCTSkip("SWBINTTODO: https://github.com/swiftlang/swift-package-manager/issues/8279: Swift run using Swift Build does not output executable content to the terminal")
262+
try XCTSkipSwiftBuildTodo(because: "https://github.com/swiftlang/swift-package-manager/issues/8279: Swift run using Swift Build does not output executable content to the terminal")
263263
}
264264

265265
override func testToolsetDebugger() async throws {
266-
throw XCTSkip("SWBINTTODO: Test fixture fails to build")
266+
try XCTSkipSwiftBuildTodo(because: "Test fixture fails to build")
267267
}
268268

269269
override func testUnreachableExecutable() async throws {
270-
throw XCTSkip("SWBINTTODO: Test fails because of build layout differences.")
270+
try XCTSkipSwiftBuildTodo(because: "Test fails because of build layout differences.")
271271
}
272272
}

0 commit comments

Comments
 (0)