diff --git a/IntegrationTests/Tests/IntegrationTests/SwiftPMTests.swift b/IntegrationTests/Tests/IntegrationTests/SwiftPMTests.swift index b69d6077426..0aae8cdc3d8 100644 --- a/IntegrationTests/Tests/IntegrationTests/SwiftPMTests.swift +++ b/IntegrationTests/Tests/IntegrationTests/SwiftPMTests.swift @@ -75,15 +75,6 @@ private struct SwiftPMTests { } @Test( - .requireThreadSafeWorkingDirectory, - arguments: [BuildSystemProvider.native] - ) - func packageInitExecutable(_ buildSystemProvider: BuildSystemProvider) throws { - try _packageInitExecutable(buildSystemProvider) - } - - @Test( - .skipHostOS(.windows), .requireThreadSafeWorkingDirectory, .bug( "https://github.com/swiftlang/swift-package-manager/issues/8416", @@ -93,13 +84,9 @@ private struct SwiftPMTests { "https://github.com/swiftlang/swift-package-manager/issues/8514", "[Windows] Integration test SwiftPMTests.packageInitExecutable with --build-system swiftbuild is skipped" ), - arguments: [BuildSystemProvider.swiftbuild] + arguments: BuildSystemProvider.allCases ) - func packageInitExecutablSkipWindows(_ buildSystemProvider: BuildSystemProvider) throws { - try _packageInitExecutable(buildSystemProvider) - } - - private func _packageInitExecutable(_ buildSystemProvider: BuildSystemProvider) throws { + private func packageInitExecutable(_ buildSystemProvider: BuildSystemProvider) throws { try withTemporaryDirectory { tmpDir in let packagePath = tmpDir.appending(component: "foo") try localFileSystem.createDirectory(packagePath) @@ -119,16 +106,16 @@ private struct SwiftPMTests { #expect(!runOutput.stderr.contains("error:")) #expect(runOutput.stdout.contains("Hello, world!")) } when: { - buildSystemProvider == .swiftbuild && ProcessInfo.hostOperatingSystem == .linux + buildSystemProvider == .swiftbuild && (ProcessInfo.hostOperatingSystem == .linux || ProcessInfo.hostOperatingSystem == .windows) } } } @Test( .requireThreadSafeWorkingDirectory, - .bug(id: 0, "SWBINTTODO: Linux: /lib/x86_64-linux-gnu/Scrt1.o:function _start: error:"), + .bug(id: 0, "SwiftBuildTodo: Linux: /lib/x86_64-linux-gnu/Scrt1.o:function _start: error:"), .bug("https://github.com/swiftlang/swift-package-manager/issues/8380", "lld-link: error: subsystem must be defined"), - .bug(id: 0, "SWBINTTODO: MacOS: Could not find or use auto-linked library 'Testing': library 'Testing' not found"), + .bug(id: 0, "SwiftBuildTodo: MacOS: Could not find or use auto-linked library 'Testing': library 'Testing' not found"), arguments: BuildSystemProvider.allCases ) func packageInitLibrary(_ buildSystemProvider: BuildSystemProvider) throws { diff --git a/Sources/SwiftBuildSupport/SwiftBuildSystem.swift b/Sources/SwiftBuildSupport/SwiftBuildSystem.swift index bdf91184927..d100c6e1dfb 100644 --- a/Sources/SwiftBuildSupport/SwiftBuildSystem.swift +++ b/Sources/SwiftBuildSupport/SwiftBuildSystem.swift @@ -59,13 +59,22 @@ func withService( func withSession( service: SWBBuildService, name: String, + toolchainPath: String, packageManagerResourcesDirectory: Basics.AbsolutePath?, body: @escaping ( _ session: SWBBuildServiceSession, _ diagnostics: [SwiftBuild.SwiftBuildMessage.DiagnosticInfo] ) async throws -> Void ) async throws { - switch await service.createSession(name: name, resourceSearchPaths: packageManagerResourcesDirectory.map { [$0.pathString] } ?? [], cachePath: nil, inferiorProductsPath: nil, environment: nil) { + switch await service.createSession( + name: name, + swiftToolchainPath: toolchainPath, + resourceSearchPaths: packageManagerResourcesDirectory.map { + [$0.pathString] + } ?? [], + cachePath: nil, inferiorProductsPath: nil, + environment: nil + ) { case (.success(let session), let diagnostics): do { try await body(session, diagnostics) @@ -260,7 +269,16 @@ public final class SwiftBuildSystem: SPMBuildCore.BuildSystem { ) do { - try await withSession(service: service, name: self.buildParameters.pifManifest.pathString, packageManagerResourcesDirectory: self.packageManagerResourcesDirectory) { session, _ in + let toolchainPath = self.buildParameters.toolchain.swiftCompilerPath + .parentDirectory // remove swift + .parentDirectory // remove bin + .parentDirectory // remove usr + try await withSession( + service: service, + name: self.buildParameters.pifManifest.pathString, + toolchainPath: toolchainPath.pathString, + packageManagerResourcesDirectory: self.packageManagerResourcesDirectory + ) { session, _ in self.outputStream.send("Building for \(self.buildParameters.configuration == .debug ? "debugging" : "production")...\n") // Load the workspace, and set the system information to the default diff --git a/Sources/_InternalTestSupport/Commands.swift b/Sources/_InternalTestSupport/Commands.swift index bb69f7b84dd..4a65e4f57bf 100644 --- a/Sources/_InternalTestSupport/Commands.swift +++ b/Sources/_InternalTestSupport/Commands.swift @@ -1,4 +1,5 @@ -import SPMBuildCore +import struct SPMBuildCore.BuildSystemProvider +import enum PackageModel.BuildConfiguration import XCTest open class BuildSystemProviderTestCase: XCTestCase { @@ -6,3 +7,14 @@ open class BuildSystemProviderTestCase: XCTestCase { fatalError("\(self) does not implement \(#function)") } } + +open class BuildConfigurationTestCase: BuildSystemProviderTestCase { + open var binPathSuffixes: [String] { + fatalError("\(self) does not implement \(#function)") + } + + open var buildConfig: BuildConfiguration { + fatalError("\(self) does not implement \(#function)") + } + +} diff --git a/Sources/_InternalTestSupport/XCTAssertHelpers.swift b/Sources/_InternalTestSupport/XCTAssertHelpers.swift index b558a0692bf..3819c2a9da8 100644 --- a/Sources/_InternalTestSupport/XCTAssertHelpers.swift +++ b/Sources/_InternalTestSupport/XCTAssertHelpers.swift @@ -15,6 +15,7 @@ import Basics import class Foundation.Bundle #endif import SPMBuildCore +import enum PackageModel.BuildConfiguration import TSCTestSupport import XCTest @@ -108,6 +109,10 @@ public func XCTSkipIfCompilerLessThan6_2() throws { #endif } +public func XCTSkipSwiftBuildTodo(because reason: String) throws { + throw XCTSkip("SwiftBuildTodo: \(reason)") +} + /// An `async`-friendly replacement for `XCTAssertThrowsError`. public func XCTAssertAsyncThrowsError( _ expression: @autoclosure () async throws -> T, @@ -139,7 +144,7 @@ package func XCTAssertAsyncNoThrow( public func XCTAssertBuilds( _ path: AbsolutePath, - configurations: Set = [.Debug, .Release], + configurations: Set = [.debug, .release], extraArgs: [String] = [], Xcc: [String] = [], Xld: [String] = [], @@ -169,7 +174,7 @@ public func XCTAssertBuilds( public func XCTAssertSwiftTest( _ path: AbsolutePath, - configuration: Configuration = .Debug, + configuration: BuildConfiguration = .debug, extraArgs: [String] = [], Xcc: [String] = [], Xld: [String] = [], diff --git a/Sources/_InternalTestSupport/misc.swift b/Sources/_InternalTestSupport/misc.swift index 94e3cb97c1f..b717a40861f 100644 --- a/Sources/_InternalTestSupport/misc.swift +++ b/Sources/_InternalTestSupport/misc.swift @@ -281,7 +281,7 @@ public func getBuildSystemArgs(for buildSystem: BuildSystemProvider.Kind?) -> [S @discardableResult public func executeSwiftBuild( _ packagePath: AbsolutePath?, - configuration: Configuration = .Debug, + configuration: BuildConfiguration = .debug, extraArgs: [String] = [], Xcc: [String] = [], Xld: [String] = [], @@ -304,7 +304,7 @@ public func executeSwiftBuild( public func executeSwiftRun( _ packagePath: AbsolutePath?, _ executable: String?, - configuration: Configuration = .Debug, + configuration: BuildConfiguration = .debug, extraArgs: [String] = [], Xcc: [String] = [], Xld: [String] = [], @@ -329,7 +329,7 @@ public func executeSwiftRun( @discardableResult public func executeSwiftPackage( _ packagePath: AbsolutePath?, - configuration: Configuration = .Debug, + configuration: BuildConfiguration = .debug, extraArgs: [String] = [], Xcc: [String] = [], Xld: [String] = [], @@ -351,7 +351,7 @@ public func executeSwiftPackage( @discardableResult public func executeSwiftPackageRegistry( _ packagePath: AbsolutePath?, - configuration: Configuration = .Debug, + configuration: BuildConfiguration = .debug, extraArgs: [String] = [], Xcc: [String] = [], Xld: [String] = [], @@ -373,7 +373,7 @@ public func executeSwiftPackageRegistry( @discardableResult public func executeSwiftTest( _ packagePath: AbsolutePath?, - configuration: Configuration = .Debug, + configuration: BuildConfiguration = .debug, extraArgs: [String] = [], Xcc: [String] = [], Xld: [String] = [], @@ -394,20 +394,14 @@ public func executeSwiftTest( } private func swiftArgs( - configuration: Configuration, + configuration: BuildConfiguration, extraArgs: [String], Xcc: [String], Xld: [String], Xswiftc: [String], buildSystem: BuildSystemProvider.Kind? ) -> [String] { - var args = ["--configuration"] - switch configuration { - case .Debug: - args.append("debug") - case .Release: - args.append("release") - } + var args = ["--configuration", "\(configuration)"] args += Xcc.flatMap { ["-Xcc", $0] } args += Xld.flatMap { ["-Xlinker", $0] } diff --git a/Tests/CommandsTests/BuildCommandTests.swift b/Tests/CommandsTests/BuildCommandTests.swift index 0f5b6a3093b..e4813447848 100644 --- a/Tests/CommandsTests/BuildCommandTests.swift +++ b/Tests/CommandsTests/BuildCommandTests.swift @@ -852,7 +852,7 @@ class BuildCommandSwiftBuildTests: BuildCommandTestCases { } override func testNonReachableProductsAndTargetsFunctional() async throws { - throw XCTSkip("SWBINTTODO: Test failed. This needs to be investigated") + try XCTSkipSwiftBuildTodo(because: "Test failed. This needs to be investigated") } override func testParseableInterfaces() async throws { @@ -871,7 +871,7 @@ class BuildCommandSwiftBuildTests: BuildCommandTestCases { } override func testAutomaticParseableInterfacesWithLibraryEvolution() async throws { - throw XCTSkip("SWBINTTODO: Test failed because of missing 'A.swiftmodule/*.swiftinterface' files") + try XCTSkipSwiftBuildTodo(because: "Test failed because of missing 'A.swiftmodule/*.swiftinterface' files") // TODO: We still need to override this test just like we did for `testParseableInterfaces` above. } @@ -890,50 +890,50 @@ class BuildCommandSwiftBuildTests: BuildCommandTestCases { } override func testGetTaskAllowEntitlement() async throws { - throw XCTSkip("SWBINTTODO: Test failed because swiftbuild doesn't output precis codesign commands. Once swift run works with swiftbuild the test can be investigated.") + try XCTSkipSwiftBuildTodo(because: "Test failed because swiftbuild doesn't output precis codesign commands. Once swift run works with swiftbuild the test can be investigated.") } override func testCodeCoverage() async throws { - throw XCTSkip("SWBINTTODO: Test failed because of missing plugin support in the PIF builder. This can be reinvestigated after the support is there.") + try XCTSkipSwiftBuildTodo(because: "Test failed because of missing plugin support in the PIF builder. This can be reinvestigated after the support is there.") } override func testAtMainSupport() async throws { #if !os(macOS) - throw XCTSkip("SWBINTTODO: File not found or missing libclang errors on non-macOS platforms. This needs to be investigated") + try XCTSkipSwiftBuildTodo(because: "File not found or missing libclang errors on non-macOS platforms. This needs to be investigated") #else try await super.testAtMainSupport() #endif } override func testImportOfMissedDepWarning() async throws { - 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.") + 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.") } override func testProductAndTarget() async throws { - 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") + 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") } override func testSwiftGetVersion() async throws { - throw XCTSkip("SWBINTTODO: Test fails because the dummy-swiftc used in the test isn't accepted by swift-build. This needs to be investigated") + try XCTSkipSwiftBuildTodo(because: "Test fails because the dummy-swiftc used in the test isn't accepted by swift-build. This needs to be investigated") } override func testSymlink() async throws { - throw XCTSkip("SWBINTTODO: Test fails because of a difference in the build layout. This needs to be updated to the expected path") + try XCTSkipSwiftBuildTodo(because: "Test fails because of a difference in the build layout. This needs to be updated to the expected path") } #if os(Linux) override func testIgnoresLinuxMain() async throws { - throw XCTSkip("SWBINTTODO: Swift build doesn't currently ignore Linux main when linking on Linux. This needs further investigation.") + try XCTSkipSwiftBuildTodo(because: "Swift build doesn't currently ignore Linux main when linking on Linux. This needs further investigation.") } #endif #if !os(macOS) override func testBuildStartMessage() async throws { - throw XCTSkip("SWBINTTODO: Swift build produces an error building the fixture for this test.") + try XCTSkipSwiftBuildTodo(because: "Swift build produces an error building the fixture for this test.") } override func testSwiftDriverRawOutputGetsNewlines() async throws { - throw XCTSkip("SWBINTTODO: Swift build produces an error building the fixture for this test.") + try XCTSkipSwiftBuildTodo(because: "Swift build produces an error building the fixture for this test.") } #endif diff --git a/Tests/CommandsTests/MultiRootSupportTests.swift b/Tests/CommandsTests/MultiRootSupportTests.swift index ae317528862..e83a685db4b 100644 --- a/Tests/CommandsTests/MultiRootSupportTests.swift +++ b/Tests/CommandsTests/MultiRootSupportTests.swift @@ -16,7 +16,7 @@ import _InternalTestSupport import Workspace import XCTest -final class MultiRootSupportTests: CommandsTestCase { +final class MultiRootSupportTests: XCTestCase { func testWorkspaceLoader() throws { let fs = InMemoryFileSystem(emptyFiles: [ "/tmp/test/dep/Package.swift", diff --git a/Tests/CommandsTests/PackageCommandTests.swift b/Tests/CommandsTests/PackageCommandTests.swift index 1a7517811c9..e22b43ff8b8 100644 --- a/Tests/CommandsTests/PackageCommandTests.swift +++ b/Tests/CommandsTests/PackageCommandTests.swift @@ -1496,7 +1496,7 @@ class PackageCommandTestCase: CommandsBuildProviderTestCase { func testPackageClean() async throws { try await fixture(name: "DependencyResolution/External/Simple") { fixturePath in - let packageRoot = fixturePath.appending("Bar") + let packageRoot: AbsolutePath = fixturePath.appending("Bar") // Build it. await XCTAssertBuilds(packageRoot) @@ -1508,6 +1508,8 @@ class PackageCommandTestCase: CommandsBuildProviderTestCase { // Clean, and check for removal of the build directory but not Packages. _ = try await execute(["clean"], packagePath: packageRoot) XCTAssertNoSuchPath(binFile) + XCTAssertFalse(try localFileSystem.getDirectoryContents(buildPath.appending("repositories")).isEmpty) + // Clean again to ensure we get no error. _ = try await execute(["clean"], packagePath: packageRoot) } @@ -1523,15 +1525,10 @@ class PackageCommandTestCase: CommandsBuildProviderTestCase { let binFile = buildPath.appending(components: try UserToolchain.default.targetTriple.platformBuildPathComponent, "debug", executableName("Bar")) XCTAssertFileExists(binFile) XCTAssert(localFileSystem.isDirectory(buildPath)) - // Clean, and check for removal of the build directory but not Packages. - - _ = try await execute(["clean"], packagePath: packageRoot) - XCTAssertNoSuchPath(binFile) - XCTAssertFalse(try localFileSystem.getDirectoryContents(buildPath.appending("repositories")).isEmpty) // Fully clean. _ = try await execute(["reset"], packagePath: packageRoot) - XCTAssertFalse(localFileSystem.isDirectory(buildPath)) + XCTAssertFalse(localFileSystem.exists(buildPath)) // Test that we can successfully run reset again. _ = try await execute(["reset"], packagePath: packageRoot) @@ -4063,10 +4060,10 @@ class PackageCommandSwiftBuildTests: PackageCommandTestCase { } override func testCommandPluginBuildingCallbacks() async throws { - throw XCTSkip("SWBINTTODO: Test fails because plugin is not producing expected output to stdout.") + try XCTSkipSwiftBuildTodo(because: "Test fails because plugin is not producing expected output to stdout") } override func testCommandPluginBuildTestability() async throws { - throw XCTSkip("SWBINTTODO: Test fails as plugins are not currenty supported") + try XCTSkipSwiftBuildTodo(because: "Test fails as plugins are not currenty supported") } override func testMigrateCommand() async throws { diff --git a/Tests/CommandsTests/RunCommandTests.swift b/Tests/CommandsTests/RunCommandTests.swift index c831e911e54..1d8b3edf2de 100644 --- a/Tests/CommandsTests/RunCommandTests.swift +++ b/Tests/CommandsTests/RunCommandTests.swift @@ -259,18 +259,18 @@ class RunCommandSwiftBuildTests: RunCommandTestCase { } override func testMultipleExecutableAndExplicitExecutable() async throws { - 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") + 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") } override func testUnknownProductAndArgumentPassing() async throws { - 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") + 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") } override func testToolsetDebugger() async throws { - throw XCTSkip("SWBINTTODO: Test fixture fails to build") + try XCTSkipSwiftBuildTodo(because: "Test fixture fails to build") } override func testUnreachableExecutable() async throws { - throw XCTSkip("SWBINTTODO: Test fails because of build layout differences.") + try XCTSkipSwiftBuildTodo(because: "Test fails because of build layout differences.") } } diff --git a/Tests/CommandsTests/TestCommandTests.swift b/Tests/CommandsTests/TestCommandTests.swift index 47f4931b4f6..207d3eae51b 100644 --- a/Tests/CommandsTests/TestCommandTests.swift +++ b/Tests/CommandsTests/TestCommandTests.swift @@ -646,54 +646,54 @@ class TestCommandSwiftBuildTests: TestCommandTestCase { } override func testList() async throws { - throw XCTSkip("SWBINTTODO: Test currently fails due to 'error: build failed'") + try XCTSkipSwiftBuildTodo(because: "Test currently fails due to 'error: build failed'") } override func testEnableTestDiscoveryDeprecation() async throws { - throw XCTSkip("SWBINTTODO: Test currently fails due to 'error: build failed'") + try XCTSkipSwiftBuildTodo(because: "Test currently fails due to 'error: build failed'") } override func testEnableDisableTestability() async throws { - throw XCTSkip("SWBINTTODO: Test currently fails due to 'error: build failed'") + try XCTSkipSwiftBuildTodo(because: "Test currently fails due to 'error: build failed'") } override func testToolsetRunner() async throws { - throw XCTSkip("SWBINTTODO: Test currently fails, as some assertions are not met") + try XCTSkipSwiftBuildTodo(because: "Test currently fails, as some assertions are not met") } override func testWithReleaseConfiguration() async throws { - throw XCTSkip("SWBINTTODO: Test currently fails with 'error: toolchain is invalid: could not find CLI tool `swiftpm-testing-helper` at any of these directories: [..., ...]'") + try XCTSkipSwiftBuildTodo(because: "Test currently fails with 'error: toolchain is invalid: could not find CLI tool `swiftpm-testing-helper` at any of these directories: [..., ...]'") } override func testXCTestOnlyDoesNotLogAboutNoMatchingTests() async throws { - throw XCTSkip("SWBINTTODO: Test currently fails assertion as the there is a different error message 'error: no tests found; create a target in the 'Tests' directory'") + try XCTSkipSwiftBuildTodo(because: "Test currently fails assertion as the there is a different error message 'error: no tests found; create a target in the 'Tests' directory'") } override func testSwiftTestXMLOutputVerifyMultipleTestFailureMessageWithFlagEnabledSwiftTesting() async throws { - throw XCTSkip("SWBINTTODO: Test currently fails assertion as the there is a different error message 'error: no tests found; create a target in the 'Tests' directory'") + try XCTSkipSwiftBuildTodo(because: "Test currently fails assertion as the there is a different error message 'error: no tests found; create a target in the 'Tests' directory'") } override func testSwiftTestXMLOutputVerifySingleTestFailureMessageWithFlagDisabledSwiftTesting() async throws { - throw XCTSkip("SWBINTTODO: Test currently fails, further investigation is needed") + try XCTSkipSwiftBuildTodo(because: "Test currently fails, further investigation is needed") } override func testSwiftTestXMLOutputVerifySingleTestFailureMessageWithFlagEnabledSwiftTesting() async throws { - throw XCTSkip("SWBINTTODO: Test currently fails, further investigation is needed") + try XCTSkipSwiftBuildTodo(because: "Test currently fails, further investigation is needed") } override func testSwiftTestXMLOutputVerifyMultipleTestFailureMessageWithFlagDisabledSwiftTesting() async throws { - throw XCTSkip("SWBINTTODO: Test currently fails, further investigation is needed") + try XCTSkipSwiftBuildTodo(because: "Test currently fails, further investigation is needed") } #if !canImport(Darwin) override func testGeneratedMainIsExistentialAnyClean() async throws { - throw XCTSkip("SWBINTTODO: This is a PIF builder missing GUID problem. Further investigation is needed.") + try XCTSkipSwiftBuildTodo(because: "This is a PIF builder missing GUID problem. Further investigation is needed.") } #endif #if !canImport(Darwin) override func testGeneratedMainIsConcurrencySafe_XCTest() async throws { - throw XCTSkip("SWBINTTODO: This is a PIF builder missing GUID problem. Further investigation is needed.") + try XCTSkipSwiftBuildTodo(because: "This is a PIF builder missing GUID problem. Further investigation is needed.") } #endif diff --git a/Tests/FunctionalTests/CFamilyTargetTests.swift b/Tests/FunctionalTests/CFamilyTargetTests.swift index 7f7b5c92245..c233977b295 100644 --- a/Tests/FunctionalTests/CFamilyTargetTests.swift +++ b/Tests/FunctionalTests/CFamilyTargetTests.swift @@ -19,9 +19,32 @@ import SourceControl import _InternalTestSupport import Workspace import XCTest +import struct SPMBuildCore.BuildSystemProvider import class Basics.AsyncProcess + +class CFamilyTargetNativeTestCase: CFamilyTargetTestCase { + override open var buildSystemProvider: BuildSystemProvider.Kind { + return .native + } + + override func testCLibraryWithSpaces() async throws { + try await super.testCLibraryWithSpaces() + } +} + +class CFamilyTargetSwiftBuildTestCase: CFamilyTargetTestCase { + override open var buildSystemProvider: BuildSystemProvider.Kind { + return .native + } + + override func testCLibraryWithSpaces() async throws { + try await super.testCLibraryWithSpaces() + } + +} + /// Asserts if a directory (recursively) contains a file. private func XCTAssertDirectoryContainsFile(dir: AbsolutePath, filename: String, file: StaticString = #file, line: UInt = #line) { do { @@ -34,10 +57,14 @@ private func XCTAssertDirectoryContainsFile(dir: AbsolutePath, filename: String, XCTFail("Directory \(dir) does not contain \(file)", file: file, line: line) } -final class CFamilyTargetTestCase: XCTestCase { +class CFamilyTargetTestCase: BuildSystemProviderTestCase { + override func setUpWithError() throws { + try XCTSkipIf(type(of: self) == CFamilyTargetTestCase.self, "Pay no attention to the class behind the curtain.") + } + func testCLibraryWithSpaces() async throws { try await fixture(name: "CFamilyTargets/CLibraryWithSpaces") { fixturePath in - await XCTAssertBuilds(fixturePath) + await XCTAssertBuilds(fixturePath, buildSystem: self.buildSystemProvider) let debugPath = fixturePath.appending(components: ".build", try UserToolchain.default.targetTriple.platformBuildPathComponent, "debug") XCTAssertDirectoryContainsFile(dir: debugPath, filename: "Bar.c.o") XCTAssertDirectoryContainsFile(dir: debugPath, filename: "Foo.c.o") @@ -47,7 +74,7 @@ final class CFamilyTargetTestCase: XCTestCase { func testCUsingCAndSwiftDep() async throws { try await fixture(name: "DependencyResolution/External/CUsingCDep") { fixturePath in let packageRoot = fixturePath.appending("Bar") - await XCTAssertBuilds(packageRoot) + await XCTAssertBuilds(packageRoot, buildSystem: self.buildSystemProvider) let debugPath = fixturePath.appending(components: "Bar", ".build", try UserToolchain.default.targetTriple.platformBuildPathComponent, "debug") XCTAssertDirectoryContainsFile(dir: debugPath, filename: "Sea.c.o") XCTAssertDirectoryContainsFile(dir: debugPath, filename: "Foo.c.o") @@ -58,7 +85,7 @@ final class CFamilyTargetTestCase: XCTestCase { func testModuleMapGenerationCases() async throws { try await fixture(name: "CFamilyTargets/ModuleMapGenerationCases") { fixturePath in - await XCTAssertBuilds(fixturePath) + await XCTAssertBuilds(fixturePath, buildSystem: self.buildSystemProvider) let debugPath = fixturePath.appending(components: ".build", try UserToolchain.default.targetTriple.platformBuildPathComponent, "debug") XCTAssertDirectoryContainsFile(dir: debugPath, filename: "Jaz.c.o") XCTAssertDirectoryContainsFile(dir: debugPath, filename: "main.swift.o") @@ -69,7 +96,7 @@ final class CFamilyTargetTestCase: XCTestCase { func testNoIncludeDirCheck() async throws { try await fixture(name: "CFamilyTargets/CLibraryNoIncludeDir") { fixturePath in - await XCTAssertAsyncThrowsError(try await executeSwiftBuild(fixturePath), "This build should throw an error") { err in + await XCTAssertAsyncThrowsError(try await executeSwiftBuild(fixturePath, buildSystem: self.buildSystemProvider), "This build should throw an error") { err in // The err.localizedDescription doesn't capture the detailed error string so interpolate let errStr = "\(err)" let missingIncludeDirStr = "\(ModuleError.invalidPublicHeadersDirectory("Cfactorial"))" @@ -81,7 +108,7 @@ final class CFamilyTargetTestCase: XCTestCase { func testCanForwardExtraFlagsToClang() async throws { // Try building a fixture which needs extra flags to be able to build. try await fixture(name: "CFamilyTargets/CDynamicLookup") { fixturePath in - await XCTAssertBuilds(fixturePath, Xld: ["-undefined", "dynamic_lookup"]) + await XCTAssertBuilds(fixturePath, Xld: ["-undefined", "dynamic_lookup"], buildSystem: self.buildSystemProvider) let debugPath = fixturePath.appending(components: ".build", try UserToolchain.default.targetTriple.platformBuildPathComponent, "debug") XCTAssertDirectoryContainsFile(dir: debugPath, filename: "Foo.c.o") } @@ -93,7 +120,7 @@ final class CFamilyTargetTestCase: XCTestCase { #endif try await fixture(name: "CFamilyTargets/ObjCmacOSPackage") { fixturePath in // Build the package. - await XCTAssertBuilds(fixturePath) + await XCTAssertBuilds(fixturePath, buildSystem: self.buildSystemProvider) XCTAssertDirectoryContainsFile(dir: fixturePath.appending(components: ".build", try UserToolchain.default.targetTriple.platformBuildPathComponent, "debug"), filename: "HelloWorldExample.m.o") // Run swift-test on package. await XCTAssertSwiftTest(fixturePath) @@ -102,7 +129,7 @@ final class CFamilyTargetTestCase: XCTestCase { func testCanBuildRelativeHeaderSearchPaths() async throws { try await fixture(name: "CFamilyTargets/CLibraryParentSearchPath") { fixturePath in - await XCTAssertBuilds(fixturePath) + await XCTAssertBuilds(fixturePath, buildSystem: self.buildSystemProvider) XCTAssertDirectoryContainsFile(dir: fixturePath.appending(components: ".build", try UserToolchain.default.targetTriple.platformBuildPathComponent, "debug"), filename: "HeaderInclude.swiftmodule") } } diff --git a/Tests/FunctionalTests/MacroTests.swift b/Tests/FunctionalTests/MacroTests.swift index ad394a48ad8..edd50144902 100644 --- a/Tests/FunctionalTests/MacroTests.swift +++ b/Tests/FunctionalTests/MacroTests.swift @@ -26,7 +26,7 @@ class MacroTests: XCTestCase { try XCTSkipIf(!localFileSystem.exists(libSwiftSyntaxMacrosPath), "test need `libSwiftSyntaxMacros` to exist in the host toolchain") try fixture(name: "Macros") { fixturePath in - let (stdout, _) = try executeSwiftBuild(fixturePath.appending("MacroPackage"), configuration: .Debug) + let (stdout, _) = try executeSwiftBuild(fixturePath.appending("MacroPackage"), configuration: .debug) XCTAssert(stdout.contains("@__swiftmacro_11MacroClient11fontLiteralfMf_.swift as Font"), "stdout:\n\(stdout)") XCTAssert(stdout.contains("Build complete!"), "stdout:\n\(stdout)") } diff --git a/Tests/FunctionalTests/PluginTests.swift b/Tests/FunctionalTests/PluginTests.swift index 3e7a0b78640..93785e63773 100644 --- a/Tests/FunctionalTests/PluginTests.swift +++ b/Tests/FunctionalTests/PluginTests.swift @@ -29,7 +29,7 @@ final class PluginTests: XCTestCase { try XCTSkipIf(!UserToolchain.default.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency") try await fixture(name: "Miscellaneous/Plugins") { fixturePath in - let (stdout, _) = try await executeSwiftBuild(fixturePath.appending("MySourceGenPlugin"), configuration: .Debug, extraArgs: ["--product", "MyLocalTool"]) + let (stdout, _) = try await executeSwiftBuild(fixturePath.appending("MySourceGenPlugin"), configuration: .debug, extraArgs: ["--product", "MyLocalTool"]) XCTAssert(stdout.contains("Linking MySourceGenBuildTool"), "stdout:\n\(stdout)") XCTAssert(stdout.contains("Generating foo.swift from foo.dat"), "stdout:\n\(stdout)") XCTAssert(stdout.contains("Linking MyLocalTool"), "stdout:\n\(stdout)") @@ -53,7 +53,7 @@ final class PluginTests: XCTestCase { try XCTSkipIf(!UserToolchain.default.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency") try await fixture(name: "Miscellaneous/Plugins") { fixturePath in - let (stdout, _) = try await executeSwiftBuild(fixturePath.appending("MySourceGenClient"), configuration: .Debug, extraArgs: ["--product", "MyTool"]) + let (stdout, _) = try await executeSwiftBuild(fixturePath.appending("MySourceGenClient"), configuration: .debug, extraArgs: ["--product", "MyTool"]) XCTAssert(stdout.contains("Linking MySourceGenBuildTool"), "stdout:\n\(stdout)") XCTAssert(stdout.contains("Generating foo.swift from foo.dat"), "stdout:\n\(stdout)") XCTAssert(stdout.contains("Linking MyTool"), "stdout:\n\(stdout)") @@ -67,7 +67,7 @@ final class PluginTests: XCTestCase { try XCTSkipIf(!UserToolchain.default.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency") try await fixture(name: "Miscellaneous/Plugins") { fixturePath in - let (stdout, _) = try await executeSwiftBuild(fixturePath.appending("MySourceGenPlugin"), configuration: .Debug, extraArgs: ["--product", "MyOtherLocalTool"]) + let (stdout, _) = try await executeSwiftBuild(fixturePath.appending("MySourceGenPlugin"), configuration: .debug, extraArgs: ["--product", "MyOtherLocalTool"]) XCTAssert(stdout.contains("Compiling MyOtherLocalTool bar.swift"), "stdout:\n\(stdout)") XCTAssert(stdout.contains("Compiling MyOtherLocalTool baz.swift"), "stdout:\n\(stdout)") XCTAssert(stdout.contains("Linking MyOtherLocalTool"), "stdout:\n\(stdout)") @@ -140,7 +140,7 @@ final class PluginTests: XCTestCase { try XCTSkipIf(!UserToolchain.default.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency") try await fixture(name: "Miscellaneous/Plugins") { fixturePath in - let (stdout, _) = try await executeSwiftBuild(fixturePath.appending("ContrivedTestPlugin"), configuration: .Debug, extraArgs: ["--product", "MyLocalTool"]) + let (stdout, _) = try await executeSwiftBuild(fixturePath.appending("ContrivedTestPlugin"), configuration: .debug, extraArgs: ["--product", "MyLocalTool"]) XCTAssert(stdout.contains("Linking MySourceGenBuildTool"), "stdout:\n\(stdout)") XCTAssert(stdout.contains("Generating foo.swift from foo.dat"), "stdout:\n\(stdout)") XCTAssert(stdout.contains("Linking MyLocalTool"), "stdout:\n\(stdout)") @@ -155,7 +155,7 @@ final class PluginTests: XCTestCase { // Only run the test if the environment in which we're running actually supports Swift concurrency (which the plugin APIs require). try XCTSkipIf(!UserToolchain.default.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency") try await fixture(name: "Miscellaneous/Plugins") { fixturePath in - let (stdout, _) = try await executeSwiftBuild(fixturePath.appending("SandboxTesterPlugin"), configuration: .Debug, extraArgs: ["--product", "MyLocalTool"]) + let (stdout, _) = try await executeSwiftBuild(fixturePath.appending("SandboxTesterPlugin"), configuration: .debug, extraArgs: ["--product", "MyLocalTool"]) XCTAssert(stdout.contains("Linking MyLocalTool"), "stdout:\n\(stdout)") XCTAssert(stdout.contains("Build of product 'MyLocalTool' complete!"), "stdout:\n\(stdout)") } @@ -168,7 +168,7 @@ final class PluginTests: XCTestCase { // Only run the test if the environment in which we're running actually supports Swift concurrency (which the plugin APIs require). try XCTSkipIf(!UserToolchain.default.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency") try await fixture(name: "Miscellaneous/Plugins") { fixturePath in - let (stdout, _) = try await executeSwiftBuild(fixturePath.appending("MyBinaryToolPlugin"), configuration: .Debug, extraArgs: ["--product", "MyLocalTool"]) + let (stdout, _) = try await executeSwiftBuild(fixturePath.appending("MyBinaryToolPlugin"), configuration: .debug, extraArgs: ["--product", "MyLocalTool"]) XCTAssert(stdout.contains("Linking MyLocalTool"), "stdout:\n\(stdout)") XCTAssert(stdout.contains("Build of product 'MyLocalTool' complete!"), "stdout:\n\(stdout)") } @@ -181,7 +181,7 @@ final class PluginTests: XCTestCase { // Only run the test if the environment in which we're running actually supports Swift concurrency (which the plugin APIs require). try XCTSkipIf(!UserToolchain.default.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency") try await fixture(name: "Miscellaneous/Plugins") { fixturePath in - let (stdout, _) = try await executeSwiftBuild(fixturePath.appending("BinaryToolProductPlugin"), configuration: .Debug, extraArgs: ["--product", "MyLocalTool"]) + let (stdout, _) = try await executeSwiftBuild(fixturePath.appending("BinaryToolProductPlugin"), configuration: .debug, extraArgs: ["--product", "MyLocalTool"]) XCTAssert(stdout.contains("Linking MyLocalTool"), "stdout:\n\(stdout)") XCTAssert(stdout.contains("Build of product 'MyLocalTool' complete!"), "stdout:\n\(stdout)") } @@ -617,7 +617,7 @@ final class PluginTests: XCTestCase { try XCTSkipIf(!UserToolchain.default.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency") try await fixture(name: "Miscellaneous/Plugins/PluginUsingLocalAndRemoteTool") { path in - let (stdout, stderr) = try await executeSwiftPackage(path.appending("MyLibrary"), configuration: .Debug, extraArgs: ["plugin", "my-plugin"]) + let (stdout, stderr) = try await executeSwiftPackage(path.appending("MyLibrary"), configuration: .debug, extraArgs: ["plugin", "my-plugin"]) XCTAssert(stderr.contains("Linking RemoteTool"), "stdout:\n\(stderr)\n\(stdout)") XCTAssert(stderr.contains("Linking LocalTool"), "stdout:\n\(stderr)\n\(stdout)") XCTAssert(stderr.contains("Linking ImpliedLocalTool"), "stdout:\n\(stderr)\n\(stdout)") @@ -1082,7 +1082,7 @@ final class PluginTests: XCTestCase { try XCTSkipIf(!UserToolchain.default.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency") try await fixture(name: "Miscellaneous/Plugins") { path in - let (stdout, stderr) = try await executeSwiftPackage(path.appending("PluginsAndSnippets"), configuration: .Debug, extraArgs: ["do-something"]) + let (stdout, stderr) = try await executeSwiftPackage(path.appending("PluginsAndSnippets"), configuration: .debug, extraArgs: ["do-something"]) XCTAssert(stdout.contains("type of snippet target: snippet"), "output:\n\(stderr)\n\(stdout)") } } @@ -1106,14 +1106,14 @@ final class PluginTests: XCTestCase { // Check that the build fails with a sandbox violation by default. try await fixture(name: "Miscellaneous/Plugins/SandboxViolatingBuildToolPluginCommands") { path in - await XCTAssertAsyncThrowsError(try await executeSwiftBuild(path.appending("MyLibrary"), configuration: .Debug)) { error in + await XCTAssertAsyncThrowsError(try await executeSwiftBuild(path.appending("MyLibrary"), configuration: .debug)) { error in XCTAssertMatch("\(error)", .contains("You don’t have permission to save the file “generated” in the folder “MyLibrary”.")) } } // Check that the build succeeds if we disable the sandbox. try await fixture(name: "Miscellaneous/Plugins/SandboxViolatingBuildToolPluginCommands") { path in - let (stdout, stderr) = try await executeSwiftBuild(path.appending("MyLibrary"), configuration: .Debug, extraArgs: ["--disable-sandbox"]) + let (stdout, stderr) = try await executeSwiftBuild(path.appending("MyLibrary"), configuration: .debug, extraArgs: ["--disable-sandbox"]) XCTAssert(stdout.contains("Compiling MyLibrary foo.swift"), "[STDOUT]\n\(stdout)\n[STDERR]\n\(stderr)\n") } @@ -1168,7 +1168,7 @@ final class PluginTests: XCTestCase { try await fixture(name: "Miscellaneous/Plugins") { fixturePath in let (stdout, _) = try await executeSwiftBuild( fixturePath.appending(component: "MySourceGenPlugin"), - configuration: .Debug, + configuration: .debug, extraArgs: ["--product", "MyLocalTool", "-Xbuild-tools-swiftc", "-DUSE_CREATE"] ) XCTAssert(stdout.contains("Linking MySourceGenBuildTool"), "stdout:\n\(stdout)") @@ -1184,7 +1184,7 @@ final class PluginTests: XCTestCase { try XCTSkipIf(!UserToolchain.default.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency") try await fixture(name: "Miscellaneous/Plugins/MySourceGenPluginUsingURLBasedAPI") { fixturePath in - let (stdout, _) = try await executeSwiftBuild(fixturePath, configuration: .Debug) + let (stdout, _) = try await executeSwiftBuild(fixturePath, configuration: .debug) XCTAssert(stdout.contains("Build complete!"), "stdout:\n\(stdout)") } } diff --git a/Tests/FunctionalTests/ResourcesTests.swift b/Tests/FunctionalTests/ResourcesTests.swift index 2dd37feff13..44ca9e5293b 100644 --- a/Tests/FunctionalTests/ResourcesTests.swift +++ b/Tests/FunctionalTests/ResourcesTests.swift @@ -14,8 +14,87 @@ import Basics import PackageModel import _InternalTestSupport import XCTest +import struct SPMBuildCore.BuildSystemProvider + +class ResourcesNativeDebugConfigTests: ResourcesTestCase { + override open var buildSystemProvider: BuildSystemProvider.Kind { + return .native + } + + override public var binPathSuffixes: [String] { + ["debug"] + } + + override public var buildConfig: BuildConfiguration { + .debug + } +} + +class ResourcesNativeReleaseConfigTests: ResourcesTestCase { + override open var buildSystemProvider: BuildSystemProvider.Kind { + return .native + } + + override public var binPathSuffixes: [String] { + ["release"] + } + + override public var buildConfig: BuildConfiguration { + .release + } +} + +class ResourcesSwiftBuildDebugConfigTests: ResourcesTestCase { + + override open var buildSystemProvider: BuildSystemProvider.Kind { + return .swiftbuild + } + + override public var binPathSuffixes: [String] { + ["Products" , "Debug"] + } + + override public var buildConfig: BuildConfiguration { + .debug + } + + override func testResourcesInMixedClangPackage() async throws { + #if os(macOS) + try XCTSkipSwiftBuildTodo(because: "Fails to build: Found multiple targets named 'MixedClangResource'") + #else + try await super.testResourcesInMixedClangPackage() + #endif + } + + override func testResourcesEmbeddedInCode() async throws { + #if os(macOS) + try XCTSkipSwiftBuildTodo(because: "Fails to build: cannot find 'PackageResources' in scope") + #else + try await super.testResourcesEmbeddedInCode() + #endif + } +} + +class ResourcesSwiftBuildReleaseConfigTests: ResourcesTestCase { + + override open var buildSystemProvider: BuildSystemProvider.Kind { + return .swiftbuild + } + + override public var binPathSuffixes: [String] { + ["Products" , "Release"] + } + + override public var buildConfig: BuildConfiguration { + .release + } +} + +class ResourcesTestCase: BuildConfigurationTestCase { + override func setUpWithError() throws { + try XCTSkipIf(type(of: self) == ResourcesTestCase.self, "Pay no attention to the class behind the curtain.") + } -final class ResourcesTests: XCTestCase { func testSimpleResources() async throws { try await fixture(name: "Resources/Simple") { fixturePath in var executables = ["SwiftyResource"] @@ -27,7 +106,7 @@ final class ResourcesTests: XCTestCase { #endif for execName in executables { - let (output, _) = try await executeSwiftRun(fixturePath, execName) + let (output, _) = try await executeSwiftRun(fixturePath, execName, buildSystem: self.buildSystemProvider) XCTAssertTrue(output.contains("foo"), output) } } @@ -35,7 +114,7 @@ final class ResourcesTests: XCTestCase { func testLocalizedResources() async throws { try await fixture(name: "Resources/Localized") { fixturePath in - try await executeSwiftBuild(fixturePath) + try await executeSwiftBuild(fixturePath, configuration: self.buildConfig, buildSystem: self.buildSystemProvider) let exec = AbsolutePath(".build/debug/exe", relativeTo: fixturePath) // Note: Source from LANG and -AppleLanguages on command line for Linux resources @@ -50,13 +129,13 @@ final class ResourcesTests: XCTestCase { } func testResourcesInMixedClangPackage() async throws { - #if !os(macOS) - // Running swift-test fixtures on linux is not yet possible. - try XCTSkipIf(true, "test is only supported on macOS") - #endif + // #if !os(macOS) + // // Running swift-test fixtures on linux is not yet possible. + // try XCTSkipIf(true, "test is only supported on macOS") + // #endif try await fixture(name: "Resources/Simple") { fixturePath in - await XCTAssertBuilds(fixturePath, extraArgs: ["--target", "MixedClangResource"]) + await XCTAssertBuilds(fixturePath, configurations: [self.buildConfig], extraArgs: ["--target", "MixedClangResource"], buildSystem: self.buildSystemProvider) } } @@ -70,12 +149,12 @@ final class ResourcesTests: XCTestCase { #endif let binPath = try AbsolutePath(validating: - await executeSwiftBuild(fixturePath, configuration: .Release, extraArgs: ["--show-bin-path"]).stdout + await executeSwiftBuild(fixturePath, configuration: .release, extraArgs: ["--show-bin-path"], buildSystem: self.buildSystemProvider).stdout .trimmingCharacters(in: .whitespacesAndNewlines) ) for execName in executables { - _ = try await executeSwiftBuild(fixturePath, configuration: .Release, extraArgs: ["--product", execName]) + _ = try await executeSwiftBuild(fixturePath, configuration: .release, extraArgs: ["--product", execName], buildSystem: self.buildSystemProvider) try await withTemporaryDirectory(prefix: execName) { tmpDirPath in defer { @@ -105,7 +184,9 @@ final class ResourcesTests: XCTestCase { try await fixture(name: "Resources/FoundationlessClient/UtilsWithFoundationPkg") { fixturePath in await XCTAssertBuilds( fixturePath, - Xswiftc: ["-warnings-as-errors"] + configurations: [self.buildConfig], + Xswiftc: ["-warnings-as-errors"], + buildSystem: self.buildSystemProvider ) } } @@ -123,8 +204,8 @@ final class ResourcesTests: XCTestCase { func testResourcesEmbeddedInCode() async throws { try await fixture(name: "Resources/EmbedInCodeSimple") { fixturePath in - let execPath = fixturePath.appending(components: ".build", "debug", "EmbedInCodeSimple") - try await executeSwiftBuild(fixturePath) + let execPath = fixturePath.appending(components: [".build"] + self.binPathSuffixes + ["EmbedInCodeSimple"]) + try await executeSwiftBuild(fixturePath, configuration: self.buildConfig, buildSystem: self.buildSystemProvider) let result = try await AsyncProcess.checkNonZeroExit(args: execPath.pathString) XCTAssertMatch(result, .contains("hello world")) let resourcePath = fixturePath.appending( @@ -135,7 +216,7 @@ final class ResourcesTests: XCTestCase { let content = "Hi there \(i)!" // Update the resource file. try localFileSystem.writeFileContents(resourcePath, string: content) - try await executeSwiftBuild(fixturePath) + try await executeSwiftBuild(fixturePath, configuration: self.buildConfig, buildSystem: self.buildSystemProvider) // Run the executable again. let result2 = try await AsyncProcess.checkNonZeroExit(args: execPath.pathString) XCTAssertMatch(result2, .contains("\(content)")) @@ -174,13 +255,13 @@ final class ResourcesTests: XCTestCase { try localFileSystem.createDirectory(resource.parentDirectory, recursive: true) try localFileSystem.writeFileContents(resource, string: "best") - let (_, stderr) = try await executeSwiftBuild(packageDir, env: ["SWIFT_DRIVER_SWIFTSCAN_LIB" : "/this/is/a/bad/path"]) + let (_, stderr) = try await executeSwiftBuild(packageDir, configuration: self.buildConfig, env: ["SWIFT_DRIVER_SWIFTSCAN_LIB" : "/this/is/a/bad/path"], buildSystem: self.buildSystemProvider) // Filter some unrelated output that could show up on stderr. let filteredStderr = stderr.components(separatedBy: "\n").filter { !$0.contains("[logging]") } .filter { !$0.contains("Unable to locate libSwiftScan") }.joined(separator: "\n") XCTAssertEqual(filteredStderr, "", "unexpectedly received error output: \(stderr)") - let builtProductsDir = packageDir.appending(components: [".build", "debug"]) + let builtProductsDir = packageDir.appending(components: [".build"] + self.binPathSuffixes) // On Apple platforms, it's going to be `.bundle` and elsewhere `.resources`. let potentialResourceBundleName = try XCTUnwrap(localFileSystem.getDirectoryContents(builtProductsDir).filter { $0.hasPrefix("MyPackage_exec.") }.first) let resourcePath = builtProductsDir.appending(components: [potentialResourceBundleName, "resources", "best.txt"]) diff --git a/Tests/FunctionalTests/VersionSpecificTests.swift b/Tests/FunctionalTests/VersionSpecificTests.swift index ba50d0a9871..3dc0c227ae1 100644 --- a/Tests/FunctionalTests/VersionSpecificTests.swift +++ b/Tests/FunctionalTests/VersionSpecificTests.swift @@ -14,8 +14,36 @@ import Basics import SourceControl import _InternalTestSupport import XCTest +import struct SPMBuildCore.BuildSystemProvider + +final class VersionSpecificNativeTests: VersionSpecificTestCase { + + override public var buildSystemProvider: BuildSystemProvider.Kind { + return .native + } + + override func testEndToEndResolution() async throws { + try await super.testEndToEndResolution() + } +} + +final class VersionSpecificSwiftBuildTests: VersionSpecificTestCase { + + override public var buildSystemProvider: BuildSystemProvider.Kind { + return .swiftbuild + } + + override func testEndToEndResolution() async throws { + throw XCTSkip("") + try await super.testEndToEndResolution() + } +} + +class VersionSpecificTestCase: BuildSystemProviderTestCase { + override func setUpWithError() throws { + try XCTSkipIf(type(of: self) == VersionSpecificTestCase.self, "Skipping this test since it will be run in subclasses that will provide different build systems to test.") + } -final class VersionSpecificTests: XCTestCase { /// Functional tests of end-to-end support for version specific dependency resolution. func testEndToEndResolution() async throws { try await testWithTemporaryDirectory{ path in @@ -90,7 +118,7 @@ final class VersionSpecificTests: XCTestCase { """ ) // This build should fail, because of the invalid package. - await XCTAssertBuildFails(primaryPath) + await XCTAssertBuildFails(primaryPath, buildSystem: self.buildSystemProvider) // Create a file which requires a version 1.1.0 resolution. try fs.writeFileContents( @@ -124,7 +152,7 @@ final class VersionSpecificTests: XCTestCase { // The build should work now. _ = try await SwiftPM.Package.execute(["reset"], packagePath: primaryPath) - await XCTAssertBuilds(primaryPath) + await XCTAssertBuilds(primaryPath, buildSystem: self.buildSystemProvider) } } } diff --git a/Tests/WorkspaceTests/InitTests.swift b/Tests/WorkspaceTests/InitTests.swift index 2e4c83a2271..028a9ca46ea 100644 --- a/Tests/WorkspaceTests/InitTests.swift +++ b/Tests/WorkspaceTests/InitTests.swift @@ -15,8 +15,120 @@ import _InternalTestSupport import PackageModel import Workspace import XCTest +import struct SPMBuildCore.BuildSystemProvider + +final class InitSwiftBuildDebugConfigurationTests: InitTestCase { + override public var buildSystemProvider: BuildSystemProvider.Kind { + return .swiftbuild + } + + override public var binPathSuffixes: [String] { + ["Products" , "Debug"] + } + + override public var buildConfig: BuildConfiguration { + .debug + } + + override func testInitPackageEmpty() throws { + try super.testInitPackageEmpty() + } +} + +final class InitSwiftBuildReleaseConfigurationTests: InitTestCase { + override public var buildSystemProvider: BuildSystemProvider.Kind { + return .swiftbuild + } + + override public var binPathSuffixes: [String] { + ["Products" , "Release"] + } + + override public var buildConfig: BuildConfiguration { + .release + } + + override func testInitPackageEmpty() throws { + try super.testInitPackageEmpty() + } + + override func testInitPackageExecutableCalledMain() async throws { + #if os(Linux) + try XCTSkipSwiftBuildTodo(because: "Test package fails to build with release configuration") + #else + try await super.testInitPackageExecutableCalledMain() + #endif + } + + override func testInitPackageExecutable() async throws { + #if os(Linux) + try XCTSkipSwiftBuildTodo(because: "Test package fails to build with release configuration") + #else + try await super.testInitPackageExecutable() + #endif + } + + override func testInitPackageLibraryWithXCTestOnly() async throws { + #if os(Linux) + try XCTSkipSwiftBuildTodo(because: "Test package fails to build with release configuration") + #else + try await super.testInitPackageLibraryWithXCTestOnly() + #endif + } + + override func testInitPackageNonc99Directory() async throws { + #if os(Linux) + try XCTSkipSwiftBuildTodo(because: "Test package fails to build with release configuration") + #else + try await super.testInitPackageNonc99Directory() + #endif + } -final class InitTests: XCTestCase { + +} + +final class InitDebugConfigNativeTests: InitTestCase { + override public var buildSystemProvider: BuildSystemProvider.Kind { + return .native + } + + override public var binPathSuffixes: [String] { + ["debug"] + } + + override public var buildConfig: BuildConfiguration { + .debug + } + + override func testInitPackageEmpty() throws { + try super.testInitPackageEmpty() + } + +} + +final class InitReleaseConfigNativeTests: InitTestCase { + override public var buildSystemProvider: BuildSystemProvider.Kind { + return .native + } + + override public var binPathSuffixes: [String] { + ["release"] + } + + override public var buildConfig: BuildConfiguration { + .release + } + + override func testInitPackageEmpty() throws { + try super.testInitPackageEmpty() + } + +} + +class InitTestCase: BuildConfigurationTestCase { + override func setUpWithError() throws { + try XCTSkipIf(type(of: self) == InitTestCase.self, "Skipping this test since it will be run in subclasses that will provide different build systems to test.") + } // MARK: TSCBasic package creation for each package type. @@ -55,6 +167,7 @@ final class InitTests: XCTestCase { } func testInitPackageExecutable() async throws { + try await testWithTemporaryDirectory { tmpPath in let fs = localFileSystem let path = tmpPath.appending("Foo") @@ -86,9 +199,9 @@ final class InitTests: XCTestCase { XCTAssertMatch(manifestContents, .prefix("// swift-tools-version:\(version < .v5_4 ? "" : " ")\(versionSpecifier)\n")) XCTAssertEqual(try fs.getDirectoryContents(path.appending("Sources").appending("Foo")), ["Foo.swift"]) - await XCTAssertBuilds(path) + await XCTAssertBuilds(path, configurations: [self.buildConfig], buildSystem: self.buildSystemProvider) let triple = try UserToolchain.default.targetTriple - let binPath = path.appending(components: ".build", triple.platformBuildPathComponent, "debug") + let binPath = path.appending(components: [".build", triple.platformBuildPathComponent] + self.binPathSuffixes) #if os(Windows) XCTAssertFileExists(binPath.appending("Foo.exe")) #else @@ -115,7 +228,7 @@ final class InitTests: XCTestCase { try initPackage.writePackageStructure() XCTAssertEqual(try fs.getDirectoryContents(path.appending("Sources").appending("main")), ["MainEntrypoint.swift"]) - await XCTAssertBuilds(path) + await XCTAssertBuilds(path, configurations: [self.buildConfig], buildSystem: self.buildSystemProvider) } } @@ -165,9 +278,9 @@ final class InitTests: XCTestCase { XCTAssertMatch(testFileContents, .contains("func testExample() throws")) // Try building it - await XCTAssertBuilds(path) + await XCTAssertBuilds(path, configurations: [self.buildConfig], buildSystem: self.buildSystemProvider) let triple = try UserToolchain.default.targetTriple - XCTAssertFileExists(path.appending(components: ".build", triple.platformBuildPathComponent, "debug", "Modules", "Foo.swiftmodule")) + XCTAssertFileExists(path.appending(components: [".build", triple.platformBuildPathComponent] + self.binPathSuffixes + ["Modules", "Foo.swiftmodule"])) } } @@ -201,9 +314,9 @@ final class InitTests: XCTestCase { #if canImport(TestingDisabled) // Try building it - await XCTAssertBuilds(path) + await XCTAssertBuilds(path, configurations: [self.buildConfig], buildSystem: self.buildSystemProvider) let triple = try UserToolchain.default.targetTriple - XCTAssertFileExists(path.appending(components: ".build", triple.platformBuildPathComponent, "debug", "Modules", "Foo.swiftmodule")) + XCTAssertFileExists(path.appending(components: [".build", triple.platformBuildPathComponent] + self.binPathSuffixes + ["Modules", "Foo.swiftmodule"])) #endif } } @@ -238,9 +351,9 @@ final class InitTests: XCTestCase { #if canImport(TestingDisabled) // Try building it - await XCTAssertBuilds(path) + await XCTAssertBuilds(path, configurations: [self.buildConfig], buildSystem: self.buildSystemProvider) let triple = try UserToolchain.default.targetTriple - XCTAssertFileExists(path.appending(components: ".build", triple.platformBuildPathComponent, "debug", "Modules", "Foo.swiftmodule")) + XCTAssertFileExists(path.appending(components: [".build", triple.platformBuildPathComponent] + self.binPathSuffixes + ["Modules", "Foo.swiftmodule"])) #endif } } @@ -272,9 +385,9 @@ final class InitTests: XCTestCase { #if canImport(TestingDisabled) // Try building it - await XCTAssertBuilds(path) + await XCTAssertBuilds(path, configurations: [self.buildConfig], buildSystem: self.buildSystemProvider) let triple = try UserToolchain.default.targetTriple - XCTAssertFileExists(path.appending(components: ".build", triple.platformBuildPathComponent, "debug", "Modules", "Foo.swiftmodule")) + XCTAssertFileExists(path.appending(components: [".build", triple.platformBuildPathComponent] + self.binPathSuffixes + ["Modules", "Foo.swiftmodule"])) #endif } } @@ -371,9 +484,9 @@ final class InitTests: XCTestCase { try initPackage.writePackageStructure() // Try building it. - await XCTAssertBuilds(packageRoot) + await XCTAssertBuilds(packageRoot, configurations: [self.buildConfig], buildSystem: self.buildSystemProvider) let triple = try UserToolchain.default.targetTriple - XCTAssertFileExists(packageRoot.appending(components: ".build", triple.platformBuildPathComponent, "debug", "Modules", "some_package.swiftmodule")) + XCTAssertFileExists(packageRoot.appending(components: [".build", triple.platformBuildPathComponent] + self.binPathSuffixes + ["Modules", "some_package.swiftmodule"])) } } @@ -394,7 +507,7 @@ final class InitTests: XCTestCase { ) try initPackage.writePackageStructure() - await XCTAssertBuilds(packageRoot) + await XCTAssertBuilds(packageRoot, configurations: [self.buildConfig], buildSystem: self.buildSystemProvider) } }