diff --git a/Sources/_InternalTestSupport/SwiftTesting+TraitConditional.swift b/Sources/_InternalTestSupport/SwiftTesting+TraitConditional.swift index b05539405b4..41411935748 100644 --- a/Sources/_InternalTestSupport/SwiftTesting+TraitConditional.swift +++ b/Sources/_InternalTestSupport/SwiftTesting+TraitConditional.swift @@ -11,6 +11,7 @@ import class Foundation.FileManager import class Foundation.ProcessInfo +import class PackageModel.UserToolchain import Basics import Testing @@ -29,6 +30,13 @@ extension Trait where Self == Testing.ConditionTrait { } } + /// Enabled only if toolchain support swift concurrency + public static var requiresSwiftConcurrencySupport: Self { + enabled("skipping because test environment doesn't support concurrency") { + (try? UserToolchain.default)!.supportsSwiftConcurrency() + } + } + /// Skip test unconditionally public static func skip(_ comment: Comment? = nil) -> Self { disabled(comment ?? "Unconditional skip, a comment should be added for the reason") { true } diff --git a/Sources/_InternalTestSupport/XCTAssertHelpers.swift b/Sources/_InternalTestSupport/XCTAssertHelpers.swift index d8dd24534f7..58a47f7fc43 100644 --- a/Sources/_InternalTestSupport/XCTAssertHelpers.swift +++ b/Sources/_InternalTestSupport/XCTAssertHelpers.swift @@ -154,7 +154,7 @@ public func XCTAssertBuilds( env: Environment? = nil, file: StaticString = #file, line: UInt = #line, - buildSystem: BuildSystemProvider.Kind = .native + buildSystem: BuildSystemProvider.Kind, ) async { for conf in configurations { await XCTAssertAsyncNoThrow( @@ -184,7 +184,7 @@ public func XCTAssertSwiftTest( env: Environment? = nil, file: StaticString = #file, line: UInt = #line, - buildSystem: BuildSystemProvider.Kind = .native + buildSystem: BuildSystemProvider.Kind, ) async { await XCTAssertAsyncNoThrow( try await executeSwiftTest( @@ -211,7 +211,7 @@ public func XCTAssertBuildFails( env: Environment? = nil, file: StaticString = #file, line: UInt = #line, - buildSystem: BuildSystemProvider.Kind = .native + buildSystem: BuildSystemProvider.Kind, ) async -> CommandExecutionError? { var failure: CommandExecutionError? = nil await XCTAssertThrowsCommandExecutionError( @@ -337,6 +337,6 @@ public func XCTExhibitsGitHubIssue(_ number: Int) throws { try XCTSkipIf( ProcessInfo.processInfo.environment[envVar] != nil, - "https://github.com/swiftlang/swift-package-manager/issues/\(number): \(envVar)environment variable is set" + "https://github.com/swiftlang/swift-package-manager/issues/\(number): \(envVar) environment variable is set" ) } diff --git a/Sources/_InternalTestSupport/misc.swift b/Sources/_InternalTestSupport/misc.swift index f64f1cdb113..4a069fdd5c1 100644 --- a/Sources/_InternalTestSupport/misc.swift +++ b/Sources/_InternalTestSupport/misc.swift @@ -395,7 +395,7 @@ public func executeSwiftBuild( Xld: [String] = [], Xswiftc: [String] = [], env: Environment? = nil, - buildSystem: BuildSystemProvider.Kind = .native, + buildSystem: BuildSystemProvider.Kind, throwIfCommandFails: Bool = true, ) async throws -> (stdout: String, stderr: String) { let args = swiftArgs( @@ -419,7 +419,7 @@ public func executeSwiftRun( Xld: [String] = [], Xswiftc: [String] = [], env: Environment? = nil, - buildSystem: BuildSystemProvider.Kind + buildSystem: BuildSystemProvider.Kind, ) async throws -> (stdout: String, stderr: String) { var args = swiftArgs( configuration: configuration, @@ -444,7 +444,7 @@ public func executeSwiftPackage( Xld: [String] = [], Xswiftc: [String] = [], env: Environment? = nil, - buildSystem: BuildSystemProvider.Kind = .native + buildSystem: BuildSystemProvider.Kind, ) async throws -> (stdout: String, stderr: String) { let args = swiftArgs( configuration: configuration, @@ -466,7 +466,7 @@ public func executeSwiftPackageRegistry( Xld: [String] = [], Xswiftc: [String] = [], env: Environment? = nil, - buildSystem: BuildSystemProvider.Kind = .native + buildSystem: BuildSystemProvider.Kind, ) async throws -> (stdout: String, stderr: String) { let args = swiftArgs( configuration: configuration, @@ -489,7 +489,7 @@ public func executeSwiftTest( Xswiftc: [String] = [], env: Environment? = nil, throwIfCommandFails: Bool = false, - buildSystem: BuildSystemProvider.Kind = .native + buildSystem: BuildSystemProvider.Kind, ) async throws -> (stdout: String, stderr: String) { let args = swiftArgs( configuration: configuration, diff --git a/Tests/BuildTests/BuildSystemDelegateTests.swift b/Tests/BuildTests/BuildSystemDelegateTests.swift index 4386199c723..364df5cf7c7 100644 --- a/Tests/BuildTests/BuildSystemDelegateTests.swift +++ b/Tests/BuildTests/BuildSystemDelegateTests.swift @@ -24,7 +24,7 @@ final class BuildSystemDelegateTests: XCTestCase { // These linker diagnostics are only produced on macOS. try XCTSkipIf(true, "test is only supported on macOS") #endif - let (fullLog, _) = try await executeSwiftBuild(fixturePath) + let (fullLog, _) = try await executeSwiftBuild(fixturePath, buildSystem: .native) XCTAssertTrue(fullLog.contains("ld: warning: search path 'foobar' not found"), "log didn't contain expected linker diagnostics") } } @@ -40,11 +40,11 @@ final class BuildSystemDelegateTests: XCTestCase { let executableExt = "" #endif try await fixtureXCTest(name: "Miscellaneous/TestableExe") { fixturePath in - _ = try await executeSwiftBuild(fixturePath) + _ = try await executeSwiftBuild(fixturePath, buildSystem: .native) let execPath = fixturePath.appending(components: ".build", "debug", "TestableExe1\(executableExt)") XCTAssertTrue(localFileSystem.exists(execPath), "executable not found at '\(execPath)'") try localFileSystem.removeFileTree(execPath) - let (fullLog, _) = try await executeSwiftBuild(fixturePath) + let (fullLog, _) = try await executeSwiftBuild(fixturePath, buildSystem: .native) XCTAssertFalse(fullLog.contains("replacing existing signature"), "log contained non-fatal codesigning messages") } } diff --git a/Tests/BuildTests/IncrementalBuildTests.swift b/Tests/BuildTests/IncrementalBuildTests.swift index 8fc45197abe..0e495269ff2 100644 --- a/Tests/BuildTests/IncrementalBuildTests.swift +++ b/Tests/BuildTests/IncrementalBuildTests.swift @@ -42,7 +42,7 @@ final class IncrementalBuildTests: XCTestCase { try XCTSkipIf(!UserToolchain.default.supportsSDKDependentTests(), "skipping because test environment doesn't support this test") try await fixtureXCTest(name: "CFamilyTargets/CLibrarySources") { fixturePath in // Build it once and capture the log (this will be a full build). - let (fullLog, _) = try await executeSwiftBuild(fixturePath) + let (fullLog, _) = try await executeSwiftBuild(fixturePath, buildSystem: .native) // Check various things that we expect to see in the full build log. // FIXME: This is specific to the format of the log output, which @@ -64,7 +64,7 @@ final class IncrementalBuildTests: XCTestCase { let llbuildContents1: String = try localFileSystem.readFileContents(llbuildManifest) // Now build again. This should be an incremental build. - let (log2, _) = try await executeSwiftBuild(fixturePath) + let (log2, _) = try await executeSwiftBuild(fixturePath, buildSystem: .native) XCTAssertMatch(log2, .contains("Compiling CLibrarySources Foo.c")) // Read the second llbuild manifest. @@ -72,7 +72,7 @@ final class IncrementalBuildTests: XCTestCase { // Now build again without changing anything. This should be a null // build. - let (log3, _) = try await executeSwiftBuild(fixturePath) + let (log3, _) = try await executeSwiftBuild(fixturePath, buildSystem: .native) XCTAssertNoMatch(log3, .contains("Compiling CLibrarySources Foo.c")) // Read the third llbuild manifest. @@ -91,7 +91,7 @@ final class IncrementalBuildTests: XCTestCase { ) // Now build again. This should be an incremental build. - let (log4, _) = try await executeSwiftBuild(fixturePath) + let (log4, _) = try await executeSwiftBuild(fixturePath, buildSystem: .native) XCTAssertMatch(log4, .contains("Compiling CLibrarySources Foo.c")) } } @@ -101,7 +101,7 @@ final class IncrementalBuildTests: XCTestCase { try await fixtureXCTest(name: "ValidLayouts/SingleModule/Library") { fixturePath in @discardableResult func build() async throws -> String { - return try await executeSwiftBuild(fixturePath).stdout + return try await executeSwiftBuild(fixturePath, buildSystem: .native).stdout } // Perform a full build. @@ -135,7 +135,11 @@ final class IncrementalBuildTests: XCTestCase { try await fixtureXCTest(name: "ValidLayouts/SingleModule/Library") { fixturePath in @discardableResult func build() async throws -> String { - return try await executeSwiftBuild(fixturePath, extraArgs: ["--disable-build-manifest-caching"]).stdout + return try await executeSwiftBuild( + fixturePath, + extraArgs: ["--disable-build-manifest-caching"], + buildSystem: .native, + ).stdout } // Perform a full build. @@ -166,7 +170,11 @@ final class IncrementalBuildTests: XCTestCase { let newSdkPathStr = "/tmp/../\(sdkPathStr)" // Perform a full build again because SDK changed. - let log1 = try await executeSwiftBuild(fixturePath, env: ["SDKROOT": newSdkPathStr]).stdout + let log1 = try await executeSwiftBuild( + fixturePath, + env: ["SDKROOT": newSdkPathStr], + buildSystem: .native, + ).stdout XCTAssertMatch(log1, .contains("Compiling Library")) } #endif diff --git a/Tests/BuildTests/PluginsBuildPlanTests.swift b/Tests/BuildTests/PluginsBuildPlanTests.swift index 7737b869969..3a3630de7bf 100644 --- a/Tests/BuildTests/PluginsBuildPlanTests.swift +++ b/Tests/BuildTests/PluginsBuildPlanTests.swift @@ -21,7 +21,7 @@ final class PluginsBuildPlanTests: XCTestCase { try XCTSkipOnWindows(because: "Fails to build the project to due to incorrect Path handling. Possibly related to https://github.com/swiftlang/swift-package-manager/issues/8511") try await fixtureXCTest(name: "Miscellaneous/Plugins/MySourceGenPlugin") { fixturePath in - let (stdout, _) = try await executeSwiftBuild(fixturePath) + let (stdout, _) = try await executeSwiftBuild(fixturePath, buildSystem: .native) XCTAssertMatch(stdout, .contains("Build complete!")) // FIXME: This is temporary until build of plugin tools is extracted into its own command. XCTAssertTrue(localFileSystem.exists(fixturePath.appending(RelativePath(".build/plugin-tools.db")))) @@ -49,7 +49,11 @@ final class PluginsBuildPlanTests: XCTestCase { // By default, plugin dependencies are built for the host platform try await fixtureXCTest(name: "Miscellaneous/Plugins/CommandPluginTestStub") { fixturePath in - let (stdout, stderr) = try await executeSwiftPackage(fixturePath, extraArgs: ["-v", "build-plugin-dependency"]) + let (stdout, stderr) = try await executeSwiftPackage( + fixturePath, + extraArgs: ["-v", "build-plugin-dependency"], + buildSystem: .native, + ) XCTAssertMatch(stdout, .contains("Hello from dependencies-stub")) XCTAssertMatch(stderr, .contains("Build of product 'plugintool' complete!")) XCTAssertTrue( @@ -66,7 +70,11 @@ final class PluginsBuildPlanTests: XCTestCase { // When cross compiling the final product, plugin dependencies should still be built for the host try await fixtureXCTest(name: "Miscellaneous/Plugins/CommandPluginTestStub") { fixturePath in - let (stdout, stderr) = try await executeSwiftPackage(fixturePath, extraArgs: ["--triple", targetTriple, "-v", "build-plugin-dependency"]) + let (stdout, stderr) = try await executeSwiftPackage( + fixturePath, + extraArgs: ["--triple", targetTriple, "-v", "build-plugin-dependency"], + buildSystem: .native, + ) XCTAssertMatch(stdout, .contains("Hello from dependencies-stub")) XCTAssertMatch(stderr, .contains("Build of product 'plugintool' complete!")) XCTAssertTrue( diff --git a/Tests/CommandsTests/PackageCommandTests.swift b/Tests/CommandsTests/PackageCommandTests.swift index 9b467de7372..70c5b6767e8 100644 --- a/Tests/CommandsTests/PackageCommandTests.swift +++ b/Tests/CommandsTests/PackageCommandTests.swift @@ -92,27 +92,27 @@ class PackageCommandTestCase: CommandsBuildProviderTestCase { let stdout = try await SwiftPM.Package.execute(["--version"]).stdout XCTAssertMatch(stdout, .regex(#"Swift Package Manager -( \w+ )?\d+.\d+.\d+(-\w+)?"#)) } - + func testCompletionTool() async throws { let stdout = try await execute(["completion-tool", "--help"]).stdout XCTAssertMatch(stdout, .contains("OVERVIEW: Command to generate shell completions.")) } - func testInitOverview() async throws { - let stdout = try await execute(["init", "--help"]).stdout - XCTAssertMatch(stdout, .contains("OVERVIEW: Initialize a new package")) - } - - func testInitUsage() async throws { - let stdout = try await execute(["init", "--help"]).stdout - XCTAssertMatch(stdout, .contains("USAGE: swift package init [--type ] ")) - XCTAssertMatch(stdout, .contains(" [--name ]")) - } - - func testInitOptionsHelp() async throws { - let stdout = try await execute(["init", "--help"]).stdout - XCTAssertMatch(stdout, .contains("OPTIONS:")) - } + func testInitOverview() async throws { + let stdout = try await execute(["init", "--help"]).stdout + XCTAssertMatch(stdout, .contains("OVERVIEW: Initialize a new package")) + } + + func testInitUsage() async throws { + let stdout = try await execute(["init", "--help"]).stdout + XCTAssertMatch(stdout, .contains("USAGE: swift package init [--type ] ")) + XCTAssertMatch(stdout, .contains(" [--name ]")) + } + + func testInitOptionsHelp() async throws { + let stdout = try await execute(["init", "--help"]).stdout + XCTAssertMatch(stdout, .contains("OPTIONS:")) + } func testPlugin() async throws { await XCTAssertThrowsCommandExecutionError(try await execute(["plugin"])) { error in @@ -1421,7 +1421,7 @@ class PackageCommandTestCase: CommandsBuildProviderTestCase { try await fixtureXCTest(name: "Miscellaneous/PackageEdit") { fixturePath in let fooPath = fixturePath.appending("foo") func build() async throws -> (stdout: String, stderr: String) { - return try await executeSwiftBuild(fooPath) + return try await executeSwiftBuild(fooPath, buildSystem: self.buildSystemProvider) } // Put bar and baz in edit mode. @@ -1429,7 +1429,7 @@ class PackageCommandTestCase: CommandsBuildProviderTestCase { _ = try await self.execute(["edit", "baz", "--branch", "bugfix"], packagePath: fooPath) // Path to the executable. - let exec = [fooPath.appending(components: ".build", try UserToolchain.default.targetTriple.platformBuildPathComponent, "debug", "foo").pathString] + let exec = [fooPath.appending(components: [".build", try UserToolchain.default.targetTriple.platformBuildPathComponent] + self.buildSystemProvider.binPathSuffixes(for: .debug) + ["foo"]).pathString] // We should see it now in packages directory. let editsPath = fooPath.appending(components: "Packages", "bar") @@ -1501,15 +1501,15 @@ class PackageCommandTestCase: CommandsBuildProviderTestCase { let packageRoot = fixturePath.appending("Bar") // Build it. - await XCTAssertBuilds(packageRoot) + await XCTAssertBuilds(packageRoot, buildSystem: self.buildSystemProvider) let buildPath = packageRoot.appending(".build") - let binFile = buildPath.appending(components: try UserToolchain.default.targetTriple.platformBuildPathComponent, "debug", executableName("Bar")) - XCTAssertFileExists(binFile) + let debugBinFile = buildPath.appending(components: [try UserToolchain.default.targetTriple.platformBuildPathComponent] + self.buildSystemProvider.binPathSuffixes(for: .debug) + [executableName("Bar")]) + XCTAssertFileExists(debugBinFile) XCTAssert(localFileSystem.isDirectory(buildPath)) // Clean, and check for removal of the build directory but not Packages. _ = try await execute(["clean"], packagePath: packageRoot) - XCTAssertNoSuchPath(binFile) + XCTAssertNoSuchPath(debugBinFile) // Clean again to ensure we get no error. _ = try await execute(["clean"], packagePath: packageRoot) } @@ -1520,9 +1520,9 @@ class PackageCommandTestCase: CommandsBuildProviderTestCase { let packageRoot = fixturePath.appending("Bar") // Build it. - await XCTAssertBuilds(packageRoot) + await XCTAssertBuilds(packageRoot, buildSystem: self.buildSystemProvider) let buildPath = packageRoot.appending(".build") - let binFile = buildPath.appending(components: try UserToolchain.default.targetTriple.platformBuildPathComponent, "debug", executableName("Bar")) + let binFile = buildPath.appending(components: [try UserToolchain.default.targetTriple.platformBuildPathComponent] + self.buildSystemProvider.binPathSuffixes(for: .debug) + [executableName("Bar")]) XCTAssertFileExists(binFile) XCTAssert(localFileSystem.isDirectory(buildPath)) // Clean, and check for removal of the build directory but not Packages. @@ -1600,14 +1600,22 @@ class PackageCommandTestCase: CommandsBuildProviderTestCase { try await fixtureXCTest(name: "Miscellaneous/PackageEdit") { fixturePath in let fooPath = fixturePath.appending("foo") let exec = [fooPath.appending( - components: ".build", - try UserToolchain.default.targetTriple.platformBuildPathComponent, - "debug", - "foo" + components: + [ + ".build", + try UserToolchain.default.targetTriple.platformBuildPathComponent, + ] + + self.buildSystemProvider.binPathSuffixes(for: .debug) + + [ + "foo", + ] ).pathString] // Build and check. - _ = try await executeSwiftBuild(fooPath) + _ = try await executeSwiftBuild( + fooPath, + buildSystem: self.buildSystemProvider, + ) try await XCTAssertAsyncEqual(try await AsyncProcess.checkNonZeroExit(arguments: exec).spm_chomp(), "\(5)") // Get path to `bar` checkout. @@ -1718,7 +1726,7 @@ class PackageCommandTestCase: CommandsBuildProviderTestCase { } func testOnlyUseVersionsFromResolvedFileFetchesWithExistingState() async throws { - try XCTSkipOnWindows(because: "error: Package.resolved file is corrupted or malformed, needs investigation") + try XCTSkipOnWindows(because: "error: Package.resolved file is corrupted or malformed, needs investigation") func writeResolvedFile(packageDir: AbsolutePath, repositoryURL: String, revision: String, version: String) throws { try localFileSystem.writeFileContents(packageDir.appending("Package.resolved"), string: @@ -2433,7 +2441,12 @@ class PackageCommandTestCase: CommandsBuildProviderTestCase { // Create and return a build command that uses all the `.foo` files in the target as inputs, so they get counted as having been handled. let fooFiles = target.sourceModule?.sourceFiles.compactMap{ $0.path.extension == "foo" ? $0.path : nil } ?? [] - return [ .buildCommand(displayName: "A command", executable: Path("/bin/echo"), arguments: fooFiles, inputFiles: fooFiles) ] + #if os(Windows) + let exec = "echo" + #else + let exec = "/bin/echo" + #endif + return [ .buildCommand(displayName: "A command", executable: Path(exec), arguments: fooFiles, inputFiles: fooFiles) ] } } @@ -2445,14 +2458,17 @@ class PackageCommandTestCase: CommandsBuildProviderTestCase { let args = staticStdlib ? ["--static-swift-stdlib"] : [] let (stdout, stderr) = try await executeSwiftBuild( packageDir, - extraArgs: args + extraArgs: args, + buildSystem: self.buildSystemProvider, ) XCTAssert(stdout.contains("Build complete!")) // We expect a warning about `library.bar` but not about `library.foo`. - XCTAssertMatch(stderr, .contains("found 1 file(s) which are unhandled")) XCTAssertNoMatch(stderr, .contains(RelativePath("Sources/MyLibrary/library.foo").pathString)) - XCTAssertMatch(stderr, .contains(RelativePath("Sources/MyLibrary/library.bar").pathString)) + if self.buildSystemProvider == .native { + XCTAssertMatch(stderr, .contains("found 1 file(s) which are unhandled")) + XCTAssertMatch(stderr, .contains(RelativePath("Sources/MyLibrary/library.bar").pathString)) + } } } @@ -2512,13 +2528,21 @@ class PackageCommandTestCase: CommandsBuildProviderTestCase { ) // Invoke it, and check the results. - await XCTAssertAsyncThrowsError(try await executeSwiftBuild(packageDir, extraArgs: ["-v"])) { error in + await XCTAssertAsyncThrowsError( + try await executeSwiftBuild( + packageDir, + extraArgs: ["-v"], + buildSystem: self.buildSystemProvider, + ) + ) { error in guard case SwiftPMError.executionFailure(_, _, let stderr) = error else { return XCTFail("invalid error \(error)") } XCTAssertMatch(stderr, .contains("This is text from the plugin")) XCTAssertMatch(stderr, .contains("error: This is an error from the plugin")) - XCTAssertMatch(stderr, .contains("build planning stopped due to build-tool plugin failures")) + if self.buildSystemProvider == .native { + XCTAssertMatch(stderr, .contains("build planning stopped due to build-tool plugin failures")) + } } } } @@ -2895,17 +2919,17 @@ class PackageCommandTestCase: CommandsBuildProviderTestCase { } try await runPlugin(flags: [], diagnostics: ["print", "progress", "remark"]) { stdout, stderr in - XCTAssertMatch(stdout, isOnlyPrint) + XCTAssertMatch(stdout, isOnlyPrint) XCTAssertMatch(stderr, containsProgress) } try await runPlugin(flags: [], diagnostics: ["print", "progress", "remark", "warning"]) { stdout, stderr in - XCTAssertMatch(stdout, isOnlyPrint) - XCTAssertMatch(stderr, containsProgress) + XCTAssertMatch(stdout, isOnlyPrint) + XCTAssertMatch(stderr, containsProgress) XCTAssertMatch(stderr, containsWarning) } - try await runPluginWithError(flags: [], diagnostics: ["print", "progress", "remark", "warning", "error"]) { stdout, stderr in + try await runPluginWithError(flags: [], diagnostics: ["print", "progress", "remark", "warning", "error"]) { stdout, stderr in XCTAssertMatch(stdout, isOnlyPrint) XCTAssertMatch(stderr, containsProgress) XCTAssertMatch(stderr, containsWarning) @@ -2924,24 +2948,24 @@ class PackageCommandTestCase: CommandsBuildProviderTestCase { } try await runPlugin(flags: ["-q"], diagnostics: ["print", "progress"]) { stdout, stderr in - XCTAssertMatch(stdout, isOnlyPrint) + XCTAssertMatch(stdout, isOnlyPrint) XCTAssertMatch(stderr, containsProgress) } try await runPlugin(flags: ["-q"], diagnostics: ["print", "progress", "remark"]) { stdout, stderr in - XCTAssertMatch(stdout, isOnlyPrint) + XCTAssertMatch(stdout, isOnlyPrint) XCTAssertMatch(stderr, containsProgress) } try await runPlugin(flags: ["-q"], diagnostics: ["print", "progress", "remark", "warning"]) { stdout, stderr in - XCTAssertMatch(stdout, isOnlyPrint) + XCTAssertMatch(stdout, isOnlyPrint) XCTAssertMatch(stderr, containsProgress) } try await runPluginWithError(flags: ["-q"], diagnostics: ["print", "progress", "remark", "warning", "error"]) { stdout, stderr in - XCTAssertMatch(stdout, isOnlyPrint) - XCTAssertMatch(stderr, containsProgress) - XCTAssertNoMatch(stderr, containsRemark) + XCTAssertMatch(stdout, isOnlyPrint) + XCTAssertMatch(stderr, containsProgress) + XCTAssertNoMatch(stderr, containsRemark) XCTAssertNoMatch(stderr, containsWarning) XCTAssertMatch(stderr, containsError) } @@ -2957,27 +2981,27 @@ class PackageCommandTestCase: CommandsBuildProviderTestCase { } try await runPlugin(flags: ["-v"], diagnostics: ["print", "progress"]) { stdout, stderr in - XCTAssertMatch(stdout, isOnlyPrint) - XCTAssertMatch(stderr, containsProgress) + XCTAssertMatch(stdout, isOnlyPrint) + XCTAssertMatch(stderr, containsProgress) } try await runPlugin(flags: ["-v"], diagnostics: ["print", "progress", "remark"]) { stdout, stderr in - XCTAssertMatch(stdout, isOnlyPrint) - XCTAssertMatch(stderr, containsProgress) + XCTAssertMatch(stdout, isOnlyPrint) + XCTAssertMatch(stderr, containsProgress) XCTAssertMatch(stderr, containsRemark) } try await runPlugin(flags: ["-v"], diagnostics: ["print", "progress", "remark", "warning"]) { stdout, stderr in - XCTAssertMatch(stdout, isOnlyPrint) - XCTAssertMatch(stderr, containsProgress) + XCTAssertMatch(stdout, isOnlyPrint) + XCTAssertMatch(stderr, containsProgress) XCTAssertMatch(stderr, containsRemark) XCTAssertMatch(stderr, containsWarning) } try await runPluginWithError(flags: ["-v"], diagnostics: ["print", "progress", "remark", "warning", "error"]) { stdout, stderr in - XCTAssertMatch(stdout, isOnlyPrint) - XCTAssertMatch(stderr, containsProgress) - XCTAssertMatch(stderr, containsRemark) + XCTAssertMatch(stdout, isOnlyPrint) + XCTAssertMatch(stderr, containsProgress) + XCTAssertMatch(stderr, containsRemark) XCTAssertMatch(stderr, containsWarning) XCTAssertMatch(stderr, containsError) } @@ -2998,8 +3022,9 @@ class PackageCommandTestCase: CommandsBuildProviderTestCase { let osSuffix = "" #endif - let debugTarget = self.buildSystemProvider == .native ? [".build", "debug", executableName("placeholder")] : [".build", try UserToolchain.default.targetTriple.platformBuildPathComponent, "Products", "Debug\(osSuffix)", "placeholder"] - let releaseTarget = self.buildSystemProvider == .native ? [".build", "release", executableName("placeholder")] : [".build", try UserToolchain.default.targetTriple.platformBuildPathComponent, "Products", "Release\(osSuffix)", "placeholder"] + let tripleString = try UserToolchain.default.targetTriple.platformBuildPathComponent + let debugTarget = [".build", tripleString ] + self.buildSystemProvider.binPathSuffixes(for: .debug) + [executableName("placeholder")] + let releaseTarget = [".build", tripleString ] + self.buildSystemProvider.binPathSuffixes(for: .release) + [executableName("placeholder")] func AssertIsExecutableFile(_ fixturePath: AbsolutePath, file: StaticString = #filePath, line: UInt = #line) { XCTAssert( @@ -3879,7 +3904,7 @@ class PackageCommandTestCase: CommandsBuildProviderTestCase { } func testPluginAPIs() async throws { - try XCTSkipOnWindows(because: "https://github.com/swiftlang/swift-package-manager/issues/8554, $0.path.lastComponent in test code returns fullpaths on Windows") + try XCTSkipOnWindows(because: "https://github.com/swiftlang/swift-package-manager/issues/8554, $0.path.lastComponent in test code returns fullpaths on Windows") // 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") @@ -4175,9 +4200,14 @@ class PackageCommandTestCase: CommandsBuildProviderTestCase { // Check that building without options compiles both plugins and that the build proceeds. do { - let (stdout, _) = try await executeSwiftBuild(packageDir) - XCTAssertMatch(stdout, .contains("Compiling plugin MyBuildToolPlugin")) - XCTAssertMatch(stdout, .contains("Compiling plugin MyCommandPlugin")) + let (stdout, _) = try await executeSwiftBuild( + packageDir, + buildSystem: self.buildSystemProvider, + ) + if (self.buildSystemProvider == .native) { + XCTAssertMatch(stdout, .contains("Compiling plugin MyBuildToolPlugin")) + XCTAssertMatch(stdout, .contains("Compiling plugin MyCommandPlugin")) + } XCTAssertMatch(stdout, .contains("Building for debugging...")) } @@ -4185,14 +4215,91 @@ class PackageCommandTestCase: CommandsBuildProviderTestCase { do { let (stdout, _) = try await executeSwiftBuild( packageDir, - extraArgs: ["--target", "MyCommandPlugin"] + extraArgs: ["--target", "MyCommandPlugin"], + buildSystem: self.buildSystemProvider, ) - XCTAssertNoMatch(stdout, .contains("Compiling plugin MyBuildToolPlugin")) - XCTAssertMatch(stdout, .contains("Compiling plugin MyCommandPlugin")) - XCTAssertNoMatch(stdout, .contains("Building for debugging...")) + XCTAssertFalse(stdout.contains("Compiling plugin MyBuildToolPlugin"), "stdout: '\(stdout)'") + XCTAssertTrue(stdout.contains("Compiling plugin MyCommandPlugin"), "stdout: '\(stdout)'") + XCTAssertFalse(stdout.contains("Building for debugging..."), "stdout: '\(stdout)'") } + } + } + func testCommandPluginCompilationError() async throws { + // 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 testWithTemporaryDirectory { tmpPath in + // Create a sample package with a couple of plugins a other targets and products. + let packageDir = tmpPath.appending(components: "MyPackage") + try localFileSystem.createDirectory(packageDir, recursive: true) + try localFileSystem.writeFileContents(packageDir.appending(components: "Package.swift"), string: """ + // swift-tools-version: 5.6 + import PackageDescription + let package = Package( + name: "MyPackage", + products: [ + .library( + name: "MyLibrary", + targets: ["MyLibrary"] + ), + .executable( + name: "MyExecutable", + targets: ["MyExecutable"] + ), + ], + targets: [ + .target( + name: "MyLibrary" + ), + .executableTarget( + name: "MyExecutable", + dependencies: ["MyLibrary"] + ), + .plugin( + name: "MyBuildToolPlugin", + capability: .buildTool() + ), + .plugin( + name: "MyCommandPlugin", + capability: .command( + intent: .custom(verb: "my-build-tester", description: "Help description") + ) + ), + ] + ) + """ + ) + let myLibraryTargetDir = packageDir.appending(components: "Sources", "MyLibrary") + try localFileSystem.createDirectory(myLibraryTargetDir, recursive: true) + try localFileSystem.writeFileContents(myLibraryTargetDir.appending("library.swift"), string: """ + public func GetGreeting() -> String { return "Hello" } + """ + ) + let myExecutableTargetDir = packageDir.appending(components: "Sources", "MyExecutable") + try localFileSystem.createDirectory(myExecutableTargetDir, recursive: true) + try localFileSystem.writeFileContents(myExecutableTargetDir.appending("main.swift"), string: """ + import MyLibrary + print("\\(GetGreeting()), World!") + """ + ) + let myBuildToolPluginTargetDir = packageDir.appending(components: "Plugins", "MyBuildToolPlugin") + try localFileSystem.createDirectory(myBuildToolPluginTargetDir, recursive: true) + try localFileSystem.writeFileContents(myBuildToolPluginTargetDir.appending("plugin.swift"), string: """ + import PackagePlugin + @main struct MyBuildToolPlugin: BuildToolPlugin { + func createBuildCommands( + context: PluginContext, + target: Target + ) throws -> [Command] { + return [] + } + } + """ + ) // Deliberately break the command plugin. + let myCommandPluginTargetDir = packageDir.appending(components: "Plugins", "MyCommandPlugin") + try localFileSystem.createDirectory(myCommandPluginTargetDir, recursive: true) try localFileSystem.writeFileContents(myCommandPluginTargetDir.appending("plugin.swift"), string: """ import PackagePlugin @main struct MyCommandPlugin: CommandPlugin { @@ -4209,14 +4316,17 @@ class PackageCommandTestCase: CommandsBuildProviderTestCase { // Check that building stops after compiling the plugin and doesn't proceed. // Run this test a number of times to try to catch any race conditions. for _ in 1...5 { - await XCTAssertAsyncThrowsError(try await executeSwiftBuild(packageDir)) { error in + await XCTAssertAsyncThrowsError( + try await executeSwiftBuild( + packageDir, + buildSystem: self.buildSystemProvider, + ) + ) { error in guard case SwiftPMError.executionFailure(_, let stdout, _) = error else { return XCTFail("invalid error \(error)") } - XCTAssertMatch(stdout, .contains("Compiling plugin MyBuildToolPlugin")) - XCTAssertMatch(stdout, .contains("Compiling plugin MyCommandPlugin")) - XCTAssertMatch(stdout, .contains("error: consecutive statements on a line must be separated by ';'")) - XCTAssertNoMatch(stdout, .contains("Building for debugging...")) + XCTAssertTrue(stdout.contains("error: consecutive statements on a line must be separated by ';'"), "stdout: '\(stdout)'") + XCTAssertFalse(stdout.contains("Building for debugging..."), "stdout: '\(stdout)'") } } } @@ -4337,4 +4447,45 @@ class PackageCommandSwiftBuildTests: PackageCommandTestCase { try XCTExhibitsGitHubIssue(8782) try await super.testCommandPluginPermissions() } + + override func testBuildToolPlugin() async throws { + try XCTSkipOnWindows(because: "TSCBasic/Path.swift:969: Assertion failed, https://github.com/swiftlang/swift-package-manager/issues/8602") + try await super.testBuildToolPlugin() + } + + override func testCommandPluginCompilationError() async throws { + throw XCTSkip("SWBINTTODO: https://github.com/swiftlang/swift-package-manager/issues/8977: does not throw expected error") + try await super.testCommandPluginCompilationError() + } + + override func testPluginCompilationBeforeBuilding() async throws { + throw XCTSkip("SWBINTTODO: https:4//github.com/swiftlang/swift-package-manager/issues/8977") + try await super.testPluginCompilationBeforeBuilding() + } + + override func testPackageEditAndUnedit() async throws { + #if os(Linux) + throw XCTSkip("SWBINTTODO: https://github.com/swiftlang/swift-package-manager/issues/8416: /tmp/Miscellaneous_PackageEdit.H5ku8Q/foo/.build/aarch64-unknown-linux-gnu/Products/Debug-linux/foo: error while loading shared libraries: libswiftCore.so: cannot open shared object file: No such file or directory") + #endif + try XCTSkipOnWindows(because: "https://github.com/swiftlang/swift-package-manager/issues/8774: Unable to write file. and https://github.com/swiftlang/swift-package-manager/issues/8380: linker issue") + try await super.testPackageEditAndUnedit() + } + + override func testPackageReset() async throws { + try XCTSkipOnWindows(because: "https://github.com/swiftlang/swift-package-manager/issues/8774: Unable to write file. and https://github.com/swiftlang/swift-package-manager/issues/8380: linker issue") + try await super.testPackageReset() + } + + override func testPackageClean() async throws { + try XCTSkipOnWindows(because: "https://github.com/swiftlang/swift-package-manager/issues/8774: Unable to write file. and https://github.com/swiftlang/swift-package-manager/issues/8380: linker issue") + try await super.testPackageClean() + } + + override func testPackageResolved() async throws { + #if os(Linux) + throw XCTSkip("SWBINTTODO: https://github.com/swiftlang/swift-package-manager/issues/8416: /tmp/Miscellaneous_PackageEdit.H5ku8Q/foo/.build/aarch64-unknown-linux-gnu/Products/Debug-linux/foo: error while loading shared libraries: libswiftCore.so: cannot open shared object file: No such file or directory") + #endif + try XCTSkipOnWindows(because: "https://github.com/swiftlang/swift-package-manager/issues/8774: Unable to write file. and https://github.com/swiftlang/swift-package-manager/issues/8380: linker issue") + try await super.testPackageResolved() + } } diff --git a/Tests/CommandsTests/PackageRegistryCommandTests.swift b/Tests/CommandsTests/PackageRegistryCommandTests.swift index b4f190f9cf3..41a7cb28657 100644 --- a/Tests/CommandsTests/PackageRegistryCommandTests.swift +++ b/Tests/CommandsTests/PackageRegistryCommandTests.swift @@ -17,6 +17,7 @@ import PackageLoading import PackageModel import PackageRegistry @testable import PackageRegistryCommand +import struct SPMBuildCore.BuildSystemProvider import PackageSigning import _InternalTestSupport import TSCclibc // for SPM_posix_spawn_file_actions_addchdir_np_supported @@ -34,15 +35,17 @@ final class PackageRegistryCommandTests: CommandsTestCase { private func execute( _ args: [String], packagePath: AbsolutePath? = nil, - env: Environment? = nil + env: Environment? = nil, + buildSystem: BuildSystemProvider.Kind, ) async throws -> (stdout: String, stderr: String) { var environment = env ?? [:] // don't ignore local packages when caching environment["SWIFTPM_TESTS_PACKAGECACHE"] = "1" - return try await SwiftPM.Registry.execute( - args, - packagePath: packagePath, - env: environment + return try await executeSwiftPackageRegistry( + packagePath, + extraArgs: args, + env: environment, + buildSystem: buildSystem, ) } @@ -54,7 +57,7 @@ final class PackageRegistryCommandTests: CommandsTestCase { "skipping because test environment doesn't support concurrency" ) - let stdout = try await execute(["-help"]).stdout + let stdout = try await SwiftPM.Registry.execute(["-help"]).stdout XCTAssert(stdout.contains("USAGE: swift package-registry"), "got stdout:\n" + stdout) } @@ -66,12 +69,12 @@ final class PackageRegistryCommandTests: CommandsTestCase { "skipping because test environment doesn't support concurrency" ) - let stdout = try await execute(["--help"]).stdout + let stdout = try await SwiftPM.Registry.execute(["--help"]).stdout XCTAssert(stdout.contains("SEE ALSO: swift package"), "got stdout:\n" + stdout) } func testCommandDoesNotEmitDuplicateSymbols() async throws { - let (stdout, stderr) = try await execute(["--help"]) + let (stdout, stderr) = try await SwiftPM.Registry.execute(["--help"]) XCTAssertNoMatch(stdout, duplicateSymbolRegex) XCTAssertNoMatch(stderr, duplicateSymbolRegex) } @@ -84,7 +87,7 @@ final class PackageRegistryCommandTests: CommandsTestCase { "skipping because test environment doesn't support concurrency" ) - let stdout = try await execute(["--version"]).stdout + let stdout = try await SwiftPM.Registry.execute(["--version"]).stdout XCTAssertMatch(stdout, .regex(#"Swift Package Manager -( \w+ )?\d+.\d+.\d+(-\w+)?"#)) } @@ -100,7 +103,11 @@ final class PackageRegistryCommandTests: CommandsTestCase { // Set default registry do { - try await execute(["set", "\(defaultRegistryBaseURL)"], packagePath: packageRoot) + try await execute( + ["set", "\(defaultRegistryBaseURL)"], + packagePath: packageRoot, + buildSystem: .native, + ) let json = try JSON(data: localFileSystem.readFileContents(configurationFilePath)) XCTAssertEqual(json["registries"]?.dictionary?.count, 1) @@ -113,7 +120,11 @@ final class PackageRegistryCommandTests: CommandsTestCase { // Set new default registry do { - try await execute(["set", "\(customRegistryBaseURL)"], packagePath: packageRoot) + try await execute( + ["set", "\(customRegistryBaseURL)"], + packagePath: packageRoot, + buildSystem: .native, + ) let json = try JSON(data: localFileSystem.readFileContents(configurationFilePath)) XCTAssertEqual(json["registries"]?.dictionary?.count, 1) @@ -126,7 +137,11 @@ final class PackageRegistryCommandTests: CommandsTestCase { // Set default registry with allow-insecure-http option do { - try await execute(["set", "\(customRegistryBaseURL)", "--allow-insecure-http"], packagePath: packageRoot) + try await execute( + ["set", "\(customRegistryBaseURL)", "--allow-insecure-http"], + packagePath: packageRoot, + buildSystem: .native, + ) let json = try JSON(data: localFileSystem.readFileContents(configurationFilePath)) XCTAssertEqual(json["registries"]?.dictionary?.count, 1) @@ -139,7 +154,11 @@ final class PackageRegistryCommandTests: CommandsTestCase { // Unset default registry do { - try await execute(["unset"], packagePath: packageRoot) + try await execute( + ["unset"], + packagePath: packageRoot, + buildSystem: .native, + ) let json = try JSON(data: localFileSystem.readFileContents(configurationFilePath)) XCTAssertEqual(json["registries"]?.dictionary?.count, 0) @@ -150,7 +169,8 @@ final class PackageRegistryCommandTests: CommandsTestCase { do { try await execute( ["set", "\(customRegistryBaseURL)", "--scope", "foo"], - packagePath: packageRoot + packagePath: packageRoot, + buildSystem: .native, ) let json = try JSON(data: localFileSystem.readFileContents(configurationFilePath)) @@ -166,7 +186,8 @@ final class PackageRegistryCommandTests: CommandsTestCase { do { try await execute( ["set", "\(customRegistryBaseURL)", "--scope", "bar"], - packagePath: packageRoot + packagePath: packageRoot, + buildSystem: .native, ) let json = try JSON(data: localFileSystem.readFileContents(configurationFilePath)) @@ -184,7 +205,11 @@ final class PackageRegistryCommandTests: CommandsTestCase { // Unset registry for "foo" scope do { - try await execute(["unset", "--scope", "foo"], packagePath: packageRoot) + try await execute( + ["unset", "--scope", "foo"], + packagePath: packageRoot, + buildSystem: .native, + ) let json = try JSON(data: localFileSystem.readFileContents(configurationFilePath)) XCTAssertEqual(json["registries"]?.dictionary?.count, 1) @@ -212,7 +237,13 @@ final class PackageRegistryCommandTests: CommandsTestCase { XCTAssertFalse(localFileSystem.exists(configurationFilePath)) // Set default registry - await XCTAssertAsyncThrowsError(try await execute(["set", "--scope", "foo"], packagePath: packageRoot)) + await XCTAssertAsyncThrowsError( + try await execute( + ["set", "--scope", "foo"], + packagePath: packageRoot, + buildSystem: .native, + ) + ) XCTAssertFalse(localFileSystem.exists(configurationFilePath)) } @@ -229,7 +260,13 @@ final class PackageRegistryCommandTests: CommandsTestCase { XCTAssertFalse(localFileSystem.exists(configurationFilePath)) // Set default registry - await XCTAssertAsyncThrowsError(try await execute(["set", "invalid"], packagePath: packageRoot)) + await XCTAssertAsyncThrowsError( + try await execute( + ["set", "invalid"], + packagePath: packageRoot, + buildSystem: .native, + ) + ) XCTAssertFalse(localFileSystem.exists(configurationFilePath)) } @@ -246,7 +283,13 @@ final class PackageRegistryCommandTests: CommandsTestCase { XCTAssertFalse(localFileSystem.exists(configurationFilePath)) // Set default registry - await XCTAssertAsyncThrowsError(try await execute(["set", "http://package.example.com"], packagePath: packageRoot)) + await XCTAssertAsyncThrowsError( + try await execute( + ["set", "http://package.example.com"], + packagePath: packageRoot, + buildSystem: .native, + ) + ) XCTAssertFalse(localFileSystem.exists(configurationFilePath)) } @@ -263,7 +306,11 @@ final class PackageRegistryCommandTests: CommandsTestCase { XCTAssertFalse(localFileSystem.exists(configurationFilePath)) // Set default registry - try await execute(["set", "http://package.example.com", "--allow-insecure-http"], packagePath: packageRoot) + try await execute( + ["set", "http://package.example.com", "--allow-insecure-http"], + packagePath: packageRoot, + buildSystem: .native, + ) XCTAssertTrue(localFileSystem.exists(configurationFilePath)) } @@ -283,7 +330,8 @@ final class PackageRegistryCommandTests: CommandsTestCase { do { await XCTAssertAsyncThrowsError(try await execute( ["set", "--scope", "_invalid_", "\(defaultRegistryBaseURL)"], - packagePath: packageRoot + packagePath: packageRoot, + buildSystem: .native, )) } @@ -303,7 +351,11 @@ final class PackageRegistryCommandTests: CommandsTestCase { // Set default registry do { - try await execute(["set", "\(defaultRegistryBaseURL)"], packagePath: packageRoot) + try await execute( + ["set", "\(defaultRegistryBaseURL)"], + packagePath: packageRoot, + buildSystem: .native, + ) let json = try JSON(data: localFileSystem.readFileContents(configurationFilePath)) XCTAssertEqual(json["registries"]?.dictionary?.count, 1) @@ -316,7 +368,13 @@ final class PackageRegistryCommandTests: CommandsTestCase { // Unset registry for missing "baz" scope do { - await XCTAssertAsyncThrowsError(try await execute(["unset", "--scope", "baz"], packagePath: packageRoot)) + await XCTAssertAsyncThrowsError( + try await execute( + ["unset", "--scope", "baz"], + packagePath: packageRoot, + buildSystem: .native, + ) + ) let json = try JSON(data: localFileSystem.readFileContents(configurationFilePath)) XCTAssertEqual(json["registries"]?.dictionary?.count, 1) @@ -484,16 +542,17 @@ final class PackageRegistryCommandTests: CommandsTestCase { let workingDirectory = temporaryDirectory.appending(component: UUID().uuidString) try localFileSystem.createDirectory(workingDirectory) - await XCTAssertAsyncThrowsError(try await SwiftPM.Registry.execute( - [ + await XCTAssertAsyncThrowsError(try await executeSwiftPackageRegistry( + packageDirectory, + extraArgs: [ "publish", packageIdentity, version, "--url=\(registryURL)", "--scratch-directory=\(workingDirectory.pathString)", - "--package-path=\(packageDirectory.pathString)", "--dry-run", - ] + ], + buildSystem: .native, )) } } @@ -527,17 +586,18 @@ final class PackageRegistryCommandTests: CommandsTestCase { let workingDirectory = temporaryDirectory.appending(component: UUID().uuidString) try localFileSystem.createDirectory(workingDirectory) - try await SwiftPM.Registry.execute( - [ + try await executeSwiftPackageRegistry( + packageDirectory, + extraArgs: [ "publish", packageIdentity, version, "--url=\(registryURL)", "--scratch-directory=\(workingDirectory.pathString)", - "--package-path=\(packageDirectory.pathString)", "--allow-insecure-http", "--dry-run", - ] + ], + buildSystem: .native, ) } @@ -568,17 +628,18 @@ final class PackageRegistryCommandTests: CommandsTestCase { try configuration.add(authentication: .init(type: .basic), for: URL(registryURL)) try localFileSystem.writeFileContents(configurationFilePath, data: JSONEncoder().encode(configuration)) - await XCTAssertAsyncThrowsError(try await SwiftPM.Registry.execute( - [ + await XCTAssertAsyncThrowsError(try await executeSwiftPackageRegistry( + packageDirectory, + extraArgs: [ "publish", packageIdentity, version, "--url=\(registryURL)", "--scratch-directory=\(workingDirectory.pathString)", - "--package-path=\(packageDirectory.pathString)", "--allow-insecure-http", "--dry-run", - ] + ], + buildSystem: .native, )) } } @@ -615,17 +676,18 @@ final class PackageRegistryCommandTests: CommandsTestCase { let metadataPath = temporaryDirectory.appending("metadata.json") try localFileSystem.writeFileContents(metadataPath, string: "{}") - try await SwiftPM.Registry.execute( - [ + try await executeSwiftPackageRegistry( + packageDirectory, + extraArgs: [ "publish", packageIdentity, version, "--url=\(registryURL)", "--scratch-directory=\(workingDirectory.pathString)", "--metadata-path=\(metadataPath.pathString)", - "--package-path=\(packageDirectory.pathString)", "--dry-run", - ] + ], + buildSystem: .native, ) let archivePath = workingDirectory.appending("\(packageIdentity)-\(version).zip") @@ -659,16 +721,17 @@ final class PackageRegistryCommandTests: CommandsTestCase { let metadataPath = packageDirectory.appending(PackageRegistryCommand.Publish.metadataFilename) try localFileSystem.writeFileContents(metadataPath, string: "{}") - try await SwiftPM.Registry.execute( - [ + try await executeSwiftPackageRegistry( + packageDirectory, + extraArgs: [ "publish", packageIdentity, version, "--url=\(registryURL)", "--scratch-directory=\(workingDirectory.pathString)", - "--package-path=\(packageDirectory.pathString)", "--dry-run", - ] + ], + buildSystem: .native, ) let archivePath = workingDirectory.appending("\(packageIdentity)-\(version).zip") @@ -699,16 +762,17 @@ final class PackageRegistryCommandTests: CommandsTestCase { let workingDirectory = temporaryDirectory.appending(component: UUID().uuidString) try localFileSystem.createDirectory(workingDirectory) - try await SwiftPM.Registry.execute( - [ + try await executeSwiftPackageRegistry( + packageDirectory, + extraArgs: [ "publish", packageIdentity, version, "--url=\(registryURL)", "--scratch-directory=\(workingDirectory.pathString)", - "--package-path=\(packageDirectory.pathString)", "--dry-run", - ] + ], + buildSystem: .native, ) let archivePath = workingDirectory.appending("\(packageIdentity)-\(version).zip") @@ -807,20 +871,21 @@ final class PackageRegistryCommandTests: CommandsTestCase { ) } - try await SwiftPM.Registry.execute( - [ + try await executeSwiftPackageRegistry( + packageDirectory, + extraArgs: [ "publish", packageIdentity, version, "--url=\(registryURL)", "--scratch-directory=\(workingDirectory.pathString)", "--metadata-path=\(metadataPath.pathString)", - "--package-path=\(packageDirectory.pathString)", "--private-key-path=\(privateKeyPath.pathString)", "--cert-chain-paths=\(certificatePath.pathString)", "\(intermediateCertificatePath.pathString)", "--dry-run", - ] + ], + buildSystem: .native, ) // Validate signatures @@ -918,19 +983,20 @@ final class PackageRegistryCommandTests: CommandsTestCase { ) } - try await SwiftPM.Registry.execute( - [ + try await executeSwiftPackageRegistry( + packageDirectory, + extraArgs: [ "publish", packageIdentity, version, "--url=\(registryURL)", "--scratch-directory=\(workingDirectory.pathString)", - "--package-path=\(packageDirectory.pathString)", "--private-key-path=\(privateKeyPath.pathString)", "--cert-chain-paths=\(certificatePath.pathString)", "\(intermediateCertificatePath.pathString)", "--dry-run", - ] + ], + buildSystem: .native, ) // Validate signatures @@ -1025,19 +1091,20 @@ final class PackageRegistryCommandTests: CommandsTestCase { ) } - try await SwiftPM.Registry.execute( - [ + try await executeSwiftPackageRegistry( + packageDirectory, + extraArgs: [ "publish", packageIdentity, version, "--url=\(registryURL)", "--scratch-directory=\(workingDirectory.pathString)", - "--package-path=\(packageDirectory.pathString)", "--private-key-path=\(privateKeyPath.pathString)", "--cert-chain-paths=\(certificatePath.pathString)", "\(intermediateCertificatePath.pathString)", "--dry-run", - ] + ], + buildSystem: .native, ) // Validate signatures diff --git a/Tests/FunctionalPerformanceTests/BuildPerfTests.swift b/Tests/FunctionalPerformanceTests/BuildPerfTests.swift index efe4333716a..4722a4ecee8 100644 --- a/Tests/FunctionalPerformanceTests/BuildPerfTests.swift +++ b/Tests/FunctionalPerformanceTests/BuildPerfTests.swift @@ -24,11 +24,11 @@ // @discardableResult // func execute(args: [String] = [], packagePath: AbsolutePath) async throws -> (stdout: String, stderr: String) { // // FIXME: We should pass the SWIFT_EXEC at lower level. -// try await SwiftPM.Build.execute(args + [], packagePath: packagePath, env: ["SWIFT_EXEC": UserToolchain.default.swiftCompilerPath.pathString]) +// try await executeSwiftBuild(packagePath, extraArgs: args + [], env: ["SWIFT_EXEC": UserToolchain.default.swiftCompilerPath.pathString], buildSystem: .native) // } // // func clean(packagePath: AbsolutePath) async throws { -// _ = try await SwiftPM.Package.execute(["clean"], packagePath: packagePath) +// _ = try await executeSwiftPackage(packagePath, extraArgs: ["clean"], buildSystem: .native) // } // // func testTrivialPackageFullBuild() throws { diff --git a/Tests/FunctionalTests/CFamilyTargetTests.swift b/Tests/FunctionalTests/CFamilyTargetTests.swift index ae494371322..a3f9d15d223 100644 --- a/Tests/FunctionalTests/CFamilyTargetTests.swift +++ b/Tests/FunctionalTests/CFamilyTargetTests.swift @@ -37,7 +37,7 @@ private func XCTAssertDirectoryContainsFile(dir: AbsolutePath, filename: String, final class CFamilyTargetTestCase: XCTestCase { func testCLibraryWithSpaces() async throws { try await fixtureXCTest(name: "CFamilyTargets/CLibraryWithSpaces") { fixturePath in - await XCTAssertBuilds(fixturePath) + await XCTAssertBuilds(fixturePath, buildSystem: .native) 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 +47,7 @@ final class CFamilyTargetTestCase: XCTestCase { func testCUsingCAndSwiftDep() async throws { try await fixtureXCTest(name: "DependencyResolution/External/CUsingCDep") { fixturePath in let packageRoot = fixturePath.appending("Bar") - await XCTAssertBuilds(packageRoot) + await XCTAssertBuilds(packageRoot, buildSystem: .native) 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 +58,7 @@ final class CFamilyTargetTestCase: XCTestCase { func testModuleMapGenerationCases() async throws { try await fixtureXCTest(name: "CFamilyTargets/ModuleMapGenerationCases") { fixturePath in - await XCTAssertBuilds(fixturePath) + await XCTAssertBuilds(fixturePath, buildSystem: .native) 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 +69,13 @@ final class CFamilyTargetTestCase: XCTestCase { func testNoIncludeDirCheck() async throws { try await fixtureXCTest(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: .native, + ), + "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 +87,7 @@ final class CFamilyTargetTestCase: XCTestCase { func testCanForwardExtraFlagsToClang() async throws { // Try building a fixture which needs extra flags to be able to build. try await fixtureXCTest(name: "CFamilyTargets/CDynamicLookup") { fixturePath in - await XCTAssertBuilds(fixturePath, Xld: ["-undefined", "dynamic_lookup"]) + await XCTAssertBuilds(fixturePath, Xld: ["-undefined", "dynamic_lookup"], buildSystem: .native) let debugPath = fixturePath.appending(components: ".build", try UserToolchain.default.targetTriple.platformBuildPathComponent, "debug") XCTAssertDirectoryContainsFile(dir: debugPath, filename: "Foo.c.o") } @@ -93,16 +99,16 @@ final class CFamilyTargetTestCase: XCTestCase { #endif try await fixtureXCTest(name: "CFamilyTargets/ObjCmacOSPackage") { fixturePath in // Build the package. - await XCTAssertBuilds(fixturePath) + await XCTAssertBuilds(fixturePath, buildSystem: .native) XCTAssertDirectoryContainsFile(dir: fixturePath.appending(components: ".build", try UserToolchain.default.targetTriple.platformBuildPathComponent, "debug"), filename: "HelloWorldExample.m.o") // Run swift-test on package. - await XCTAssertSwiftTest(fixturePath) + await XCTAssertSwiftTest(fixturePath, buildSystem: .native) } } func testCanBuildRelativeHeaderSearchPaths() async throws { try await fixtureXCTest(name: "CFamilyTargets/CLibraryParentSearchPath") { fixturePath in - await XCTAssertBuilds(fixturePath) + await XCTAssertBuilds(fixturePath, buildSystem: .native) XCTAssertDirectoryContainsFile(dir: fixturePath.appending(components: ".build", try UserToolchain.default.targetTriple.platformBuildPathComponent, "debug"), filename: "HeaderInclude.swiftmodule") } } diff --git a/Tests/FunctionalTests/DependencyResolutionTests.swift b/Tests/FunctionalTests/DependencyResolutionTests.swift index c0bc3981f7c..21f196180fc 100644 --- a/Tests/FunctionalTests/DependencyResolutionTests.swift +++ b/Tests/FunctionalTests/DependencyResolutionTests.swift @@ -23,7 +23,7 @@ import enum TSCUtility.Git class DependencyResolutionTests: XCTestCase { func testInternalSimple() async throws { try await fixtureXCTest(name: "DependencyResolution/Internal/Simple") { fixturePath in - await XCTAssertBuilds(fixturePath) + await XCTAssertBuilds(fixturePath, buildSystem: .native) let output = try await AsyncProcess.checkNonZeroExit(args: fixturePath.appending(components: ".build", UserToolchain.default.targetTriple.platformBuildPathComponent, "debug", "Foo").pathString).withSwiftLineEnding XCTAssertEqual(output, "Foo\nBar\n") @@ -32,13 +32,13 @@ class DependencyResolutionTests: XCTestCase { func testInternalExecAsDep() async throws { try await fixtureXCTest(name: "DependencyResolution/Internal/InternalExecutableAsDependency") { fixturePath in - await XCTAssertBuildFails(fixturePath) + await XCTAssertBuildFails(fixturePath, buildSystem: .native) } } func testInternalComplex() async throws { try await fixtureXCTest(name: "DependencyResolution/Internal/Complex") { fixturePath in - await XCTAssertBuilds(fixturePath) + await XCTAssertBuilds(fixturePath, buildSystem: .native) let output = try await AsyncProcess.checkNonZeroExit(args: fixturePath.appending(components: ".build", UserToolchain.default.targetTriple.platformBuildPathComponent, "debug", "Foo").pathString).withSwiftLineEnding XCTAssertEqual(output, "meiow Baz\n") @@ -55,7 +55,7 @@ class DependencyResolutionTests: XCTestCase { } let packageRoot = fixturePath.appending("Bar") - await XCTAssertBuilds(packageRoot) + await XCTAssertBuilds(packageRoot, buildSystem: .native) XCTAssertFileExists(fixturePath.appending(components: "Bar", ".build", try UserToolchain.default.targetTriple.platformBuildPathComponent, "debug", executableName("Bar"))) let path = try SwiftPM.packagePath(for: "Foo", packageRoot: packageRoot) XCTAssert(try GitRepository(path: path).getTags().contains("1.2.3")) @@ -64,7 +64,7 @@ class DependencyResolutionTests: XCTestCase { func testExternalComplex() async throws { try await fixtureXCTest(name: "DependencyResolution/External/Complex") { fixturePath in - await XCTAssertBuilds(fixturePath.appending("app")) + await XCTAssertBuilds(fixturePath.appending("app"), buildSystem: .native) let output = try await AsyncProcess.checkNonZeroExit(args: fixturePath.appending(components: "app", ".build", UserToolchain.default.targetTriple.platformBuildPathComponent, "debug", "Dealer").pathString).withSwiftLineEnding XCTAssertEqual(output, "♣︎K\n♣︎Q\n♣︎J\n♣︎10\n♣︎9\n♣︎8\n♣︎7\n♣︎6\n♣︎5\n♣︎4\n") } @@ -74,7 +74,10 @@ class DependencyResolutionTests: XCTestCase { try await fixtureXCTest(name: "DependencyResolution/External/Branch") { fixturePath in // Tests the convenience init .package(url: , branch: ) let app = fixturePath.appending("Bar") - try await SwiftPM.Build.execute(packagePath: app) + try await executeSwiftBuild( + app, + buildSystem: .native, + ) } } @@ -93,7 +96,11 @@ class DependencyResolutionTests: XCTestCase { // run with no mirror do { - let output = try await executeSwiftPackage(appPath, extraArgs: ["show-dependencies"]) + let output = try await executeSwiftPackage( + appPath, + extraArgs: ["show-dependencies"], + buildSystem: .native, + ) // logs are in stderr XCTAssertMatch(output.stderr, .contains("Fetching \(prefix.appending("Foo").pathString)\n")) XCTAssertMatch(output.stderr, .contains("Fetching \(prefix.appending("Bar").pathString)\n")) @@ -105,7 +112,7 @@ class DependencyResolutionTests: XCTestCase { XCTAssertMatch(resolvedPackages, .contains(prefix.appending("Foo").escapedPathString)) XCTAssertMatch(resolvedPackages, .contains(prefix.appending("Bar").escapedPathString)) - await XCTAssertBuilds(appPath) + await XCTAssertBuilds(appPath, buildSystem: .native) } // clean @@ -113,13 +120,26 @@ class DependencyResolutionTests: XCTestCase { try localFileSystem.removeFileTree(packageResolvedPath) // set mirror - _ = try await executeSwiftPackage(appPath, extraArgs: ["config", "set-mirror", - "--original-url", prefix.appending("Bar").pathString, - "--mirror-url", prefix.appending("BarMirror").pathString]) + _ = try await executeSwiftPackage( + appPath, + extraArgs: [ + "config", + "set-mirror", + "--original-url", + prefix.appending("Bar").pathString, + "--mirror-url", + prefix.appending("BarMirror").pathString, + ], + buildSystem: .native, + ) // run with mirror do { - let output = try await executeSwiftPackage(appPath, extraArgs: ["show-dependencies"]) + let output = try await executeSwiftPackage( + appPath, + extraArgs: ["show-dependencies"], + buildSystem: .native, + ) // logs are in stderr XCTAssertMatch(output.stderr, .contains("Fetching \(prefix.appending("Foo").pathString)\n")) XCTAssertMatch(output.stderr, .contains("Fetching \(prefix.appending("BarMirror").pathString)\n")) @@ -135,14 +155,18 @@ class DependencyResolutionTests: XCTestCase { XCTAssertMatch(resolvedPackages, .contains(prefix.appending("Bar").escapedPathString)) XCTAssertNoMatch(resolvedPackages, .contains(prefix.appending("BarMirror").escapedPathString)) - await XCTAssertBuilds(appPath) + await XCTAssertBuilds(appPath, buildSystem: .native) } } } func testPackageLookupCaseInsensitive() async throws { try await fixtureXCTest(name: "DependencyResolution/External/PackageLookupCaseInsensitive") { fixturePath in - try await SwiftPM.Package.execute(["update"], packagePath: fixturePath.appending("pkg")) + try await executeSwiftPackage( + fixturePath.appending("pkg"), + extraArgs: ["update"], + buildSystem: .native, + ) } } } diff --git a/Tests/FunctionalTests/MacroTests.swift b/Tests/FunctionalTests/MacroTests.swift index 2de1aa5e073..f3724770503 100644 --- a/Tests/FunctionalTests/MacroTests.swift +++ b/Tests/FunctionalTests/MacroTests.swift @@ -26,7 +26,11 @@ class MacroTests: XCTestCase { try XCTSkipIf(!localFileSystem.exists(libSwiftSyntaxMacrosPath), "test need `libSwiftSyntaxMacros` to exist in the host toolchain") try fixtureXCTest(name: "Macros") { fixturePath in - let (stdout, _) = try executeSwiftBuild(fixturePath.appending("MacroPackage"), configuration: .debug) + let (stdout, _) = try executeSwiftBuild( + fixturePath.appending("MacroPackage"), + configuration: .debug, + buildSystem: .native, + ) XCTAssert(stdout.contains("@__swiftmacro_11MacroClient11fontLiteralfMf_.swift as Font"), "stdout:\n\(stdout)") XCTAssert(stdout.contains("Build complete!"), "stdout:\n\(stdout)") } diff --git a/Tests/FunctionalTests/MiscellaneousTests.swift b/Tests/FunctionalTests/MiscellaneousTests.swift index 10ce6758909..1a7e39d6554 100644 --- a/Tests/FunctionalTests/MiscellaneousTests.swift +++ b/Tests/FunctionalTests/MiscellaneousTests.swift @@ -28,7 +28,10 @@ final class MiscellaneousTestCase: XCTestCase { // the selected version of the package try await fixtureXCTest(name: "DependencyResolution/External/Simple") { fixturePath in - let (stdout, stderr) = try await executeSwiftBuild(fixturePath.appending("Bar")) + let (stdout, stderr) = try await executeSwiftBuild( + fixturePath.appending("Bar"), + buildSystem: .native, + ) // package resolution output goes to stderr XCTAssertMatch(stderr, .regex("Computed .* at 1\\.2\\.3")) // in "swift build" build output goes to stdout @@ -48,7 +51,10 @@ final class MiscellaneousTestCase: XCTestCase { // are not passed into the build-command. try await fixtureXCTest(name: "Miscellaneous/ExactDependencies") { fixturePath in - await XCTAssertBuilds(fixturePath.appending("app")) + await XCTAssertBuilds( + fixturePath.appending("app"), + buildSystem: .native, + ) let buildDir = fixturePath.appending(components: "app", ".build", try UserToolchain.default.targetTriple.platformBuildPathComponent, "debug") XCTAssertFileExists(buildDir.appending(executableName("FooExec"))) XCTAssertFileExists(buildDir.appending(components: "Modules", "FooLib1.swiftmodule")) @@ -62,14 +68,28 @@ final class MiscellaneousTestCase: XCTestCase { // should immediately exit with exit-status: `0` try await fixtureXCTest(name: "DependencyResolution/External/Complex") { fixturePath in - await XCTAssertBuilds(fixturePath.appending("app")) - await XCTAssertBuilds(fixturePath.appending("app")) - await XCTAssertBuilds(fixturePath.appending("app")) + await XCTAssertBuilds( + fixturePath.appending("app"), + buildSystem: .native, + ) + await XCTAssertBuilds( + fixturePath.appending("app"), + buildSystem: .native, + ) + await XCTAssertBuilds( + fixturePath.appending("app"), + buildSystem: .native, + ) } } func testNoArgumentsExitsWithOne() async throws { - await XCTAssertThrowsCommandExecutionError(try await executeSwiftBuild("/")) { error in + await XCTAssertThrowsCommandExecutionError( + try await executeSwiftBuild( + "/", + buildSystem: .native, + ) + ) { error in // if our code crashes we'll get an exit code of 256 guard error.result.exitStatus == .terminated(code: 1) else { return XCTFail("failed in an unexpected manner: \(error)") @@ -79,7 +99,12 @@ final class MiscellaneousTestCase: XCTestCase { func testCompileFailureExitsGracefully() async throws { try await fixtureXCTest(name: "Miscellaneous/CompileFails") { fixturePath in - await XCTAssertThrowsCommandExecutionError(try await executeSwiftBuild(fixturePath)) { error in + await XCTAssertThrowsCommandExecutionError( + try await executeSwiftBuild( + fixturePath, + buildSystem: .native, + ) + ) { error in // if our code crashes we'll get an exit code of 256 guard error.result.exitStatus == .terminated(code: 1) else { return XCTFail("failed in an unexpected manner: \(error)") @@ -93,8 +118,16 @@ final class MiscellaneousTestCase: XCTestCase { func testPackageManagerDefineAndXArgs() async throws { try await fixtureXCTest(name: "Miscellaneous/-DSWIFT_PACKAGE") { fixturePath in - await XCTAssertBuildFails(fixturePath) - await XCTAssertBuilds(fixturePath, Xcc: ["-DEXTRA_C_DEFINE=2"], Xswiftc: ["-DEXTRA_SWIFTC_DEFINE"]) + await XCTAssertBuildFails( + fixturePath, + buildSystem: .native, + ) + await XCTAssertBuilds( + fixturePath, + Xcc: ["-DEXTRA_C_DEFINE=2"], + Xswiftc: ["-DEXTRA_SWIFTC_DEFINE"], + buildSystem: .native, + ) } } @@ -106,7 +139,10 @@ final class MiscellaneousTestCase: XCTestCase { try await fixtureXCTest(name: "Miscellaneous/DependencyEdges/Internal") { fixturePath in let execpath = fixturePath.appending(components: ".build", try UserToolchain.default.targetTriple.platformBuildPathComponent, "debug", "Foo").pathString - await XCTAssertBuilds(fixturePath) + await XCTAssertBuilds( + fixturePath, + buildSystem: .native, + ) var output = try await AsyncProcess.checkNonZeroExit(args: execpath) XCTAssertEqual(output, "Hello\(ProcessInfo.EOL)") @@ -116,7 +152,10 @@ final class MiscellaneousTestCase: XCTestCase { try localFileSystem.writeFileContents(fixturePath.appending(components: "Bar", "Bar.swift"), bytes: "public let bar = \"Goodbye\"\n") - await XCTAssertBuilds(fixturePath) + await XCTAssertBuilds( + fixturePath, + buildSystem: .native, + ) output = try await AsyncProcess.checkNonZeroExit(args: execpath) XCTAssertEqual(output, "Goodbye\(ProcessInfo.EOL)") } @@ -131,7 +170,10 @@ final class MiscellaneousTestCase: XCTestCase { let execpath = fixturePath.appending(components: "app", ".build", try UserToolchain.default.targetTriple.platformBuildPathComponent, "debug", "Dealer").pathString let packageRoot = fixturePath.appending("app") - await XCTAssertBuilds(packageRoot) + await XCTAssertBuilds( + packageRoot, + buildSystem: .native, + ) var output = try await AsyncProcess.checkNonZeroExit(args: execpath).withSwiftLineEnding XCTAssertEqual(output, "♣︎K\n♣︎Q\n♣︎J\n♣︎10\n♣︎9\n♣︎8\n♣︎7\n♣︎6\n♣︎5\n♣︎4\n") @@ -143,7 +185,10 @@ final class MiscellaneousTestCase: XCTestCase { try localFileSystem.chmod(.userWritable, path: path, options: [.recursive]) try localFileSystem.writeFileContents(path.appending(components: "src", "Fisher-Yates_Shuffle.swift"), bytes: "public extension Collection{ func shuffle() -> [Iterator.Element] {return []} }\n\npublic extension MutableCollection where Index == Int { mutating func shuffleInPlace() { for (i, _) in enumerated() { self[i] = self[0] } }}\n\npublic let shuffle = true") - await XCTAssertBuilds(fixturePath.appending("app")) + await XCTAssertBuilds( + fixturePath.appending("app"), + buildSystem: .native, + ) output = try await AsyncProcess.checkNonZeroExit(args: execpath).withSwiftLineEnding XCTAssertEqual(output, "♠︎A\n♠︎A\n♠︎A\n♠︎A\n♠︎A\n♠︎A\n♠︎A\n♠︎A\n♠︎A\n♠︎A\n") } @@ -158,7 +203,10 @@ final class MiscellaneousTestCase: XCTestCase { let execpath = [fixturePath.appending(components: "root", ".build", try UserToolchain.default.targetTriple.platformBuildPathComponent, "debug", "dep2").pathString] let packageRoot = fixturePath.appending("root") - await XCTAssertBuilds(fixturePath.appending("root")) + await XCTAssertBuilds( + fixturePath.appending("root"), + buildSystem: .native, + ) var output = try await AsyncProcess.checkNonZeroExit(arguments: execpath) XCTAssertEqual(output, "Hello\(ProcessInfo.EOL)") @@ -170,7 +218,10 @@ final class MiscellaneousTestCase: XCTestCase { try localFileSystem.chmod(.userWritable, path: path, options: [.recursive]) try localFileSystem.writeFileContents(path.appending(components: "Foo.swift"), bytes: "public let foo = \"Goodbye\"") - await XCTAssertBuilds(fixturePath.appending("root")) + await XCTAssertBuilds( + fixturePath.appending("root"), + buildSystem: .native, + ) output = try await AsyncProcess.checkNonZeroExit(arguments: execpath) XCTAssertEqual(output, "Goodbye\(ProcessInfo.EOL)") } @@ -178,7 +229,10 @@ final class MiscellaneousTestCase: XCTestCase { func testSpaces() async throws { try await fixtureXCTest(name: "Miscellaneous/Spaces Fixture") { fixturePath in - await XCTAssertBuilds(fixturePath) + await XCTAssertBuilds( + fixturePath, + buildSystem: .native, + ) XCTAssertFileExists(fixturePath.appending(components: ".build", try UserToolchain.default.targetTriple.platformBuildPathComponent, "debug", "Module_Name_1.build", "Foo.swift.o")) } } @@ -188,9 +242,15 @@ final class MiscellaneousTestCase: XCTestCase { #if false // Make sure that swiftpm doesn't rebuild second time if the modulemap is being generated. try fixtureXCTest(name: "CFamilyTargets/SwiftCMixed") { fixturePath in - var output = try await executeSwiftBuild(prefix) + var output = try await executeSwiftBuild( + prefix, + buildSystem: .native, + ) XCTAssertFalse(output.isEmpty, output) - output = try await executeSwiftBuild(prefix) + output = try await executeSwiftBuild( + prefix, + buildSystem: .native, + ) XCTAssertTrue(output.isEmpty, output) } #endif @@ -202,7 +262,11 @@ final class MiscellaneousTestCase: XCTestCase { #endif try await fixtureXCTest(name: "Miscellaneous/DistantFutureDeploymentTarget") { fixturePath in let hostTriple = try UserToolchain.default.targetTriple - try await executeSwiftBuild(fixturePath, Xswiftc: ["-target", "\(hostTriple.archName)-apple-macosx41.0"]) + try await executeSwiftBuild( + fixturePath, + Xswiftc: ["-target", "\(hostTriple.archName)-apple-macosx41.0"], + buildSystem: .native, + ) } } @@ -235,15 +299,27 @@ final class MiscellaneousTestCase: XCTestCase { let moduleUser = fixturePath.appending("SystemModuleUserClang") let env: Environment = ["PKG_CONFIG_PATH": fixturePath.pathString] - _ = try await executeSwiftBuild(moduleUser, env: env) + _ = try await executeSwiftBuild( + moduleUser, + env: env, + buildSystem: .native, + ) XCTAssertFileExists(moduleUser.appending(components: ".build", triple.platformBuildPathComponent, "debug", "SystemModuleUserClang")) // Clean up the build directory before re-running the build with // different arguments. - _ = try await executeSwiftPackage(moduleUser, extraArgs: ["clean"]) + _ = try await executeSwiftPackage( + moduleUser, + extraArgs: ["clean"], + buildSystem: .native, + ) - _ = try await executeSwiftBuild(moduleUser, extraArgs: ["--pkg-config-path", fixturePath.pathString]) + _ = try await executeSwiftBuild( + moduleUser, + extraArgs: ["--pkg-config-path", fixturePath.pathString], + buildSystem: .native, + ) XCTAssertFileExists(moduleUser.appending(components: ".build", triple.platformBuildPathComponent, "debug", "SystemModuleUserClang")) } @@ -311,7 +387,12 @@ final class MiscellaneousTestCase: XCTestCase { // Launch swift-build. let app = fixturePath.appending("Bar") - await XCTAssertAsyncThrowsError(try await SwiftPM.Build.execute(packagePath: app)) { error in + await XCTAssertAsyncThrowsError( + try await executeSwiftBuild( + app, + buildSystem: .native, + ) + ) { error in // We should exited with a failure from the attempt to "git clone" // something that doesn't exist. guard case SwiftPMError.executionFailure(_, _, let stderr) = error else { @@ -326,7 +407,12 @@ final class MiscellaneousTestCase: XCTestCase { try await fixtureXCTest(name: "Miscellaneous/LocalPackageAsURL", createGitRepo: false) { fixturePath in // This fixture has a setup that is trying to use a local package // as a url that hasn't been initialized as a repo - await XCTAssertAsyncThrowsError(try await SwiftPM.Build.execute(packagePath: fixturePath.appending("Bar"))) { error in + await XCTAssertAsyncThrowsError( + try await executeSwiftBuild( + fixturePath.appending("Bar"), + buildSystem: .native, + ) + ) { error in guard case SwiftPMError.executionFailure(_, _, let stderr) = error else { return XCTFail("invalid error \(error)") } @@ -349,7 +435,9 @@ final class MiscellaneousTestCase: XCTestCase { /*let output =*/ try await executeSwiftBuild( fixturePath, - extraArgs: ["--experimental-lto-mode=full", "--verbose"] + extraArgs: ["--experimental-lto-mode=full", "--verbose"], + buildSystem: .native, + ) // FIXME: On macOS dsymutil cannot find temporary .o files? (#6890) // Ensure warnings like the following are not present in build output @@ -390,8 +478,15 @@ final class MiscellaneousTestCase: XCTestCase { // ••••• // Attempt several operations. - try await SwiftPM.Test.execute(packagePath: fixturePath) - try await SwiftPM.Run.execute([complicatedString + "‐tool"], packagePath: fixturePath) + try await executeSwiftTest( + fixturePath, + buildSystem: .native, + ) + try await executeSwiftRun( + fixturePath, + complicatedString + "‐tool", + buildSystem: .native, + ) } #endif } @@ -399,7 +494,10 @@ final class MiscellaneousTestCase: XCTestCase { func testTestsCanLinkAgainstExecutable() async throws { try await fixtureXCTest(name: "Miscellaneous/TestableExe") { fixturePath in do { - let (stdout, stderr) = try await executeSwiftTest(fixturePath) + let (stdout, stderr) = try await executeSwiftTest( + fixturePath, + buildSystem: .native, + ) // in "swift test" build output goes to stderr XCTAssertMatch(stderr, .contains("Linking TestableExe1")) XCTAssertMatch(stderr, .contains("Linking TestableExe2")) @@ -412,7 +510,11 @@ final class MiscellaneousTestCase: XCTestCase { } catch { #if os(macOS) && arch(arm64) // Add some logging but ignore the failure for an environment being investigated. - let (stdout, stderr) = try await executeSwiftTest(fixturePath, extraArgs: ["-v"]) + let (stdout, stderr) = try await executeSwiftTest( + fixturePath, + extraArgs: ["-v"], + buildSystem: .native, + ) print("testTestsCanLinkAgainstExecutable failed") print("ENV:\n") for (k, v) in Environment.current.sorted(by: { $0.key < $1.key }) { @@ -430,7 +532,10 @@ final class MiscellaneousTestCase: XCTestCase { @available(macOS 15, *) func testTestsCanLinkAgainstAsyncExecutable() async throws { try await fixtureXCTest(name: "Miscellaneous/TestableAsyncExe") { fixturePath in - let (stdout, stderr) = try await executeSwiftTest(fixturePath) + let (stdout, stderr) = try await executeSwiftTest( + fixturePath, + buildSystem: .native, + ) // in "swift test" build output goes to stderr XCTAssertMatch(stderr, .contains("Linking TestableAsyncExe1")) XCTAssertMatch(stderr, .contains("Linking TestableAsyncExe2")) @@ -450,7 +555,10 @@ final class MiscellaneousTestCase: XCTestCase { func testExecutableTargetMismatch() async throws { try await fixtureXCTest(name: "Miscellaneous/TargetMismatch") { path in do { - let output = try await executeSwiftBuild(path) + let output = try await executeSwiftBuild( + path, + buildSystem: .native, + ) // in "swift build" build output goes to stdout XCTAssertMatch(output.stdout, .contains("Compiling Sample main.swift")) XCTAssertMatch(output.stderr, .contains("The target named 'Sample' was identified as an executable target but a non-executable product with this name already exists.")) @@ -462,7 +570,12 @@ final class MiscellaneousTestCase: XCTestCase { func testLibraryTriesToIncludeExecutableTarget() async throws { try await fixtureXCTest(name: "Miscellaneous/PackageWithMalformedLibraryProduct") { path in - await XCTAssertThrowsCommandExecutionError(try await executeSwiftBuild(path)) { error in + await XCTAssertThrowsCommandExecutionError( + try await executeSwiftBuild( + path, + buildSystem: .native, + ) + ) { error in // if our code crashes we'll get an exit code of 256 guard error.result.exitStatus == .terminated(code: 1) else { return XCTFail("failed in an unexpected manner: \(error)") @@ -489,7 +602,10 @@ final class MiscellaneousTestCase: XCTestCase { do { // make sure it builds - let output = try await executeSwiftBuild(appPath) + let output = try await executeSwiftBuild( + appPath, + buildSystem: .native, + ) // package resolution output goes to stderr XCTAssertMatch(output.stderr, .contains("Fetching \(prefix.appending("Foo").pathString)")) XCTAssertMatch(output.stderr, .contains("Fetched \(prefix.appending("Foo").pathString)")) @@ -502,18 +618,29 @@ final class MiscellaneousTestCase: XCTestCase { } // put foo into edit mode - _ = try await executeSwiftPackage(appPath, extraArgs: ["edit", "Foo"]) + _ = try await executeSwiftPackage( + appPath, + extraArgs: ["edit", "Foo"], + buildSystem: .native, + ) XCTAssertDirectoryExists(appPath.appending(components: ["Packages", "Foo"])) do { // build again in edit mode - let output = try await executeSwiftBuild(appPath) + let output = try await executeSwiftBuild( + appPath, + buildSystem: .native, + ) XCTAssertMatch(output.stdout, .contains("Build complete!")) } do { // take foo out of edit mode - let output = try await executeSwiftPackage(appPath, extraArgs: ["unedit", "Foo"]) + let output = try await executeSwiftPackage( + appPath, + extraArgs: ["unedit", "Foo"], + buildSystem: .native, + ) // package resolution output goes to stderr XCTAssertMatch(output.stderr, .contains("Creating working copy for \(prefix.appending("Foo"))")) XCTAssertNoSuchPath(appPath.appending(components: ["Packages", "Foo"])) @@ -521,7 +648,10 @@ final class MiscellaneousTestCase: XCTestCase { // build again in edit mode do { - let output = try await executeSwiftBuild(appPath) + let output = try await executeSwiftBuild( + appPath, + buildSystem: .native, + ) // in "swift build" build output goes to stdout XCTAssertMatch(output.stdout, .contains("Build complete!")) } @@ -532,7 +662,11 @@ final class MiscellaneousTestCase: XCTestCase { try await fixtureXCTest(name: "Miscellaneous/Simple") { path in let customCachePath = path.appending(components: "custom", "cache") XCTAssertNoSuchPath(customCachePath) - try await SwiftPM.Build.execute(["--cache-path", customCachePath.pathString], packagePath: path) + try await executeSwiftBuild( + path, + extraArgs: ["--cache-path", customCachePath.pathString], + buildSystem: .native, + ) XCTAssertDirectoryExists(customCachePath) } @@ -542,11 +676,17 @@ final class MiscellaneousTestCase: XCTestCase { try localFileSystem.chmod(.userUnWritable, path: path) let customCachePath = path.appending(components: "custom", "cache") XCTAssertNoSuchPath(customCachePath) - await XCTAssertAsyncThrowsError(try await SwiftPM.Build.execute(["--cache-path", customCachePath.pathString], packagePath: path)) { error in + await XCTAssertAsyncThrowsError( + try await executeSwiftBuild( + path, + extraArgs: ["--cache-path", customCachePath.pathString], + buildSystem: .native, + ) + ) { error in guard case SwiftPMError.executionFailure(_, _, let stderr) = error else { return XCTFail("invalid error \(error)") } - XCTAssert(stderr.contains("error: You don’t have permission"), "expected permissions error") + XCTAssert(stderr.contains("error: You don’t have permission"), "expected permissions error. stderr: '\(stderr)'") } XCTAssertNoSuchPath(customCachePath) } @@ -557,7 +697,11 @@ final class MiscellaneousTestCase: XCTestCase { try await fixtureXCTest(name: "Miscellaneous/Simple") { path in let customConfigPath = path.appending(components: "custom", "config") XCTAssertNoSuchPath(customConfigPath) - try await SwiftPM.Build.execute(["--config-path", customConfigPath.pathString], packagePath: path) + try await executeSwiftBuild( + path, + extraArgs: ["--config-path", customConfigPath.pathString], + buildSystem: .native, + ) XCTAssertDirectoryExists(customConfigPath) } @@ -567,11 +711,17 @@ final class MiscellaneousTestCase: XCTestCase { try localFileSystem.chmod(.userUnWritable, path: path) let customConfigPath = path.appending(components: "custom", "config") XCTAssertNoSuchPath(customConfigPath) - await XCTAssertAsyncThrowsError(try await SwiftPM.Build.execute(["--config-path", customConfigPath.pathString], packagePath: path)) { error in + await XCTAssertAsyncThrowsError( + try await executeSwiftBuild( + path, + extraArgs: ["--config-path", customConfigPath.pathString], + buildSystem: .native, + ) + ) { error in guard case SwiftPMError.executionFailure(_, _, let stderr) = error else { return XCTFail("invalid error \(error)") } - XCTAssert(stderr.contains("error: You don’t have permission"), "expected permissions error") + XCTAssert(stderr.contains("error: You don’t have permission"), "expected permissions error. stderr: '\(stderr)'") } XCTAssertNoSuchPath(customConfigPath) } @@ -582,7 +732,11 @@ final class MiscellaneousTestCase: XCTestCase { try await fixtureXCTest(name: "Miscellaneous/Simple") { path in let customSecurityPath = path.appending(components: "custom", "security") XCTAssertNoSuchPath(customSecurityPath) - try await SwiftPM.Build.execute(["--security-path", customSecurityPath.pathString], packagePath: path) + try await executeSwiftBuild( + path, + extraArgs: ["--security-path", customSecurityPath.pathString], + buildSystem: .native, + ) XCTAssertDirectoryExists(customSecurityPath) } @@ -592,11 +746,17 @@ final class MiscellaneousTestCase: XCTestCase { try localFileSystem.chmod(.userUnWritable, path: path) let customSecurityPath = path.appending(components: "custom", "security") XCTAssertNoSuchPath(customSecurityPath) - await XCTAssertAsyncThrowsError(try await SwiftPM.Build.execute(["--security-path", customSecurityPath.pathString], packagePath: path)) { error in + await XCTAssertAsyncThrowsError( + try await executeSwiftBuild( + path, + extraArgs: ["--security-path", customSecurityPath.pathString], + buildSystem: .native, + ) + ) { error in guard case SwiftPMError.executionFailure(_, _, let stderr) = error else { return XCTFail("invalid error \(error)") } - XCTAssert(stderr.contains("error: You don’t have permission"), "expected permissions error") + XCTAssert(stderr.contains("error: You don’t have permission"), "expected permissions error. stderr: '\(stderr)'") } } #endif @@ -613,7 +773,11 @@ final class MiscellaneousTestCase: XCTestCase { ) try await fixtureXCTest(name: "Miscellaneous/PluginGeneratedResources") { path in - let result = try await SwiftPM.Run.execute(packagePath: path) + let result = try await executeSwiftRun( + path, + nil, + buildSystem: .native, + ) XCTAssertEqual(result.stdout, "Hello, World!\n", "executable did not produce expected output") XCTAssertTrue(result.stderr.contains("Copying best.txt\n"), "build log is missing message about copying resource file") } @@ -621,20 +785,29 @@ final class MiscellaneousTestCase: XCTestCase { func testCompileCXX17CrashWithFModules() async throws { try await fixtureXCTest(name: "Miscellaneous/CXX17CompilerCrash/v5_8") { fixturePath in - await XCTAssertBuilds(fixturePath) + await XCTAssertBuilds( + fixturePath, + buildSystem: .native, + ) } } func testNoJSONOutputWithFlatPackageStructure() async throws { try await fixtureXCTest(name: "Miscellaneous/FlatPackage") { package in // First build, make sure we got the `.build` directory where we expect it, and that there is no JSON output (by looking for known output). - let (stdout1, stderr1) = try await SwiftPM.Build.execute(packagePath: package) + let (stdout1, stderr1) = try await executeSwiftBuild( + package, + buildSystem: .native, + ) XCTAssertDirectoryExists(package.appending(".build")) XCTAssertNoMatch(stdout1, .contains("command_arguments")) XCTAssertNoMatch(stderr1, .contains("command_arguments")) // Now test, make sure we got the `.build` directory where we expect it, and that there is no JSON output (by looking for known output). - let (stdout2, stderr2) = try await SwiftPM.Test.execute(packagePath: package) + let (stdout2, stderr2) = try await executeSwiftTest( + package, + buildSystem: .native, + ) XCTAssertDirectoryExists(package.appending(".build")) XCTAssertNoMatch(stdout2, .contains("command_arguments")) XCTAssertNoMatch(stderr2, .contains("command_arguments")) @@ -650,7 +823,10 @@ final class MiscellaneousTestCase: XCTestCase { initGitRepo(dependency2Path, tag: "1.0.0") let appPath = path.appending("app") - let (stdout, stderr) = try await SwiftPM.Build.execute(packagePath: appPath) + let (stdout, stderr) = try await executeSwiftBuild( + appPath, + buildSystem: .native, + ) XCTAssertDirectoryExists(appPath.appending(".build")) XCTAssertMatch(stdout + stderr, .contains("'DeprecatedApp' is deprecated")) XCTAssertNoMatch(stdout + stderr, .contains("'Deprecated1' is deprecated")) @@ -667,7 +843,11 @@ final class MiscellaneousTestCase: XCTestCase { initGitRepo(dependency2Path, tag: "1.0.0") let appPath = path.appending("app") - let (stdout, stderr) = try await SwiftPM.Build.execute(["-Xswiftc", "-warnings-as-errors"], packagePath: appPath) + let (stdout, stderr) = try await executeSwiftBuild( + appPath, + Xswiftc: ["-warnings-as-errors"], + buildSystem: .native, + ) XCTAssertDirectoryExists(appPath.appending(".build")) XCTAssertNoMatch(stdout + stderr, .contains("'Deprecated1' is deprecated")) XCTAssertNoMatch(stdout + stderr, .contains("'Deprecated2' is deprecated")) @@ -676,7 +856,11 @@ final class MiscellaneousTestCase: XCTestCase { func testRootPackageWithConditionals() async throws { try await fixtureXCTest(name: "Miscellaneous/RootPackageWithConditionals") { path in - let (_, stderr) = try await SwiftPM.Build.execute(packagePath: path, env: ["SWIFT_DRIVER_SWIFTSCAN_LIB" : "/this/is/a/bad/path"]) + let (_, stderr) = try await executeSwiftBuild( + path, + env: ["SWIFT_DRIVER_SWIFTSCAN_LIB" : "/this/is/a/bad/path"], + buildSystem: .native, + ) let errors = stderr.components(separatedBy: .newlines).filter { !$0.contains("[logging] misuse") && !$0.isEmpty } .filter { !$0.contains("Unable to locate libSwiftScan") } XCTAssertEqual(errors, [], "unexpected errors: \(errors)") @@ -691,7 +875,12 @@ final class MiscellaneousTestCase: XCTestCase { } #endif try await fixtureXCTest(name: "Miscellaneous/RootPackageWithConditionals") { path in - _ = try await SwiftPM.Build.execute(["--build-system=swiftbuild"], packagePath: path, env: ["SWIFT_DRIVER_SWIFTSCAN_LIB" : "/this/is/a/bad/path"]) + _ = try await executeSwiftBuild( + path, + extraArgs: ["--build-system=swiftbuild"], + env: ["SWIFT_DRIVER_SWIFTSCAN_LIB" : "/this/is/a/bad/path"], + buildSystem: .native, + ) } } } diff --git a/Tests/FunctionalTests/ModuleAliasingFixtureTests.swift b/Tests/FunctionalTests/ModuleAliasingFixtureTests.swift index 1a1afd2d370..d6eb8cf655a 100644 --- a/Tests/FunctionalTests/ModuleAliasingFixtureTests.swift +++ b/Tests/FunctionalTests/ModuleAliasingFixtureTests.swift @@ -22,11 +22,18 @@ final class ModuleAliasingFixtureTests: XCTestCase { try await fixtureXCTest(name: "ModuleAliasing/DirectDeps1") { fixturePath in let pkgPath = fixturePath.appending(components: "AppPkg") let buildPath = pkgPath.appending(components: ".build", try UserToolchain.default.targetTriple.platformBuildPathComponent, "debug") - await XCTAssertBuilds(pkgPath, extraArgs: ["--vv"]) + await XCTAssertBuilds( + pkgPath, + extraArgs: ["--vv"], + buildSystem: .native, + ) XCTAssertFileExists(buildPath.appending(components: executableName("App"))) XCTAssertFileExists(buildPath.appending(components: "Modules", "GameUtils.swiftmodule")) XCTAssertFileExists(buildPath.appending(components: "Modules", "Utils.swiftmodule")) - _ = try await SwiftPM.Build.execute(packagePath: pkgPath) + _ = try await executeSwiftBuild( + pkgPath, + buildSystem: .native, + ) } } @@ -34,11 +41,18 @@ final class ModuleAliasingFixtureTests: XCTestCase { try await fixtureXCTest(name: "ModuleAliasing/DirectDeps2") { fixturePath in let pkgPath = fixturePath.appending(components: "AppPkg") let buildPath = pkgPath.appending(components: ".build", try UserToolchain.default.targetTriple.platformBuildPathComponent, "debug") - await XCTAssertBuilds(pkgPath, extraArgs: ["--vv"]) + await XCTAssertBuilds( + pkgPath, + extraArgs: ["--vv"], + buildSystem: .native, + ) XCTAssertFileExists(buildPath.appending(components: executableName("App"))) XCTAssertFileExists(buildPath.appending(components: "Modules", "AUtils.swiftmodule")) XCTAssertFileExists(buildPath.appending(components: "Modules", "BUtils.swiftmodule")) - _ = try await SwiftPM.Build.execute(packagePath: pkgPath) + _ = try await executeSwiftBuild( + pkgPath, + buildSystem: .native, + ) } } @@ -46,7 +60,11 @@ final class ModuleAliasingFixtureTests: XCTestCase { try await fixtureXCTest(name: "ModuleAliasing/NestedDeps1") { fixturePath in let pkgPath = fixturePath.appending(components: "AppPkg") let buildPath = pkgPath.appending(components: ".build", try UserToolchain.default.targetTriple.platformBuildPathComponent, "debug") - await XCTAssertBuilds(pkgPath, extraArgs: ["--vv"]) + await XCTAssertBuilds( + pkgPath, + extraArgs: ["--vv"], + buildSystem: .native, + ) XCTAssertFileExists(buildPath.appending(components: executableName("App"))) XCTAssertFileExists(buildPath.appending(components: "Modules", "A.swiftmodule")) XCTAssertFileExists(buildPath.appending(components: "Modules", "AFooUtils.swiftmodule")) @@ -54,7 +72,10 @@ final class ModuleAliasingFixtureTests: XCTestCase { XCTAssertFileExists(buildPath.appending(components: "Modules", "X.swiftmodule")) XCTAssertFileExists(buildPath.appending(components: "Modules", "XFooUtils.swiftmodule")) XCTAssertFileExists(buildPath.appending(components: "Modules", "XUtils.swiftmodule")) - _ = try await SwiftPM.Build.execute(packagePath: pkgPath) + _ = try await executeSwiftBuild( + pkgPath, + buildSystem: .native, + ) } } @@ -62,13 +83,20 @@ final class ModuleAliasingFixtureTests: XCTestCase { try await fixtureXCTest(name: "ModuleAliasing/NestedDeps2") { fixturePath in let pkgPath = fixturePath.appending(components: "AppPkg") let buildPath = pkgPath.appending(components: ".build", try UserToolchain.default.targetTriple.platformBuildPathComponent, "debug") - await XCTAssertBuilds(pkgPath, extraArgs: ["--vv"]) + await XCTAssertBuilds( + pkgPath, + extraArgs: ["--vv"], + buildSystem: .native, + ) XCTAssertFileExists(buildPath.appending(components: executableName("App"))) XCTAssertFileExists(buildPath.appending(components: "Modules", "A.swiftmodule")) XCTAssertFileExists(buildPath.appending(components: "Modules", "BUtils.swiftmodule")) XCTAssertFileExists(buildPath.appending(components: "Modules", "CUtils.swiftmodule")) XCTAssertFileExists(buildPath.appending(components: "Modules", "XUtils.swiftmodule")) - _ = try await SwiftPM.Build.execute(packagePath: pkgPath) + _ = try await executeSwiftBuild( + pkgPath, + buildSystem: .native, + ) } } } diff --git a/Tests/FunctionalTests/ModuleMapTests.swift b/Tests/FunctionalTests/ModuleMapTests.swift index e209363a0b7..aed18490fe2 100644 --- a/Tests/FunctionalTests/ModuleMapTests.swift +++ b/Tests/FunctionalTests/ModuleMapTests.swift @@ -44,7 +44,11 @@ final class ModuleMapsTestCase: XCTestCase { func testDirectDependency() async throws { try XCTSkipOnWindows(because: "fails to build on windows (maybe not supported?)") try await fixtureXCTest(name: "ModuleMaps/Direct", cModuleName: "CFoo", rootpkg: "App") { fixturePath, Xld in - await XCTAssertBuilds(fixturePath.appending("App"), Xld: Xld) + await XCTAssertBuilds( + fixturePath.appending("App"), + Xld: Xld, + buildSystem: .native, + ) let triple = try UserToolchain.default.targetTriple let targetPath = fixturePath.appending(components: "App", ".build", triple.platformBuildPathComponent) @@ -62,7 +66,11 @@ final class ModuleMapsTestCase: XCTestCase { func testTransitiveDependency() async throws { try XCTSkipOnWindows(because: "fails to build on windows (maybe not supported?)") try await fixtureXCTest(name: "ModuleMaps/Transitive", cModuleName: "packageD", rootpkg: "packageA") { fixturePath, Xld in - await XCTAssertBuilds(fixturePath.appending("packageA"), Xld: Xld) + await XCTAssertBuilds( + fixturePath.appending("packageA"), + Xld: Xld, + buildSystem: .native, + ) func verify(_ conf: String) async throws { let triple = try UserToolchain.default.targetTriple diff --git a/Tests/FunctionalTests/PluginTests.swift b/Tests/FunctionalTests/PluginTests.swift index 4dd087889d3..94261adaa42 100644 --- a/Tests/FunctionalTests/PluginTests.swift +++ b/Tests/FunctionalTests/PluginTests.swift @@ -28,12 +28,17 @@ final class PluginTests { @Test( .bug("https://github.com/swiftlang/swift-package-manager/issues/8602"), .bug("https://github.com/swiftlang/swift-package-manager/issues/8791"), - .enabled(if: (try? UserToolchain.default)!.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency") + .requiresSwiftConcurrencySupport, ) func testUseOfBuildToolPluginTargetByExecutableInSamePackage() async throws { try await withKnownIssue { 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"], + buildSystem: .native, + ) #expect(stdout.contains("Linking MySourceGenBuildTool"), "stdout:\n\(stdout)") #expect(stdout.contains("Generating foo.swift from foo.dat"), "stdout:\n\(stdout)") #expect(stdout.contains("Linking MyLocalTool"), "stdout:\n\(stdout)") @@ -46,7 +51,12 @@ final class PluginTests { try await withKnownIssue { // Try again with the Swift Build build system try await fixture(name: "Miscellaneous/Plugins") { fixturePath in - let (stdout, _) = try await executeSwiftBuild(fixturePath.appending("MySourceGenPlugin"), configuration: .debug, extraArgs: ["--product", "MyLocalTool", "--build-system", "swiftbuild"]) + let (stdout, _) = try await executeSwiftBuild( + fixturePath.appending("MySourceGenPlugin"), + configuration: .debug, + extraArgs: ["--product", "MyLocalTool", "--build-system", "swiftbuild"], + buildSystem: .native, + ) #expect(stdout.contains("Build complete!"), "stdout:\n\(stdout)") } } when: { ProcessInfo.hostOperatingSystem == .linux || ProcessInfo.hostOperatingSystem == .windows } @@ -55,12 +65,15 @@ final class PluginTests { @Test( .bug("https://github.com/swiftlang/swift-package-manager/issues/8602"), .bug("https://github.com/swiftlang/swift-package-manager/issues/8786"), - .enabled(if: (try? UserToolchain.default)!.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency") + .requiresSwiftConcurrencySupport, ) func testUseOfBuildToolPluginTargetNoPreBuildCommands() async throws { try await withKnownIssue { try await fixture(name: "Miscellaneous/Plugins") { fixturePath in - let (_, stderr) = try await executeSwiftTest(fixturePath.appending("MySourceGenPluginNoPreBuildCommands")) + let (_, stderr) = try await executeSwiftTest( + fixturePath.appending("MySourceGenPluginNoPreBuildCommands"), + buildSystem: .native, + ) #expect(stderr.contains("file(s) which are unhandled; explicitly declare them as resources or exclude from the target"), "expected warning not emitted") } } when: { @@ -70,7 +83,11 @@ final class PluginTests { // Try again with the Swift Build build system await withKnownIssue { try await fixture(name: "Miscellaneous/Plugins") { fixturePath in - let (_, stderr) = try await executeSwiftTest(fixturePath.appending("MySourceGenPluginNoPreBuildCommands"), extraArgs: ["--build-system", "swiftbuild"]) + let (_, stderr) = try await executeSwiftTest( + fixturePath.appending("MySourceGenPluginNoPreBuildCommands"), + extraArgs: ["--build-system", "swiftbuild"], + buildSystem: .native, + ) #expect(stderr.contains("file(s) which are unhandled; explicitly declare them as resources or exclude from the target"), "expected warning not emitted") } } @@ -79,12 +96,17 @@ final class PluginTests { @Test( .bug("https://github.com/swiftlang/swift-package-manager/issues/8602"), .bug("https://github.com/swiftlang/swift-package-manager/issues/8774"), - .enabled(if: (try? UserToolchain.default)!.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency") + .requiresSwiftConcurrencySupport, ) func testUseOfBuildToolPluginProductByExecutableAcrossPackages() async throws { try await withKnownIssue { 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"], + buildSystem: .native, + ) #expect(stdout.contains("Linking MySourceGenBuildTool"), "stdout:\n\(stdout)") #expect(stdout.contains("Generating foo.swift from foo.dat"), "stdout:\n\(stdout)") #expect(stdout.contains("Linking MyTool"), "stdout:\n\(stdout)") @@ -97,7 +119,12 @@ final class PluginTests { try await withKnownIssue { // Try again with the Swift Build build system try await fixture(name: "Miscellaneous/Plugins") { fixturePath in - let (stdout, _) = try await executeSwiftBuild(fixturePath.appending("MySourceGenClient"), configuration: .debug, extraArgs: ["--build-system", "swiftbuild", "--product", "MyTool"]) + let (stdout, _) = try await executeSwiftBuild( + fixturePath.appending("MySourceGenClient"), + configuration: .debug, + extraArgs: ["--build-system", "swiftbuild", "--product", "MyTool"], + buildSystem: .native, + ) #expect(stdout.contains("Build complete!"), "stdout:\n\(stdout)") } } when: { @@ -108,12 +135,17 @@ final class PluginTests { @Test( .bug("https://github.com/swiftlang/swift-package-manager/issues/8602"), .bug("https://github.com/swiftlang/swift-package-manager/issues/8774"), - .enabled(if: (try? UserToolchain.default)!.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency") + .requiresSwiftConcurrencySupport, ) func testUseOfPrebuildPluginTargetByExecutableAcrossPackages() async throws { try await withKnownIssue { 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"], + buildSystem: .native, + ) #expect(stdout.contains("Compiling MyOtherLocalTool bar.swift"), "stdout:\n\(stdout)") #expect(stdout.contains("Compiling MyOtherLocalTool baz.swift"), "stdout:\n\(stdout)") #expect(stdout.contains("Linking MyOtherLocalTool"), "stdout:\n\(stdout)") @@ -126,7 +158,12 @@ final class PluginTests { try await withKnownIssue { // Try again with the Swift Build build system try await fixture(name: "Miscellaneous/Plugins") { fixturePath in - let (stdout, _) = try await executeSwiftBuild(fixturePath.appending("MySourceGenPlugin"), configuration: .debug, extraArgs: ["--build-system", "swiftbuild", "--product", "MyOtherLocalTool"]) + let (stdout, _) = try await executeSwiftBuild( + fixturePath.appending("MySourceGenPlugin"), + configuration: .debug, + extraArgs: ["--build-system", "swiftbuild", "--product", "MyOtherLocalTool"], + buildSystem: .native, + ) #expect(stdout.contains("Build complete!"), "stdout:\n\(stdout)") } } when: { @@ -137,12 +174,15 @@ final class PluginTests { @Test( .bug("https://github.com/swiftlang/swift-package-manager/issues/8602"), .bug("https://github.com/swiftlang/swift-package-manager/issues/8774"), - .enabled(if: (try? UserToolchain.default)!.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency") + .requiresSwiftConcurrencySupport, ) func testUseOfPluginWithInternalExecutable() async throws { try await withKnownIssue { try await fixture(name: "Miscellaneous/Plugins") { fixturePath in - let (stdout, _) = try await executeSwiftBuild(fixturePath.appending("ClientOfPluginWithInternalExecutable")) + let (stdout, _) = try await executeSwiftBuild( + fixturePath.appending("ClientOfPluginWithInternalExecutable"), + buildSystem: .native, + ) #expect(stdout.contains("Compiling PluginExecutable main.swift"), "stdout:\n\(stdout)") #expect(stdout.contains("Linking PluginExecutable"), "stdout:\n\(stdout)") #expect(stdout.contains("Generating foo.swift from foo.dat"), "stdout:\n\(stdout)") @@ -153,7 +193,11 @@ final class PluginTests { // Try again with the Swift Build build system try await fixture(name: "Miscellaneous/Plugins") { fixturePath in - let (stdout, _) = try await executeSwiftBuild(fixturePath.appending("ClientOfPluginWithInternalExecutable"), extraArgs: ["--build-system", "swiftbuild"]) + let (stdout, _) = try await executeSwiftBuild( + fixturePath.appending("ClientOfPluginWithInternalExecutable"), + extraArgs: ["--build-system", "swiftbuild"], + buildSystem: .native, + ) #expect(stdout.contains("Build complete!"), "stdout:\n\(stdout)") } } when: { @@ -162,12 +206,15 @@ final class PluginTests { } @Test( - .enabled(if: (try? UserToolchain.default)!.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency") + .requiresSwiftConcurrencySupport, ) func testInternalExecutableAvailableOnlyToPlugin() async throws { try await fixture(name: "Miscellaneous/Plugins") { fixturePath in let error = try await #require(throws: SwiftPMError.self, "Illegally used internal executable") { - try await executeSwiftBuild(fixturePath.appending("InvalidUseOfInternalPluginExecutable")) + try await executeSwiftBuild( + fixturePath.appending("InvalidUseOfInternalPluginExecutable"), + buildSystem: .native, + ) } guard case SwiftPMError.executionFailure(_, _, let stderr) = error else { @@ -182,7 +229,10 @@ final class PluginTests { try await fixture(name: "Miscellaneous/Plugins") { fixturePath in let error = try await #require(throws: SwiftPMError.self, "Illegally used internal executable") { - try await executeSwiftBuild(fixturePath.appending("InvalidUseOfInternalPluginExecutable")) + try await executeSwiftBuild( + fixturePath.appending("InvalidUseOfInternalPluginExecutable"), + buildSystem: .native, + ) } guard case SwiftPMError.executionFailure(_, _, _) = error else { @@ -195,12 +245,15 @@ final class PluginTests { @Test( .bug("https://github.com/swiftlang/swift-package-manager/issues/8602"), .bug("https://github.com/swiftlang/swift-package-manager/issues/8774"), - .enabled(if: (try? UserToolchain.default)!.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency") + .requiresSwiftConcurrencySupport, ) func testLocalBuildToolPluginUsingRemoteExecutable() async throws { try await withKnownIssue { try await fixture(name: "Miscellaneous/Plugins") { fixturePath in - let (stdout, _) = try await executeSwiftBuild(fixturePath.appending("LibraryWithLocalBuildToolPluginUsingRemoteTool")) + let (stdout, _) = try await executeSwiftBuild( + fixturePath.appending("LibraryWithLocalBuildToolPluginUsingRemoteTool"), + buildSystem: .native, + ) #expect(stdout.contains("Compiling MySourceGenBuildTool main.swift"), "stdout:\n\(stdout)") #expect(stdout.contains("Linking MySourceGenBuildTool"), "stdout:\n\(stdout)") #expect(stdout.contains("Generating generated.swift from generated.dat"), "stdout:\n\(stdout)") @@ -214,7 +267,11 @@ final class PluginTests { try await withKnownIssue { // Try again with the Swift Build build system try await fixture(name: "Miscellaneous/Plugins") { fixturePath in - let (stdout, _) = try await executeSwiftBuild(fixturePath.appending("LibraryWithLocalBuildToolPluginUsingRemoteTool"), extraArgs: ["--build-system", "swiftbuild"]) + let (stdout, _) = try await executeSwiftBuild( + fixturePath.appending("LibraryWithLocalBuildToolPluginUsingRemoteTool"), + extraArgs: ["--build-system", "swiftbuild"], + buildSystem: .native, + ) #expect(stdout.contains("Build complete!"), "stdout:\n\(stdout)") } } when: { @@ -226,12 +283,15 @@ final class PluginTests { .bug("https://github.com/swiftlang/swift-package-manager/issues/8602"), .bug("https://github.com/swiftlang/swift-package-manager/issues/8774"), .bug("https://github.com/swiftlang/swift-package-manager/issues/8791"), - .enabled(if: (try? UserToolchain.default)!.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency") + .requiresSwiftConcurrencySupport, ) func testBuildToolPluginDependencies() async throws { try await withKnownIssue { try await fixture(name: "Miscellaneous/Plugins") { fixturePath in - let (stdout, _) = try await executeSwiftBuild(fixturePath.appending("MyBuildToolPluginDependencies")) + let (stdout, _) = try await executeSwiftBuild( + fixturePath.appending("MyBuildToolPluginDependencies"), + buildSystem: .native, + ) #expect(stdout.contains("Compiling MySourceGenBuildTool main.swift"), "stdout:\n\(stdout)") #expect(stdout.contains("Linking MySourceGenBuildTool"), "stdout:\n\(stdout)") #expect(stdout.contains("Generating foo.swift from foo.dat"), "stdout:\n\(stdout)") @@ -245,7 +305,11 @@ final class PluginTests { try await withKnownIssue { // Try again with the Swift Build build system try await fixture(name: "Miscellaneous/Plugins") { fixturePath in - let (stdout, _) = try await executeSwiftBuild(fixturePath.appending("MyBuildToolPluginDependencies"), extraArgs: ["--build-system", "swiftbuild"]) + let (stdout, _) = try await executeSwiftBuild( + fixturePath.appending("MyBuildToolPluginDependencies"), + extraArgs: ["--build-system", "swiftbuild"], + buildSystem: .native, + ) #expect(stdout.contains("Build complete!"), "stdout:\n\(stdout)") } } when: { ProcessInfo.hostOperatingSystem == .windows || ProcessInfo.hostOperatingSystem == .linux } @@ -254,12 +318,17 @@ final class PluginTests { @Test( .bug("https://github.com/swiftlang/swift-package-manager/issues/8602"), .bug("https://github.com/swiftlang/swift-package-manager/issues/8774"), - .enabled(if: (try? UserToolchain.default)!.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency") + .requiresSwiftConcurrencySupport, ) func testContrivedTestCases() async throws { try await withKnownIssue { 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"], + buildSystem: .native, + ) #expect(stdout.contains("Linking MySourceGenBuildTool"), "stdout:\n\(stdout)") #expect(stdout.contains("Generating foo.swift from foo.dat"), "stdout:\n\(stdout)") #expect(stdout.contains("Linking MyLocalTool"), "stdout:\n\(stdout)") @@ -271,7 +340,12 @@ final class PluginTests { try await withKnownIssue { try await fixture(name: "Miscellaneous/Plugins") { fixturePath in - let (stdout, _) = try await executeSwiftBuild(fixturePath.appending("ContrivedTestPlugin"), configuration: .debug, extraArgs: ["--build-system", "swiftbuild", "--product", "MyLocalTool", "--disable-sandbox"]) + let (stdout, _) = try await executeSwiftBuild( + fixturePath.appending("ContrivedTestPlugin"), + configuration: .debug, + extraArgs: ["--build-system", "swiftbuild", "--product", "MyLocalTool", "--disable-sandbox"], + buildSystem: .native, + ) #expect(stdout.contains("Build complete!"), "stdout:\n\(stdout)") } } when: { @@ -280,31 +354,46 @@ final class PluginTests { } @Test( - .enabled(if: (try? UserToolchain.default)!.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency"), + .requiresSwiftConcurrencySupport, .enabled(if: ProcessInfo.hostOperatingSystem == .macOS, "Test is only supported on macOS") ) func testPluginScriptSandbox() async throws { 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"], + buildSystem: .native, + ) #expect(stdout.contains("Linking MyLocalTool"), "stdout:\n\(stdout)") #expect(stdout.contains("Build of product 'MyLocalTool' complete!"), "stdout:\n\(stdout)") } // Try again with Swift Build build system try await fixture(name: "Miscellaneous/Plugins") { fixturePath in - let (stdout, _) = try await executeSwiftBuild(fixturePath.appending("SandboxTesterPlugin"), configuration: .debug, extraArgs: ["--build-system", "swiftbuild", "--product", "MyLocalTool"]) + let (stdout, _) = try await executeSwiftBuild( + fixturePath.appending("SandboxTesterPlugin"), + configuration: .debug, + extraArgs: ["--build-system", "swiftbuild", "--product", "MyLocalTool"], + buildSystem: .native, + ) #expect(stdout.contains("Build complete!"), "stdout:\n\(stdout)") } } @Test( - .enabled(if: (try? UserToolchain.default)!.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency"), + .requiresSwiftConcurrencySupport, .enabled(if: ProcessInfo.hostOperatingSystem == .macOS, "Test is only supported on macOS"), arguments: [BuildSystemProvider.Kind.native, .swiftbuild] ) func testUseOfVendedBinaryTool(buildSystem: BuildSystemProvider.Kind) async throws { try await fixture(name: "Miscellaneous/Plugins") { fixturePath in - let (stdout, _) = try await executeSwiftBuild(fixturePath.appending("MyBinaryToolPlugin"), configuration: .debug, extraArgs: ["--product", "MyLocalTool"], buildSystem: buildSystem) + let (stdout, _) = try await executeSwiftBuild( + fixturePath.appending("MyBinaryToolPlugin"), + configuration: .debug, + extraArgs: ["--product", "MyLocalTool"], + buildSystem: buildSystem, + ) if buildSystem == .native { #expect(stdout.contains("Linking MyLocalTool"), "stdout:\n\(stdout)") #expect(stdout.contains("Build of product 'MyLocalTool' complete!"), "stdout:\n(stdout)") @@ -317,12 +406,17 @@ final class PluginTests { } @Test( - .enabled(if: (try? UserToolchain.default)!.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency"), + .requiresSwiftConcurrencySupport, .enabled(if: ProcessInfo.hostOperatingSystem == .macOS, "Test is only supported on macOS") ) func testUseOfBinaryToolVendedAsProduct() async throws { 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"], + buildSystem: .native, + ) #expect(stdout.contains("Linking MyLocalTool"), "stdout:\n\(stdout)") #expect(stdout.contains("Build of product 'MyLocalTool' complete!"), "stdout:\n\(stdout)") } @@ -331,9 +425,12 @@ final class PluginTests { @Test( .bug("https://github.com/swiftlang/swift-package-manager/issues/8794"), .bug("https://github.com/swiftlang/swift-package-manager/issues/8602"), - .enabled(if: (try? UserToolchain.default)!.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency"), + .requiresSwiftConcurrencySupport, + arguments: SupportedBuildSystemOnAllPlatforms, ) - func testBuildToolWithoutOutputs() async throws { + func testBuildToolWithoutOutputs( + buildSystem: BuildSystemProvider.Kind, + ) async throws { func createPackageUnderTest(packageDir: AbsolutePath, toolsVersion: ToolsVersion) throws { let manifestFile = packageDir.appending("Package.swift") try localFileSystem.createDirectory(manifestFile.parentDirectory, recursive: true) @@ -381,33 +478,39 @@ final class PluginTests { } try await withKnownIssue { - for buildSystem in ["native", "swiftbuild"] { - try await testWithTemporaryDirectory { tmpPath in - let packageDir = tmpPath.appending(components: "MyPackage") - let pathOfGeneratedFile = packageDir.appending(components: [".build", "plugins", "outputs", "mypackage", "SomeTarget", "destination", "Plugin", "best.txt"]) - - try await withKnownIssue { - try createPackageUnderTest(packageDir: packageDir, toolsVersion: .v5_9) - let (_, stderr) = try await executeSwiftBuild(packageDir, extraArgs: ["--build-system", buildSystem], env: ["SWIFT_DRIVER_SWIFTSCAN_LIB" : "/this/is/a/bad/path"]) - #expect(stderr.contains("warning: Build tool command 'empty' (applied to target 'SomeTarget') does not declare any output files"), "expected warning not emitted") - #expect(!localFileSystem.exists(pathOfGeneratedFile), "plugin generated file unexpectedly exists at \(pathOfGeneratedFile.pathString)") - } when: { - buildSystem == "swiftbuild" - } - - try createPackageUnderTest(packageDir: packageDir, toolsVersion: .v6_0) - let (stdout, stderr2) = try await executeSwiftBuild(packageDir, extraArgs: ["--build-system", buildSystem], env: ["SWIFT_DRIVER_SWIFTSCAN_LIB" : "/this/is/a/bad/path"]) - #expect(stdout.contains("Build complete!")) - #expect(!stderr2.contains("error:")) - #expect(localFileSystem.exists(pathOfGeneratedFile), "plugin did not run, generated file does not exist at \(pathOfGeneratedFile.pathString)") + try await testWithTemporaryDirectory { tmpPath in + let packageDir = tmpPath.appending(components: "MyPackage") + let pathOfGeneratedFile = packageDir.appending(components: [".build", "plugins", "outputs", "mypackage", "SomeTarget", "destination", "Plugin", "best.txt"]) + + try await withKnownIssue { + try createPackageUnderTest(packageDir: packageDir, toolsVersion: .v5_9) + let (_, stderr) = try await executeSwiftBuild( + packageDir, + env: ["SWIFT_DRIVER_SWIFTSCAN_LIB" : "/this/is/a/bad/path"], + buildSystem: buildSystem, + ) + #expect(stderr.contains("warning: Build tool command 'empty' (applied to target 'SomeTarget') does not declare any output files"), "expected warning not emitted") + #expect(!localFileSystem.exists(pathOfGeneratedFile), "plugin generated file unexpectedly exists at \(pathOfGeneratedFile.pathString)") + } when: { + buildSystem == .swiftbuild } + + try createPackageUnderTest(packageDir: packageDir, toolsVersion: .v6_0) + let (stdout, stderr2) = try await executeSwiftBuild( + packageDir, + env: ["SWIFT_DRIVER_SWIFTSCAN_LIB" : "/this/is/a/bad/path"], + buildSystem: buildSystem, + ) + #expect(stdout.contains("Build complete!")) + #expect(!stderr2.contains("error:")) + #expect(localFileSystem.exists(pathOfGeneratedFile), "plugin did not run, generated file does not exist at \(pathOfGeneratedFile.pathString)") } } when: { ProcessInfo.hostOperatingSystem == .windows } } @Test( .bug("rdar://117870608"), - .enabled(if: (try? UserToolchain.default)!.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency"), + .requiresSwiftConcurrencySupport, .disabled() ) func testCommandPluginInvocation() async throws { @@ -760,13 +863,18 @@ final class PluginTests { @Test( .bug("https://github.com/swiftlang/swift-package-manager/issues/8602"), - .enabled(if: (try? UserToolchain.default)!.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency"), + .requiresSwiftConcurrencySupport, arguments: [BuildSystemProvider.Kind.native, .swiftbuild] ) func testLocalAndRemoteToolDependencies(buildSystem: BuildSystemProvider.Kind) async throws { try await withKnownIssue (isIntermittent: true) { try await fixture(name: "Miscellaneous/Plugins/PluginUsingLocalAndRemoteTool") { path in - let (stdout, stderr) = try await executeSwiftPackage(path.appending("MyLibrary"), configuration: .debug, extraArgs: ["--build-system", buildSystem.rawValue, "plugin", "my-plugin"]) + let (stdout, stderr) = try await executeSwiftPackage( + path.appending("MyLibrary"), + configuration: .debug, + extraArgs: ["plugin", "my-plugin"], + buildSystem: buildSystem, + ) if buildSystem == .native { // Native build system is more explicit about what it's doing in stderr #expect(stderr.contains("Linking RemoteTool"), "stdout:\n\(stderr)\n\(stdout)") @@ -784,7 +892,7 @@ final class PluginTests { } @Test( - .enabled(if: (try? UserToolchain.default)!.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency"), + .requiresSwiftConcurrencySupport, ) func testPluginUsageDoesntAffectTestTargetMappings() async throws { try await fixture(name: "Miscellaneous/Plugins/MySourceGenPlugin") { packageDir in @@ -822,7 +930,7 @@ final class PluginTests { @Test( .bug("rdar://88792829"), - .enabled(if: (try? UserToolchain.default)!.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency"), + .requiresSwiftConcurrencySupport, .disabled(if: ProcessInfo.hostOperatingSystem == .windows, "This hangs intermittently on windows in CI") ) func testCommandPluginCancellation() async throws { @@ -1238,35 +1346,53 @@ final class PluginTests { @Test( .bug("https://github.com/swiftlang/swift-package-manager/issues/8774"), .bug("https://github.com/swiftlang/swift-package-manager/issues/8602"), - .enabled(if: (try? UserToolchain.default)!.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency"), + .requiresSwiftConcurrencySupport, ) func testSnippetSupport() async throws { 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"], + buildSystem: .native, + ) #expect(stdout.contains("type of snippet target: snippet"), "output:\n\(stderr)\n\(stdout)") } // Try again with the Swift Build build system try await fixture(name: "Miscellaneous/Plugins") { path in - let (stdout, stderr) = try await executeSwiftPackage(path.appending("PluginsAndSnippets"), configuration: .debug, extraArgs: ["--build-system", "swiftbuild", "do-something"]) + let (stdout, stderr) = try await executeSwiftPackage( + path.appending("PluginsAndSnippets"), + configuration: .debug, + extraArgs: ["--build-system", "swiftbuild", "do-something"], + buildSystem: .native, + ) #expect(stdout.contains("type of snippet target: snippet"), "output:\n\(stderr)\n\(stdout)") } } @Test( .bug("https://github.com/swiftlang/swift-package-manager/issues/8774"), - .enabled(if: (try? UserToolchain.default)!.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency"), + .requiresSwiftConcurrencySupport, ) func testIncorrectDependencies() async throws { try await fixture(name: "Miscellaneous/Plugins") { path in - let (stdout, stderr) = try await executeSwiftBuild(path.appending("IncorrectDependencies"), extraArgs: ["--build-tests"]) + let (stdout, stderr) = try await executeSwiftBuild( + path.appending("IncorrectDependencies"), + extraArgs: ["--build-tests"], + buildSystem: .native, + ) #expect(stdout.contains("Build complete!"), "output:\n\(stderr)\n\(stdout)") } try await withKnownIssue (isIntermittent: true) { // Try again with the Swift Build build system try await fixture(name: "Miscellaneous/Plugins") { path in - let (stdout, stderr) = try await executeSwiftBuild(path.appending("IncorrectDependencies"), extraArgs: ["--build-system", "swiftbuild", "--build-tests"]) + let (stdout, stderr) = try await executeSwiftBuild( + path.appending("IncorrectDependencies"), + extraArgs: ["--build-tests"], + buildSystem: .swiftbuild, + ) #expect(stdout.contains("Build complete!"), "output:\n\(stderr)\n\(stdout)") } } when: { ProcessInfo.hostOperatingSystem == .windows || (ProcessInfo.hostOperatingSystem == .linux && CiEnvironment.runningInSmokeTestPipeline) } @@ -1274,48 +1400,69 @@ final class PluginTests { @Test( .enabled(if: ProcessInfo.hostOperatingSystem == .macOS, "sandboxing tests are only supported on macOS"), - .enabled(if: (try? UserToolchain.default)!.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency"), + .requiresSwiftConcurrencySupport, + arguments: [BuildSystemProvider.Kind.native], // FIXME: enable swiftbuild testing once pre-build plugins are working ) - func testSandboxViolatingBuildToolPluginCommands() async throws { - for buildSystem in [BuildSystemProvider.Kind.native] { // FIXME: enable swiftbuild testing once pre-build plugins are working - // Check that the build fails with a sandbox violation by default. - try await fixture(name: "Miscellaneous/Plugins/SandboxViolatingBuildToolPluginCommands") { path in - let error = try await #require(throws: Error.self) { - try await executeSwiftBuild(path.appending("MyLibrary"), configuration: .debug, buildSystem: buildSystem) - } - - #expect("\(error)".contains("You don’t have permission to save the file “generated” in the folder “MyLibrary”.")) + func testSandboxViolatingBuildToolPluginCommands( + buildSystem: BuildSystemProvider.Kind, + ) async throws { + // Check that the build fails with a sandbox violation by default. + try await fixture(name: "Miscellaneous/Plugins/SandboxViolatingBuildToolPluginCommands") { path in + let error = try await #require(throws: Error.self) { + try await executeSwiftBuild( + path.appending("MyLibrary"), + configuration: .debug, + buildSystem: buildSystem, + ) } - // 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"], buildSystem: buildSystem) - #expect(stdout.contains("Compiling MyLibrary foo.swift"), "[STDOUT]\n\(stdout)\n[STDERR]\n\(stderr)\n") - } + #expect("\(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"], + buildSystem: buildSystem, + ) + #expect(stdout.contains("Compiling MyLibrary foo.swift"), "[STDOUT]\n\(stdout)\n[STDERR]\n\(stderr)\n") } } - @Test(.enabled(if: ProcessInfo.hostOperatingSystem == .macOS, "sandboxing tests are only supported on macOS")) - func testBuildToolPluginSwiftFileExecutable() async throws { - for buildSystem in ["native", "swiftbuild"] { - try await fixture(name: "Miscellaneous/Plugins") { fixturePath in - let (stdout, stderr) = try await executeSwiftBuild(fixturePath.appending("SwiftFilePlugin"), configuration: .debug, extraArgs: ["--build-system", buildSystem, "--verbose"]) - if buildSystem == "native" { - #expect(stdout.contains("Hello, Build Tool Plugin!"), "stdout:\n\(stdout)") - } else { - #expect(stderr.contains("Hello, Build Tool Plugin!"), "stderr:\n\(stderr)") - } + @Test( + .enabled(if: ProcessInfo.hostOperatingSystem == .macOS, "sandboxing tests are only supported on macOS"), + arguments: SupportedBuildSystemOnAllPlatforms, + ) + func testBuildToolPluginSwiftFileExecutable( + buildSystem: BuildSystemProvider.Kind, + ) async throws { + try await fixture(name: "Miscellaneous/Plugins") { fixturePath in + let (stdout, stderr) = try await executeSwiftBuild( + fixturePath.appending("SwiftFilePlugin"), + configuration: .debug, + extraArgs: [ "--verbose"], + buildSystem: buildSystem, + ) + if buildSystem == .native { + #expect(stdout.contains("Hello, Build Tool Plugin!"), "stdout:\n\(stdout)") + } else { + #expect(stderr.contains("Hello, Build Tool Plugin!"), "stderr:\n\(stderr)") } } } @Test( .bug("https://github.com/swiftlang/swift-package-manager/issues/8774"), - .enabled(if: (try? UserToolchain.default)!.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency") + .requiresSwiftConcurrencySupport, ) func testTransitivePluginOnlyDependency() async throws { try await fixture(name: "Miscellaneous/Plugins") { fixturePath in - let (stdout, _) = try await executeSwiftBuild(fixturePath.appending("TransitivePluginOnlyDependency")) + let (stdout, _) = try await executeSwiftBuild( + fixturePath.appending("TransitivePluginOnlyDependency"), + buildSystem: .native, + ) #expect(stdout.contains("Compiling plugin MyPlugin"), "stdout:\n\(stdout)") #expect(stdout.contains("Compiling Library Library.swift"), "stdout:\n\(stdout)") #expect(stdout.contains("Build complete!"), "stdout:\n\(stdout)") @@ -1324,7 +1471,10 @@ final class PluginTests { try await withKnownIssue { // Try again with Swift Build build system try await fixture(name: "Miscellaneous/Plugins") { fixturePath in - let (stdout, _) = try await executeSwiftBuild(fixturePath.appending("TransitivePluginOnlyDependency"), extraArgs: ["--build-system", "swiftbuild"]) + let (stdout, _) = try await executeSwiftBuild( + fixturePath.appending("TransitivePluginOnlyDependency"), + buildSystem: .swiftbuild, + ) #expect(stdout.contains("Build complete!"), "stdout:\n\(stdout)") } } when: { @@ -1335,21 +1485,18 @@ final class PluginTests { @Test( .bug("https://github.com/swiftlang/swift-package-manager/issues/8774"), .bug("https://github.com/swiftlang/swift-package-manager/issues/8602"), - .enabled(if: (try? UserToolchain.default)!.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency") + .requiresSwiftConcurrencySupport, + arguments: SupportedBuildSystemOnAllPlatforms, ) - func testMissingPlugin() async throws { + func testMissingPlugin( + buildSystem: BuildSystemProvider.Kind, + ) async throws { try await fixture(name: "Miscellaneous/Plugins") { fixturePath in do { - try await executeSwiftBuild(fixturePath.appending("MissingPlugin")) - } catch SwiftPMError.executionFailure(_, _, let stderr) { - #expect(stderr.contains("error: 'missingplugin': no plugin named 'NonExistingPlugin' found"), "stderr:\n\(stderr)") - } - } - - // Try again with Swift Build build system - try await fixture(name: "Miscellaneous/Plugins") { fixturePath in - do { - try await executeSwiftBuild(fixturePath.appending("MissingPlugin"), extraArgs: ["--build-system", "swiftbuild"]) + try await executeSwiftBuild( + fixturePath.appending("MissingPlugin"), + buildSystem: buildSystem, + ) } catch SwiftPMError.executionFailure(_, _, let stderr) { #expect(stderr.contains("error: 'missingplugin': no plugin named 'NonExistingPlugin' found"), "stderr:\n\(stderr)") } @@ -1358,11 +1505,14 @@ final class PluginTests { @Test( .bug("https://github.com/swiftlang/swift-package-manager/issues/8774"), - .enabled(if: (try? UserToolchain.default)!.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency") + .requiresSwiftConcurrencySupport, ) func testPluginCanBeReferencedByProductName() async throws { try await fixture(name: "Miscellaneous/Plugins") { fixturePath in - let (stdout, _) = try await executeSwiftBuild(fixturePath.appending("PluginCanBeReferencedByProductName")) + let (stdout, _) = try await executeSwiftBuild( + fixturePath.appending("PluginCanBeReferencedByProductName"), + buildSystem: .native, + ) #expect(stdout.contains("Compiling plugin MyPlugin"), "stdout:\n\(stdout)") #expect(stdout.contains("Compiling PluginCanBeReferencedByProductName gen.swift"), "stdout:\n\(stdout)") #expect(stdout.contains("Build complete!"), "stdout:\n\(stdout)") @@ -1371,7 +1521,10 @@ final class PluginTests { try await withKnownIssue { // Try again with the Swift Build build system try await fixture(name: "Miscellaneous/Plugins") { fixturePath in - let (stdout, _) = try await executeSwiftBuild(fixturePath.appending("PluginCanBeReferencedByProductName"), extraArgs: ["--build-system", "swiftbuild"]) + let (stdout, _) = try await executeSwiftBuild( + fixturePath.appending("PluginCanBeReferencedByProductName"), + buildSystem: .swiftbuild, + ) #expect(stdout.contains("Build complete!"), "stdout:\n\(stdout)") } } when: { ProcessInfo.hostOperatingSystem == .windows } @@ -1380,7 +1533,7 @@ final class PluginTests { @Test( .bug("https://github.com/swiftlang/swift-package-manager/issues/8602"), .bug("https://github.com/swiftlang/swift-package-manager/issues/8791"), - .enabled(if: (try? UserToolchain.default)!.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency") + .requiresSwiftConcurrencySupport, ) func testPluginCanBeAffectedByXBuildToolsParameters() async throws { try await withKnownIssue { @@ -1388,7 +1541,8 @@ final class PluginTests { let (stdout, _) = try await executeSwiftBuild( fixturePath.appending(component: "MySourceGenPlugin"), configuration: .debug, - extraArgs: ["--product", "MyLocalTool", "-Xbuild-tools-swiftc", "-DUSE_CREATE"] + extraArgs: ["--product", "MyLocalTool", "-Xbuild-tools-swiftc", "-DUSE_CREATE"], + buildSystem: .native, ) #expect(stdout.contains("Linking MySourceGenBuildTool"), "stdout:\n\(stdout)") #expect(stdout.contains("Creating foo.swift from foo.dat"), "stdout:\n\(stdout)") @@ -1402,7 +1556,8 @@ final class PluginTests { let (stdout, stderr) = try await executeSwiftBuild( fixturePath.appending(component: "MySourceGenPlugin"), configuration: .debug, - extraArgs: ["-v", "--product", "MyLocalTool", "-Xbuild-tools-swiftc", "-DUSE_CREATE", "--build-system", "swiftbuild"] + extraArgs: ["-v", "--product", "MyLocalTool", "-Xbuild-tools-swiftc", "-DUSE_CREATE",], + buildSystem: .swiftbuild, ) #expect(stdout.contains("MySourceGenBuildTool-product"), "stdout:\n\(stdout)\nstderr:\n\(stderr)") #expect(stderr.contains("Creating foo.swift from foo.dat"), "stdout:\n\(stdout)\nstderr:\n\(stderr)") @@ -1414,12 +1569,16 @@ final class PluginTests { @Test( .bug("https://github.com/swiftlang/swift-package-manager/issues/8602"), .bug("https://github.com/swiftlang/swift-package-manager/issues/8791"), - .enabled(if: (try? UserToolchain.default)!.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency") + .requiresSwiftConcurrencySupport, ) func testURLBasedPluginAPI() async throws { try await withKnownIssue { 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, + buildSystem: .native, + ) #expect(stdout.contains("Build complete!"), "stdout:\n\(stdout)") } } when: { @@ -1429,7 +1588,11 @@ final class PluginTests { try await withKnownIssue { // Try again with the Swift Build build system try await fixture(name: "Miscellaneous/Plugins/MySourceGenPluginUsingURLBasedAPI") { fixturePath in - let (stdout, _) = try await executeSwiftBuild(fixturePath, configuration: .debug, extraArgs: ["--build-system", "swiftbuild"]) + let (stdout, _) = try await executeSwiftBuild( + fixturePath, + configuration: .debug, + buildSystem: .swiftbuild, + ) #expect(stdout.contains("Build complete!"), "stdout:\n\(stdout)") } } when: { ProcessInfo.hostOperatingSystem == .linux || ProcessInfo.hostOperatingSystem == .windows } @@ -1437,19 +1600,22 @@ final class PluginTests { @Test( .bug("https://github.com/swiftlang/swift-package-manager/issues/8774"), - .enabled(if: (try? UserToolchain.default)!.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency") + .requiresSwiftConcurrencySupport, + arguments: SupportedBuildSystemOnAllPlatforms, ) - func testDependentPlugins() async throws { - try await fixture(name: "Miscellaneous/Plugins/DependentPlugins") { fixturePath in - let (stdout, _) = try await executeSwiftBuild(fixturePath) - #expect(stdout.contains("Build complete!"), "stdout:\n\(stdout)") - } - + func testDependentPlugins( + buildSystem: BuildSystemProvider.Kind, + ) async throws { try await withKnownIssue { try await fixture(name: "Miscellaneous/Plugins/DependentPlugins") { fixturePath in - let (stdout, _) = try await executeSwiftBuild(fixturePath, extraArgs: ["--build-system", "swiftbuild"]) + let (stdout, _) = try await executeSwiftBuild( + fixturePath, + buildSystem: buildSystem, + ) #expect(stdout.contains("Build complete!"), "stdout:\n\(stdout)") } - } when: { ProcessInfo.hostOperatingSystem == .windows } + } when: { + buildSystem == .swiftbuild && ProcessInfo.hostOperatingSystem == .windows + } } } diff --git a/Tests/FunctionalTests/ResourcesTests.swift b/Tests/FunctionalTests/ResourcesTests.swift index 65359392c79..0d5eeae6a22 100644 --- a/Tests/FunctionalTests/ResourcesTests.swift +++ b/Tests/FunctionalTests/ResourcesTests.swift @@ -34,7 +34,11 @@ final class ResourcesTests: XCTestCase { #endif for execName in executables { - let (output, _) = try await executeSwiftRun(fixturePath, execName, buildSystem: .native) + let (output, _) = try await executeSwiftRun( + fixturePath, + execName, + buildSystem: .native, + ) XCTAssertTrue(output.contains("foo"), output) } } @@ -42,7 +46,10 @@ final class ResourcesTests: XCTestCase { func testLocalizedResources() async throws { try await fixtureXCTest(name: "Resources/Localized") { fixturePath in - try await executeSwiftBuild(fixturePath) + try await executeSwiftBuild( + fixturePath, + buildSystem: .native, + ) let exec = AbsolutePath(".build/debug/exe", relativeTo: fixturePath) // Note: Source from LANG and -AppleLanguages on command line for Linux resources @@ -63,7 +70,11 @@ final class ResourcesTests: XCTestCase { #endif try await fixtureXCTest(name: "Resources/Simple") { fixturePath in - await XCTAssertBuilds(fixturePath, extraArgs: ["--target", "MixedClangResource"]) + await XCTAssertBuilds( + fixturePath, + extraArgs: ["--target", "MixedClangResource"], + buildSystem: .native, + ) } } @@ -77,12 +88,22 @@ 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: .native, + ).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: .native, + ) try await withTemporaryDirectory(prefix: execName) { tmpDirPath in defer { @@ -112,7 +133,8 @@ final class ResourcesTests: XCTestCase { try await fixtureXCTest(name: "Resources/FoundationlessClient/UtilsWithFoundationPkg") { fixturePath in await XCTAssertBuilds( fixturePath, - Xswiftc: ["-warnings-as-errors"] + Xswiftc: ["-warnings-as-errors"], + buildSystem: .native, ) } } @@ -124,14 +146,21 @@ final class ResourcesTests: XCTestCase { #endif try await fixtureXCTest(name: "Resources/Simple") { fixturePath in - await XCTAssertSwiftTest(fixturePath, extraArgs: ["--filter", "ClangResourceTests"]) + await XCTAssertSwiftTest( + fixturePath, + extraArgs: ["--filter", "ClangResourceTests"], + buildSystem: .native, + ) } } func testResourcesEmbeddedInCode() async throws { try await fixtureXCTest(name: "Resources/EmbedInCodeSimple") { fixturePath in let execPath = fixturePath.appending(components: ".build", "debug", "EmbedInCodeSimple") - try await executeSwiftBuild(fixturePath) + try await executeSwiftBuild( + fixturePath, + buildSystem: .native, + ) let result = try await AsyncProcess.checkNonZeroExit(args: execPath.pathString) XCTAssertMatch(result, .contains("hello world")) let resourcePath = fixturePath.appending( @@ -139,13 +168,16 @@ final class ResourcesTests: XCTestCase { // Check incremental builds for i in 0..<2 { - let content = "Hi there \(i)!" - // Update the resource file. - try localFileSystem.writeFileContents(resourcePath, string: content) - try await executeSwiftBuild(fixturePath) - // Run the executable again. - let result2 = try await AsyncProcess.checkNonZeroExit(args: execPath.pathString) - XCTAssertMatch(result2, .contains("\(content)")) + let content = "Hi there \(i)!" + // Update the resource file. + try localFileSystem.writeFileContents(resourcePath, string: content) + try await executeSwiftBuild( + fixturePath, + buildSystem: .native, + ) + // Run the executable again. + let result2 = try await AsyncProcess.checkNonZeroExit(args: execPath.pathString) + XCTAssertMatch(result2, .contains("\(content)")) } } } @@ -181,7 +213,11 @@ 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, + env: ["SWIFT_DRIVER_SWIFTSCAN_LIB" : "/this/is/a/bad/path"], + buildSystem: .native, + ) // 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") diff --git a/Tests/FunctionalTests/ToolsVersionTests.swift b/Tests/FunctionalTests/ToolsVersionTests.swift index 2a96eb64e5a..01f57e4eb50 100644 --- a/Tests/FunctionalTests/ToolsVersionTests.swift +++ b/Tests/FunctionalTests/ToolsVersionTests.swift @@ -55,8 +55,11 @@ final class ToolsVersionTests: XCTestCase { try repo.tag(name: "1.0.0") // v1.0.1 - _ = try await SwiftPM.Package.execute( - ["tools-version", "--set", "10000.1"], packagePath: depPath) + _ = try await executeSwiftPackage( + depPath, + extraArgs: ["tools-version", "--set", "10000.1"], + buildSystem: .native, + ) try fs.writeFileContents( depPath.appending("foo.swift"), string: #"public func foo() { print("foo@1.0.1") }"# @@ -87,20 +90,34 @@ final class ToolsVersionTests: XCTestCase { Dep.foo() """ ) - _ = try await SwiftPM.Package.execute( - ["tools-version", "--set", "4.2"], packagePath: primaryPath).stdout.spm_chomp() + _ = try await executeSwiftPackage( + primaryPath, + extraArgs: ["tools-version", "--set", "4.2"], + buildSystem: .native, + ).stdout.spm_chomp() // Build the primary package. - _ = try await SwiftPM.Build.execute(packagePath: primaryPath) + _ = try await executeSwiftBuild( + primaryPath, + buildSystem: .native, + ) let exe = primaryPath.appending(components: ".build", try UserToolchain.default.targetTriple.platformBuildPathComponent, "debug", "Primary").pathString // v1 should get selected because v1.0.1 depends on a (way) higher set of tools. try await XCTAssertAsyncEqual(try await AsyncProcess.checkNonZeroExit(args: exe).spm_chomp(), "foo@1.0") // Set the tools version to something high. - _ = try await SwiftPM.Package.execute( - ["tools-version", "--set", "10000.1"], packagePath: primaryPath) + _ = try await executeSwiftPackage( + primaryPath, + extraArgs: ["tools-version", "--set", "10000.1"], + buildSystem: .native, + ) - await XCTAssertThrowsCommandExecutionError(try await SwiftPM.Build.execute(packagePath: primaryPath)) { error in + await XCTAssertThrowsCommandExecutionError( + try await executeSwiftBuild( + primaryPath, + buildSystem: .native, + ) + ) { error in XCTAssert(error.stderr.contains("is using Swift tools version 10000.1.0 but the installed version is \(ToolsVersion.current)"), error.stderr) } @@ -116,10 +133,18 @@ final class ToolsVersionTests: XCTestCase { swiftLanguageVersions: [.version("1000")]) """ ) - _ = try await SwiftPM.Package.execute( - ["tools-version", "--set", "4.2"], packagePath: primaryPath).stdout.spm_chomp() + _ = try await executeSwiftPackage( + primaryPath, + extraArgs: ["tools-version", "--set", "4.2"], + buildSystem: .native, + ).stdout.spm_chomp() - await XCTAssertThrowsCommandExecutionError(try await SwiftPM.Build.execute(packagePath: primaryPath)) { error in + await XCTAssertThrowsCommandExecutionError( + try await executeSwiftBuild( + primaryPath, + buildSystem: .native, + ) + ) { error in XCTAssertTrue(error.stderr.contains("package 'primary' requires minimum Swift language version 1000 which is not supported by the current tools version (\(ToolsVersion.current))"), error.stderr) } @@ -134,9 +159,15 @@ final class ToolsVersionTests: XCTestCase { swiftLanguageVersions: [.version("\(ToolsVersion.current.major)"), .version("1000")]) """ ) - _ = try await SwiftPM.Package.execute( - ["tools-version", "--set", "4.2"], packagePath: primaryPath).stdout.spm_chomp() - _ = try await SwiftPM.Build.execute(packagePath: primaryPath) + _ = try await executeSwiftPackage( + primaryPath, + extraArgs: ["tools-version", "--set", "4.2"], + buildSystem: .native, + ).stdout.spm_chomp() + _ = try await executeSwiftBuild( + primaryPath, + buildSystem: .native, + ) } } } diff --git a/Tests/FunctionalTests/VersionSpecificTests.swift b/Tests/FunctionalTests/VersionSpecificTests.swift index ba50d0a9871..b44f5bdc739 100644 --- a/Tests/FunctionalTests/VersionSpecificTests.swift +++ b/Tests/FunctionalTests/VersionSpecificTests.swift @@ -90,7 +90,10 @@ final class VersionSpecificTests: XCTestCase { """ ) // This build should fail, because of the invalid package. - await XCTAssertBuildFails(primaryPath) + await XCTAssertBuildFails( + primaryPath, + buildSystem: .native, + ) // Create a file which requires a version 1.1.0 resolution. try fs.writeFileContents( @@ -123,8 +126,15 @@ final class VersionSpecificTests: XCTestCase { try repo.tag(name: "1.1.0@swift-\(SwiftVersion.current.major)") // The build should work now. - _ = try await SwiftPM.Package.execute(["reset"], packagePath: primaryPath) - await XCTAssertBuilds(primaryPath) + _ = try await executeSwiftPackage( + primaryPath, + extraArgs: ["reset"], + buildSystem: .native, + ) + await XCTAssertBuilds( + primaryPath, + buildSystem: .native, + ) } } } diff --git a/Tests/IntegrationTests/BasicTests.swift b/Tests/IntegrationTests/BasicTests.swift index 8067a779671..be2d128648a 100644 --- a/Tests/IntegrationTests/BasicTests.swift +++ b/Tests/IntegrationTests/BasicTests.swift @@ -34,7 +34,10 @@ private struct BasicTests { // marking as withKnownIssue(intermittent: trye) as git operation can fail. try sh("git\(ProcessInfo.exeSuffix)", "clone", "https://github.com/apple/example-package-dealer", packagePath) } - let build1Output = try await executeSwiftBuild(packagePath).stdout + let build1Output = try await executeSwiftBuild( + packagePath, + buildSystem: .native, + ).stdout // Check the build log. #expect(build1Output.contains("Build complete")) @@ -51,7 +54,10 @@ private struct BasicTests { #expect(gitOutput.contains("nothing to commit, working tree clean")) // Verify that another 'swift build' does nothing. - let build2Output = try await executeSwiftBuild(packagePath).stdout + let build2Output = try await executeSwiftBuild( + packagePath, + buildSystem: .native, + ).stdout #expect(build2Output.contains("Build complete")) #expect(build2Output.contains("Compiling") == false) } @@ -88,7 +94,11 @@ private struct BasicTests { ) // Check the build. - let buildOutput = try await executeSwiftBuild(packagePath, extraArgs: ["-v"]).stdout + let buildOutput = try await executeSwiftBuild( + packagePath, + extraArgs: ["-v"], + buildSystem: .native, + ).stdout #expect(try #/swiftc.* -module-name tool/#.firstMatch(in: buildOutput) != nil) // Verify that the tool exists and works. @@ -110,8 +120,15 @@ private struct BasicTests { // Create a new package with an executable target. let packagePath = tempDir.appending(component: "Project") try localFileSystem.createDirectory(packagePath) - try await executeSwiftPackage(packagePath, extraArgs: ["init", "--type", "executable"]) - let packageOutput = try await executeSwiftBuild(packagePath) + try await executeSwiftPackage( + packagePath, + extraArgs: ["init", "--type", "executable"], + buildSystem: .native, + ) + let packageOutput = try await executeSwiftBuild( + packagePath, + buildSystem: .native, + ) // Check the build log. let compilingRegex = try Regex("Compiling .*Project.*") @@ -144,8 +161,16 @@ private struct BasicTests { let packagePath = tempDir.appending(component: "Project") try localFileSystem.createDirectory(packagePath) await withKnownIssue("error: no tests found; create a target in the 'Tests' directory") { - try await executeSwiftPackage(packagePath, extraArgs: ["init", "--type", "executable"]) - let packageOutput = try await executeSwiftTest(packagePath, extraArgs: ["--vv"]) + try await executeSwiftPackage( + packagePath, + extraArgs: ["init", "--type", "executable"], + buildSystem: .native, + ) + let packageOutput = try await executeSwiftTest( + packagePath, + extraArgs: ["--vv"], + buildSystem: .native, + ) // Check the test log. let compilingRegex = try Regex("Compiling .*ProjectTests.*") @@ -171,8 +196,15 @@ private struct BasicTests { // Create a new package with an executable target. let packagePath = tempDir.appending(component: "Project") try localFileSystem.createDirectory(packagePath) - try await executeSwiftPackage(packagePath, extraArgs: ["init", "--type", "library"]) - let buildOutput = try await executeSwiftBuild(packagePath).stdout + try await executeSwiftPackage( + packagePath, + extraArgs: ["init", "--type", "library"], + buildSystem: .native, + ) + let buildOutput = try await executeSwiftBuild( + packagePath, + buildSystem: .native, + ).stdout // Check the build log. #expect(try #/Compiling .*Project.*/#.firstMatch(in: buildOutput) != nil) @@ -197,8 +229,15 @@ private struct BasicTests { // Create a new package with an executable target. let packagePath = tempDir.appending(component: "Project") try localFileSystem.createDirectory(packagePath) - try await executeSwiftPackage(packagePath, extraArgs: ["init", "--type", "library"]) - let output = try await executeSwiftTest(packagePath) + try await executeSwiftPackage( + packagePath, + extraArgs: ["init", "--type", "library"], + buildSystem: .native, + ) + let output = try await executeSwiftTest( + packagePath, + buildSystem: .native, + ) // Check there were no compile errors or warnings. #expect(output.stdout.contains("error") == false) @@ -242,7 +281,11 @@ private struct BasicTests { ) // Check the build. - let buildOutput = try await executeSwiftBuild(packagePath, extraArgs: ["-v"]).stdout + let buildOutput = try await executeSwiftBuild( + packagePath, + extraArgs: ["-v"], + buildSystem: .native, + ).stdout let expression = ProcessInfo .hostOperatingSystem != .windows ? #/swiftc.* -module-name special_tool .* '@.*/more spaces/special tool/.build/[^/]+/debug/special_tool.build/sources'/# : @@ -270,7 +313,11 @@ private struct BasicTests { try withTemporaryDirectory { tempDir in let packagePath = tempDir.appending(component: "secho") try localFileSystem.createDirectory(packagePath) - try await executeSwiftPackage(packagePath, extraArgs: ["init", "--type", "executable"]) + try await executeSwiftPackage( + packagePath, + extraArgs: ["init", "--type", "executable"], + buildSystem: .native, + ) // delete any files generated for entry in try localFileSystem.getDirectoryContents( packagePath.appending(components: "Sources") @@ -316,7 +363,11 @@ private struct BasicTests { try withTemporaryDirectory { tempDir in let packagePath = tempDir.appending(component: "swiftTest") try localFileSystem.createDirectory(packagePath) - try await executeSwiftPackage(packagePath, extraArgs: ["init", "--type", "library"]) + try await executeSwiftPackage( + packagePath, + extraArgs: ["init", "--type", "library"], + buildSystem: .native, + ) try localFileSystem.writeFileContents( packagePath.appending(components: "Tests", "swiftTestTests", "MyTests.swift"), bytes: ByteString( @@ -343,7 +394,8 @@ private struct BasicTests { "--skip", "testBaz", "--vv", - ] + ], + buildSystem: .native, ) // Check the test log. @@ -363,7 +415,9 @@ private struct BasicTests { try await fixture(name: "Miscellaneous/PackageWithResource/") { packagePath in let result = try await executeSwiftTest( - packagePath, extraArgs: ["--filter", "MyTests.*", "--vv"] + packagePath, + extraArgs: ["--filter", "MyTests.*", "--vv"], + buildSystem: .native, ) // Check the test log. diff --git a/Tests/IntegrationTests/SwiftPMTests.swift b/Tests/IntegrationTests/SwiftPMTests.swift index 8e6affdf5af..b0e17222fd4 100644 --- a/Tests/IntegrationTests/SwiftPMTests.swift +++ b/Tests/IntegrationTests/SwiftPMTests.swift @@ -24,7 +24,11 @@ private struct SwiftPMTests { try await binaryTargetsFixture { fixturePath in do { await withKnownIssue("error: local binary target ... does not contain a binary artifact") { - let runOutput = try await executeSwiftRun(fixturePath, "exe", buildSystem: .native) + let runOutput = try await executeSwiftRun( + fixturePath, + "exe", + buildSystem: .native, + ) #expect(!runOutput.stderr.contains("error:")) #expect( runOutput.stdout == """ @@ -50,7 +54,8 @@ private struct SwiftPMTests { await #expect { try await executeSwiftPackage( fixturePath, - extraArgs: ["compute-checksum", invalidPath.pathString] + extraArgs: ["compute-checksum", invalidPath.pathString], + buildSystem: .native, ) } throws: { error in // The order of supported extensions is not ordered, and changes. @@ -63,7 +68,9 @@ private struct SwiftPMTests { let validPath = fixturePath.appending(component: "SwiftFramework.zip") let packageOutput = try await executeSwiftPackage( - fixturePath, extraArgs: ["compute-checksum", validPath.pathString] + fixturePath, + extraArgs: ["compute-checksum", validPath.pathString], + buildSystem: .native, ) #expect( packageOutput.stdout.spm_chomp() @@ -93,8 +100,15 @@ private struct SwiftPMTests { try withTemporaryDirectory { tmpDir in let packagePath = tmpDir.appending(component: "foo") try localFileSystem.createDirectory(packagePath) - try await executeSwiftPackage(packagePath, extraArgs: ["init", "--type", "executable"]) - try await executeSwiftBuild(packagePath, buildSystem: buildSystemProvider) + try await executeSwiftPackage( + packagePath, + extraArgs: ["init", "--type", "executable"], + buildSystem: buildSystemProvider, + ) + try await executeSwiftBuild( + packagePath, + buildSystem: buildSystemProvider, + ) try await withKnownIssue( "Error while loading shared libraries: libswiftCore.so: cannot open shared object file: No such file or directory" @@ -131,7 +145,11 @@ private struct SwiftPMTests { try await withTemporaryDirectory { tmpDir in let packagePath = tmpDir.appending(component: "foo") try localFileSystem.createDirectory(packagePath) - try await executeSwiftPackage(packagePath, extraArgs: ["init", "--type", "library"]) + try await executeSwiftPackage( + packagePath, + extraArgs: ["init", "--type", "library"], + buildSystem: buildSystemProvider, + ) try await withKnownIssue( """ Linux: /lib/x86_64-linux-gnu/Scrt1.o:function _start: error: undefined reference to 'main' @@ -140,8 +158,14 @@ private struct SwiftPMTests { """, isIntermittent: true ) { - try await executeSwiftBuild(packagePath, buildSystem: buildSystemProvider) - let testOutput = try await executeSwiftTest(packagePath, buildSystem: buildSystemProvider) + try await executeSwiftBuild( + packagePath, + buildSystem: buildSystemProvider, + ) + let testOutput = try await executeSwiftTest( + packagePath, + buildSystem: buildSystemProvider, + ) // #expect(testOutput.returnCode == .terminated(code: 0)) #expect(!testOutput.stderr.contains("error:")) @@ -156,7 +180,11 @@ private struct SwiftPMTests { try await withTemporaryDirectory { tmpDir in let packagePath = tmpDir.appending(component: "foo") try localFileSystem.createDirectory(packagePath) - try await executeSwiftPackage(packagePath, extraArgs: ["init", "--type", "executable"]) + try await executeSwiftPackage( + packagePath, + extraArgs: ["init", "--type", "executable"], + buildSystem: .native, + ) // delete any files generated for entry in try localFileSystem.getDirectoryContents( packagePath.appending(components: "Sources") @@ -173,7 +201,11 @@ private struct SwiftPMTests { let archs = ["x86_64", "arm64"] for arch in archs { - try await executeSwiftBuild(packagePath, extraArgs: ["--arch", arch]) + try await executeSwiftBuild( + packagePath, + extraArgs: ["--arch", arch], + buildSystem: .native, + ) let fooPath = try AbsolutePath( validating: ".build/\(arch)-apple-macosx/debug/foo", relativeTo: packagePath @@ -184,7 +216,11 @@ private struct SwiftPMTests { // let args = // [swiftBuild.pathString, "--package-path", packagePath.pathString] // + archs.flatMap { ["--arch", $0] } - try await executeSwiftBuild(packagePath, extraArgs: archs.flatMap { ["--arch", $0] }) + try await executeSwiftBuild( + packagePath, + extraArgs: archs.flatMap { ["--arch", $0] }, + buildSystem: .native, + ) let fooPath = try AbsolutePath( validating: ".build/apple/Products/Debug/foo", relativeTo: packagePath @@ -207,8 +243,16 @@ private struct SwiftPMTests { try await withTemporaryDirectory { tmpDir in let packagePath = tmpDir.appending(component: "test-package-coverage") try localFileSystem.createDirectory(packagePath) - try await executeSwiftPackage(packagePath, extraArgs: ["init", "--type", "empty"]) - try await executeSwiftPackage(packagePath, extraArgs: ["add-target", "--type", "test", "ReproTests"]) + try await executeSwiftPackage( + packagePath, + extraArgs: ["init", "--type", "empty"], + buildSystem: .native, + ) + try await executeSwiftPackage( + packagePath, + extraArgs: ["add-target", "--type", "test", "ReproTests"], + buildSystem: .native, + ) try localFileSystem.writeFileContents( AbsolutePath(validating: "Tests/ReproTests/Subject.swift", relativeTo: packagePath), string: """ @@ -233,8 +277,16 @@ private struct SwiftPMTests { } """ ) - let expectedCoveragePath = try await executeSwiftTest(packagePath, extraArgs: ["--show-coverage-path"]).stdout.trimmingCharacters(in: .whitespacesAndNewlines) - try await executeSwiftTest(packagePath, extraArgs: ["--enable-code-coverage", "--disable-xctest"]) + let expectedCoveragePath = try await executeSwiftTest( + packagePath, + extraArgs: ["--show-coverage-path"], + buildSystem: .native, + ).stdout.trimmingCharacters(in: .whitespacesAndNewlines) + try await executeSwiftTest( + packagePath, + extraArgs: ["--enable-code-coverage", "--disable-xctest"], + buildSystem: .native, + ) let coveragePath = try AbsolutePath(validating: expectedCoveragePath) // Check the coverage path exists. diff --git a/Tests/WorkspaceTests/InitTests.swift b/Tests/WorkspaceTests/InitTests.swift index 2e4c83a2271..d09e117d1a5 100644 --- a/Tests/WorkspaceTests/InitTests.swift +++ b/Tests/WorkspaceTests/InitTests.swift @@ -86,7 +86,10 @@ 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, + buildSystem: .native, + ) let triple = try UserToolchain.default.targetTriple let binPath = path.appending(components: ".build", triple.platformBuildPathComponent, "debug") #if os(Windows) @@ -115,7 +118,10 @@ final class InitTests: XCTestCase { try initPackage.writePackageStructure() XCTAssertEqual(try fs.getDirectoryContents(path.appending("Sources").appending("main")), ["MainEntrypoint.swift"]) - await XCTAssertBuilds(path) + await XCTAssertBuilds( + path, + buildSystem: .native, + ) } } @@ -165,7 +171,10 @@ final class InitTests: XCTestCase { XCTAssertMatch(testFileContents, .contains("func testExample() throws")) // Try building it - await XCTAssertBuilds(path) + await XCTAssertBuilds( + path, + buildSystem: .native, + ) let triple = try UserToolchain.default.targetTriple XCTAssertFileExists(path.appending(components: ".build", triple.platformBuildPathComponent, "debug", "Modules", "Foo.swiftmodule")) } @@ -201,7 +210,10 @@ final class InitTests: XCTestCase { #if canImport(TestingDisabled) // Try building it - await XCTAssertBuilds(path) + await XCTAssertBuilds( + path, + buildSystem: .native, + ) let triple = try UserToolchain.default.targetTriple XCTAssertFileExists(path.appending(components: ".build", triple.platformBuildPathComponent, "debug", "Modules", "Foo.swiftmodule")) #endif @@ -238,7 +250,10 @@ final class InitTests: XCTestCase { #if canImport(TestingDisabled) // Try building it - await XCTAssertBuilds(path) + await XCTAssertBuilds( + path, + buildSystem: .native, + ) let triple = try UserToolchain.default.targetTriple XCTAssertFileExists(path.appending(components: ".build", triple.platformBuildPathComponent, "debug", "Modules", "Foo.swiftmodule")) #endif @@ -272,7 +287,10 @@ final class InitTests: XCTestCase { #if canImport(TestingDisabled) // Try building it - await XCTAssertBuilds(path) + await XCTAssertBuilds( + path, + buildSystem: .native, + ) let triple = try UserToolchain.default.targetTriple XCTAssertFileExists(path.appending(components: ".build", triple.platformBuildPathComponent, "debug", "Modules", "Foo.swiftmodule")) #endif @@ -371,7 +389,10 @@ final class InitTests: XCTestCase { try initPackage.writePackageStructure() // Try building it. - await XCTAssertBuilds(packageRoot) + await XCTAssertBuilds( + packageRoot, + buildSystem: .native, + ) let triple = try UserToolchain.default.targetTriple XCTAssertFileExists(packageRoot.appending(components: ".build", triple.platformBuildPathComponent, "debug", "Modules", "some_package.swiftmodule")) } @@ -394,7 +415,10 @@ final class InitTests: XCTestCase { ) try initPackage.writePackageStructure() - await XCTAssertBuilds(packageRoot) + await XCTAssertBuilds( + packageRoot, + buildSystem: .native, + ) } }