diff --git a/Fixtures/Coverage/Simple/Package.swift b/Fixtures/Coverage/Simple/Package.swift deleted file mode 100644 index 4449f7edfff..00000000000 --- a/Fixtures/Coverage/Simple/Package.swift +++ /dev/null @@ -1,26 +0,0 @@ -// swift-tools-version: 6.2 -// The swift-tools-version declares the minimum version of Swift required to build this package. - -import PackageDescription - -let package = Package( - name: "Simple", - products: [ - // Products define the executables and libraries a package produces, making them visible to other packages. - .library( - name: "Simple", - targets: ["Simple"] - ), - ], - targets: [ - // Targets are the basic building blocks of a package, defining a module or a test suite. - // Targets can depend on other targets in this package and products from dependencies. - .target( - name: "Simple" - ), - .testTarget( - name: "SimpleTests", - dependencies: ["Simple"] - ), - ] -) diff --git a/Fixtures/Coverage/Simple/Sources/Simple/Simple.swift b/Fixtures/Coverage/Simple/Sources/Simple/Simple.swift deleted file mode 100644 index 5e1e981ad5d..00000000000 --- a/Fixtures/Coverage/Simple/Sources/Simple/Simple.swift +++ /dev/null @@ -1,10 +0,0 @@ -// The Swift Programming Language -// https://docs.swift.org/swift-book - -public func greet(name: String = "world") -> String { - return "Hello, \(name)!" -} - -public func libA() -> String { - return "libA" -} diff --git a/Fixtures/Coverage/Simple/Tests/SimpleTests/SimpleTests.swift b/Fixtures/Coverage/Simple/Tests/SimpleTests/SimpleTests.swift deleted file mode 100644 index 89e144011f1..00000000000 --- a/Fixtures/Coverage/Simple/Tests/SimpleTests/SimpleTests.swift +++ /dev/null @@ -1,24 +0,0 @@ -import Testing -import XCTest -@testable import Simple - -@Test( - arguments: [ - "Bob", - "Alice", - "", - ] -) - func testGreet( - name: String - ) async throws { - let actual = greet(name: name) - - #expect(actual == "Hello, \(name)!") -} - -final class SimpleTests: XCTestCase { - func testExample() throws { - XCTAssertEqual(libA(), "libA", "Actual is not as expected") - } -} diff --git a/Sources/Commands/SwiftTestCommand.swift b/Sources/Commands/SwiftTestCommand.swift index d2eefa5fd97..669f04dab3b 100644 --- a/Sources/Commands/SwiftTestCommand.swift +++ b/Sources/Commands/SwiftTestCommand.swift @@ -14,7 +14,6 @@ import ArgumentParser @_spi(SwiftPMInternal) import Basics -import struct Basics.Triple import _Concurrency @@ -598,11 +597,7 @@ public struct SwiftTestCommand: AsyncSwiftCommand { for product in testProducts { // Export the codecov data as JSON. let jsonPath = productsBuildParameters.codeCovAsJSONPath(packageName: rootManifest.displayName) - try await exportCodeCovAsJSON( - to: jsonPath, - testBinary: product.binaryPath, - swiftCommandState: swiftCommandState, - ) + try await exportCodeCovAsJSON(to: jsonPath, testBinary: product.binaryPath, swiftCommandState: swiftCommandState) } } @@ -624,6 +619,7 @@ public struct SwiftTestCommand: AsyncSwiftCommand { } } args += ["-o", productsBuildParameters.codeCovDataFile.pathString] + try await AsyncProcess.checkNonZeroExit(arguments: args) } @@ -636,17 +632,11 @@ public struct SwiftTestCommand: AsyncSwiftCommand { // Export using the llvm-cov tool. let llvmCov = try swiftCommandState.getTargetToolchain().getLLVMCov() let (productsBuildParameters, _) = try swiftCommandState.buildParametersForTest(options: self.options) - let archArgs: [String] = if let arch = productsBuildParameters.triple.llvmCovArchArgument { - ["--arch", "\(arch)"] - } else { - [] - } let args = [ llvmCov.pathString, "export", "-instr-profile=\(productsBuildParameters.codeCovDataFile)", - ] + archArgs + [ - testBinary.pathString, + testBinary.pathString ] let result = try await AsyncProcess.popen(arguments: args) @@ -719,21 +709,6 @@ extension SwiftTestCommand { } } -fileprivate extension Triple { - var llvmCovArchArgument: String? { - guard let arch = self.arch else { - return nil - } - switch arch { - case .aarch64: - // Apple platforms uses arm64 - return self.isApple() ? "arm64" : "aarch64" - default: - return "\(arch)" - } - } -} - extension SwiftTestCommand { struct Last: SwiftCommand { @OptionGroup(visibility: .hidden) diff --git a/Sources/SwiftBuildSupport/SwiftBuildSystem.swift b/Sources/SwiftBuildSupport/SwiftBuildSystem.swift index 2878554ad06..0a23a7b2fb7 100644 --- a/Sources/SwiftBuildSupport/SwiftBuildSystem.swift +++ b/Sources/SwiftBuildSupport/SwiftBuildSystem.swift @@ -1109,9 +1109,8 @@ public final class SwiftBuildSystem: SPMBuildCore.BuildSystem { private static func constructTestingSettingsOverrides(from parameters: BuildParameters.Testing) -> [String: String] { var settings: [String: String] = [:] - - // Coverage settings - settings["CLANG_COVERAGE_MAPPING"] = parameters.enableCodeCoverage ? "YES" : "NO" + // TODO: enableCodeCoverage + // explicitlyEnabledTestability switch parameters.explicitlyEnabledTestability { case true: diff --git a/Sources/_InternalTestSupport/SwiftTesting+TraitsBug.swift b/Sources/_InternalTestSupport/SwiftTesting+TraitsBug.swift index 81a245e6929..e452da7d6eb 100644 --- a/Sources/_InternalTestSupport/SwiftTesting+TraitsBug.swift +++ b/Sources/_InternalTestSupport/SwiftTesting+TraitsBug.swift @@ -54,13 +54,6 @@ extension Trait where Self == Testing.Bug { ) } - public static var IssueWindowsPathTestsFailures: Self { - .issue( - "https://github.com/swiftlang/swift-package-manager/issues/8511", - relationship: .defect, - ) - } - public static var IssueWindowsCannotSaveAttachment: Self { // error: unable to write file 'C:\Users\ContainerAdministrator\AppData\Local\Temp\CFamilyTargets_CDynamicLookup.hNxGHC\CFamilyTargets_CDynamicLookup\.build\x86_64-unknown-windows-msvc\Intermediates.noindex\CDynamicLookup.build\Release-windows\CDynamicLookup.build\Objects-normal\x86_64\CDynamicLookup.LinkFileList': No such file or directory (2) .issue( diff --git a/Tests/BasicsTests/FileSystem/PathTests.swift b/Tests/BasicsTests/FileSystem/PathTests.swift index 58fe9cadd98..5cf741f1a34 100644 --- a/Tests/BasicsTests/FileSystem/PathTests.swift +++ b/Tests/BasicsTests/FileSystem/PathTests.swift @@ -43,7 +43,6 @@ struct PathTests { } @Test( - .IssueWindowsPathTestsFailures, arguments: [ (path: "/ab/cd/ef/", expected: (windows ? #"\ab\cd\ef"# : "/ab/cd/ef"), label: "Trailing path seperator"), (path: "/ab/cd/ef//", expected: (windows ? #"\ab\cd\ef"# : "/ab/cd/ef"), label: "Trailing path seperator"), @@ -111,7 +110,6 @@ struct PathTests { } @Test( - .IssueWindowsPathTestsFailures, arguments: [ (path: "/./a", expected: (windows ? #"\"# : "/")), (path: "/../..", expected: (windows ? #"\"# : "/")), @@ -145,7 +143,6 @@ struct PathTests { } @Test( - .IssueWindowsPathTestsFailures, arguments: [ (path: "/../..", expected: "/"), ] @@ -181,7 +178,6 @@ struct PathTests { } @Test( - .IssueWindowsPathTestsFailures, arguments: [ (path: "/../..", expected: "/"), ] @@ -208,7 +204,6 @@ struct PathTests { #expect(actual == expectedPath) } @Test( - .IssueWindowsPathTestsFailures, arguments: [ (path: "/", numParentDirectoryCalls: 1, expected: "/"), (path: "/", numParentDirectoryCalls: 2, expected: "/"), @@ -220,7 +215,6 @@ struct PathTests { } @Test( - .IssueWindowsPathTestsFailures, arguments: [ (path: "/bar/../foo/..//", numParentDirectoryCalls: 2, expected: "/"), (path: "/bar/../foo/..//yabba/a/b", numParentDirectoryCalls: 2, expected: "/yabba") @@ -237,7 +231,6 @@ struct PathTests { } @Test( - .IssueWindowsPathTestsFailures, arguments: [ (path: "/", expected: ["/"]), (path: "/.", expected: ["/"]), @@ -375,7 +368,6 @@ struct PathTests { } @Test( - .IssueWindowsPathTestsFailures, arguments: [ (path: "ab//cd//ef", expected: (windows ? #"ab\cd\ef"# : "ab/cd/ef"), label: "repeated path seperators"), (path: "ab//cd///ef", expected: (windows ? #"ab\cd\ef"# : "ab/cd/ef"), label: "repeated path seperators"), @@ -448,8 +440,7 @@ struct PathTests { } @Test( - .IssueWindowsPathTestsFailures, - arguments: [ + arguments: [ (path: "../a/..", expected: "."), (path: "a/..", expected: "."), (path: "a/../////../////./////", expected: "."), @@ -490,7 +481,6 @@ struct PathTests { } @Test( - .IssueWindowsPathTestsFailures, arguments: [ (path: "a/..", expected: "."), (path: "a/../////../////./////", expected: ".."), @@ -529,7 +519,6 @@ struct PathTests { } @Test( - .IssueWindowsPathTestsFailures, arguments: [ (path: "../..", expected: ".."), (path: "../a/..", expected: ".."), @@ -571,8 +560,7 @@ struct PathTests { } @Test( - .IssueWindowsPathTestsFailures, - arguments:[ + arguments:[ "a.", ".a", "", @@ -613,7 +601,6 @@ struct PathTests { } @Test( - .IssueWindowsPathTestsFailures, arguments: [ (path: "foo/bar/..", expected: ["foo"]), (path: "bar/../foo", expected: ["foo"]), @@ -635,15 +622,13 @@ struct PathTests { } } - @Test( - .IssueWindowsPathTestsFailures, - ) + @Test func relativePathValidation() throws { #expect(throws: Never.self) { try RelativePath(validating: "a/b/c/d") } - withKnownIssue("https://github.com/swiftlang/swift-package-manager/issues/8511: \\") { + withKnownIssue { #expect {try RelativePath(validating: "/a/b/d")} throws: { error in ("\(error)" == "invalid relative path '/a/b/d'; relative path should not begin with '/'") } @@ -651,6 +636,7 @@ struct PathTests { ProcessInfo.hostOperatingSystem == .windows } } + } @Test diff --git a/Tests/BasicsTests/HTTPClientTests.swift b/Tests/BasicsTests/HTTPClientTests.swift index b4402c55919..6ea4442b3db 100644 --- a/Tests/BasicsTests/HTTPClientTests.swift +++ b/Tests/BasicsTests/HTTPClientTests.swift @@ -259,8 +259,11 @@ struct HTTPClientTests { var request = HTTPClient.Request(method: .get, url: "http://test") request.options.validResponseCodes = [200] - await #expect(throws: HTTPClientError.badResponseStatusCode(statusCode)) { - try await httpClient.execute(request) + do { + let response = try await httpClient.execute(request) + Issue.record("unexpected success \(response)") + } catch { + #expect(error as? HTTPClientError == .badResponseStatusCode(statusCode)) } } @@ -404,8 +407,11 @@ struct HTTPClientTests { var request = HTTPClient.Request(url: "http://test") request.options.maximumResponseSizeInBytes = 10 - await #expect(throws: HTTPClientError.responseTooLarge(maxSize * 2)) { - try await httpClient.execute(request) + do { + let response = try await httpClient.execute(request) + Issue.record("unexpected success \(response)") + } catch { + #expect(error as? HTTPClientError == .responseTooLarge(maxSize * 2)) } } diff --git a/Tests/BuildTests/PluginsBuildPlanTests.swift b/Tests/BuildTests/PluginsBuildPlanTests.swift index 60e04740d1e..86158adfc16 100644 --- a/Tests/BuildTests/PluginsBuildPlanTests.swift +++ b/Tests/BuildTests/PluginsBuildPlanTests.swift @@ -28,7 +28,7 @@ struct PluginsBuildPlanTests { .tags( .Feature.Command.Build, ), - .IssueWindowsPathTestsFailures, // Fails to build the project to due to incorrect Path handling + .issue("https://github.com/swiftlang/swift-package-manager/issues/8511", relationship: .defect), // Fails to build the project to due to incorrect Path handling arguments: BuildConfiguration.allCases, ) func buildToolsDatabasePath( diff --git a/Tests/CommandsTests/BuildCommandTests.swift b/Tests/CommandsTests/BuildCommandTests.swift index 19bee7f9add..01e7c813abc 100644 --- a/Tests/CommandsTests/BuildCommandTests.swift +++ b/Tests/CommandsTests/BuildCommandTests.swift @@ -32,89 +32,22 @@ struct BuildResult { let moduleContents: [String] } -@discardableResult -fileprivate func execute( - _ args: [String] = [], - environment: Environment? = nil, - packagePath: AbsolutePath? = nil, - configuration: BuildConfiguration, - buildSystem: BuildSystemProvider.Kind, - throwIfCommandFails: Bool = true, -) async throws -> (stdout: String, stderr: String) { - - return try await executeSwiftBuild( - packagePath, - configuration: configuration, - extraArgs: args, - env: environment, - buildSystem: buildSystem, - throwIfCommandFails: throwIfCommandFails, +@Suite( + .tags( + Tag.TestSize.small, + ), +) +struct SanitierTests { + @Test( + arguments: Sanitizer.allCases ) -} - -fileprivate func build( - _ args: [String], - packagePath: AbsolutePath? = nil, - configuration: BuildConfiguration, - cleanAfterward: Bool = true, - buildSystem: BuildSystemProvider.Kind, -) async throws -> BuildResult { - do { - let (stdout, stderr) = try await execute(args, packagePath: packagePath,configuration: configuration, buildSystem: buildSystem,) - defer { - } - let (binPathOutput, _) = try await execute( - ["--show-bin-path"], - packagePath: packagePath, - configuration: configuration, - buildSystem: buildSystem, - ) - let binPath = try AbsolutePath(validating: binPathOutput.trimmingCharacters(in: .whitespacesAndNewlines)) - let binContents = try localFileSystem.getDirectoryContents(binPath).filter { - guard let contents = try? localFileSystem.getDirectoryContents(binPath.appending(component: $0)) else { - return true - } - // Filter directories which only contain an output file map since we didn't build anything for those which - // is what `binContents` is meant to represent. - return contents != ["output-file-map.json"] - } - var moduleContents: [String] = [] - if buildSystem == .native { - moduleContents = (try? localFileSystem.getDirectoryContents(binPath.appending(component: "Modules"))) ?? [] - } else { - let moduleDirs = (try? localFileSystem.getDirectoryContents(binPath).filter { - $0.hasSuffix(".swiftmodule") - }) ?? [] - for dir: String in moduleDirs { - moduleContents += - (try? localFileSystem.getDirectoryContents(binPath.appending(component: dir)).map { "\(dir)/\($0)" }) ?? [] - } - } - + func creatingSanitizers(sanitizer: Sanitizer) throws { + #expect(sanitizer == Sanitizer(argument: sanitizer.shortName)) + } - if cleanAfterward { - try await executeSwiftPackage( - packagePath, - extraArgs: ["clean"], - buildSystem: buildSystem - ) - } - return BuildResult( - binPath: binPath, - stdout: stdout, - stderr: stderr, - binContents: binContents, - moduleContents: moduleContents - ) - } catch { - if cleanAfterward { - try await executeSwiftPackage( - packagePath, - extraArgs: ["clean"], - buildSystem: buildSystem - ) - } - throw error + @Test + func invalidSanitizer() throws { + #expect(Sanitizer(argument: "invalid") == nil) } } @@ -127,36 +60,114 @@ fileprivate func build( ) struct BuildCommandTestCases { + @discardableResult + func execute( + _ args: [String] = [], + environment: Environment? = nil, + packagePath: AbsolutePath? = nil, + configuration: BuildConfiguration = .debug, + buildSystem: BuildSystemProvider.Kind, + throwIfCommandFails: Bool = true, + ) async throws -> (stdout: String, stderr: String) { + + return try await executeSwiftBuild( + packagePath, + configuration: configuration, + extraArgs: args, + env: environment, + buildSystem: buildSystem, + throwIfCommandFails: throwIfCommandFails, + ) + } + + func build( + _ args: [String], + packagePath: AbsolutePath? = nil, + configuration: BuildConfiguration = .debug, + cleanAfterward: Bool = true, + buildSystem: BuildSystemProvider.Kind, + ) async throws -> BuildResult { + do { + // let buildConfigurationArguments = isRelease ? ["-c", "release"] : [] + let (stdout, stderr) = try await execute(args, packagePath: packagePath,configuration: configuration, buildSystem: buildSystem,) + defer { + } + let (binPathOutput, _) = try await execute( + ["--show-bin-path"], + packagePath: packagePath, + configuration: configuration, + buildSystem: buildSystem, + ) + let binPath = try AbsolutePath(validating: binPathOutput.trimmingCharacters(in: .whitespacesAndNewlines)) + let binContents = try localFileSystem.getDirectoryContents(binPath).filter { + guard let contents = try? localFileSystem.getDirectoryContents(binPath.appending(component: $0)) else { + return true + } + // Filter directories which only contain an output file map since we didn't build anything for those which + // is what `binContents` is meant to represent. + return contents != ["output-file-map.json"] + } + var moduleContents: [String] = [] + if buildSystem == .native { + moduleContents = (try? localFileSystem.getDirectoryContents(binPath.appending(component: "Modules"))) ?? [] + } else { + let moduleDirs = (try? localFileSystem.getDirectoryContents(binPath).filter { + $0.hasSuffix(".swiftmodule") + }) ?? [] + for dir: String in moduleDirs { + moduleContents += + (try? localFileSystem.getDirectoryContents(binPath.appending(component: dir)).map { "\(dir)/\($0)" }) ?? [] + } + } + + + if cleanAfterward { + try await executeSwiftPackage( + packagePath, + extraArgs: ["clean"], + buildSystem: buildSystem + ) + } + return BuildResult( + binPath: binPath, + stdout: stdout, + stderr: stderr, + binContents: binContents, + moduleContents: moduleContents + ) + } catch { + if cleanAfterward { + try await executeSwiftPackage( + packagePath, + extraArgs: ["clean"], + buildSystem: buildSystem + ) + } + throw error + } + } @Test( - arguments: getBuildData(for: SupportedBuildSystemOnPlatform), + arguments: SupportedBuildSystemOnPlatform, ) - func usage( - data: BuildData, - ) async throws { - let stdout = try await execute(["-help"], configuration: data.config, buildSystem: data.buildSystem).stdout + func usage(buildSystem: BuildSystemProvider.Kind) async throws { + let stdout = try await execute(["-help"], buildSystem: buildSystem).stdout #expect(stdout.contains("USAGE: swift build")) } @Test( - arguments: getBuildData(for: SupportedBuildSystemOnPlatform), + arguments: SupportedBuildSystemOnPlatform, BuildConfiguration.allCases ) func binSymlink( - buildData: BuildData, + buildSystem: BuildSystemProvider.Kind, + configuration: BuildConfiguration, ) async throws { - let buildSystem = buildData.buildSystem - let configuration = buildData.config // Test is not implemented for Xcode build system try await fixture(name: "ValidLayouts/SingleModule/ExecutableNew") { fixturePath in let fullPath = try resolveSymlinks(fixturePath) let targetPath = try fullPath.appending(components: buildSystem.binPath(for: configuration)) - let path = try await execute( - ["--show-bin-path"], - packagePath: fullPath, - configuration: configuration, - buildSystem: buildSystem, - ).stdout.trimmingCharacters(in: .whitespacesAndNewlines) + let path = try await self.execute(["--show-bin-path"], packagePath: fullPath, configuration: configuration, buildSystem: buildSystem).stdout.trimmingCharacters(in: .whitespacesAndNewlines) #expect( AbsolutePath(path).pathString == targetPath.pathString ) @@ -164,67 +175,44 @@ struct BuildCommandTestCases { } @Test( - arguments: getBuildData(for: SupportedBuildSystemOnPlatform), + arguments: SupportedBuildSystemOnPlatform, ) - func seeAlso( - data: BuildData, - ) async throws { - let stdout = try await execute( - ["--help"], - configuration: data.config, - buildSystem: data.buildSystem, - ).stdout + func seeAlso(buildSystem: BuildSystemProvider.Kind) async throws { + let stdout = try await execute(["--help"], buildSystem: buildSystem).stdout #expect(stdout.contains("SEE ALSO: swift run, swift package, swift test")) } @Test( - arguments: getBuildData(for: SupportedBuildSystemOnPlatform), + arguments: SupportedBuildSystemOnPlatform, ) - func commandDoesNotEmitDuplicateSymbols( - data: BuildData, - ) async throws { + func commandDoesNotEmitDuplicateSymbols(buildSystem: BuildSystemProvider.Kind) async throws { let duplicateSymbolRegex = try #require(duplicateSymbolRegex) - let (stdout, stderr) = try await execute( - ["--help"], - configuration: data.config, - buildSystem: data.buildSystem, - ) + let (stdout, stderr) = try await execute(["--help"], buildSystem: buildSystem) #expect(!stdout.contains(duplicateSymbolRegex)) #expect(!stderr.contains(duplicateSymbolRegex)) } @Test( - arguments: getBuildData(for: SupportedBuildSystemOnPlatform), + arguments: SupportedBuildSystemOnPlatform, ) - func version( - data: BuildData, - ) async throws { - let stdout = try await execute( - ["--version"], - configuration: data.config, - buildSystem: data.buildSystem, - ).stdout + func version(buildSystem: BuildSystemProvider.Kind) async throws { + let stdout = try await execute(["--version"], buildSystem: buildSystem).stdout let expectedRegex = try Regex(#"Swift Package Manager -( \w+ )?\d+.\d+.\d+(-\w+)?"#) #expect(stdout.contains(expectedRegex)) } @Test( - arguments: getBuildData(for: SupportedBuildSystemOnPlatform), + arguments: SupportedBuildSystemOnPlatform, ) - func importOfMissedDepWarning( - buildData: BuildData, - ) async throws { - let buildSystem = buildData.buildSystem - let configuration = buildData.config + func importOfMissedDepWarning(buildSystem: BuildSystemProvider.Kind) async throws { try await withKnownIssue("SWBINTTODO: Test fails because the warning message regarding missing imports is expected to be more verbose and actionable at the SwiftPM level with mention of the involved targets. This needs to be investigated. See case targetDiagnostic(TargetDiagnosticInfo) as a message type that may help.") { try await fixture(name: "Miscellaneous/ImportOfMissingDependency") { path in let fullPath = try resolveSymlinks(path) let error = await #expect(throws: SwiftPMError.self ) { - try await build( + try await self.build( ["--explicit-target-dependency-import-check=warn"], packagePath: fullPath, - configuration: configuration, buildSystem: buildSystem, ) } @@ -244,21 +232,16 @@ struct BuildCommandTestCases { } @Test( - arguments: getBuildData(for: SupportedBuildSystemOnPlatform), + arguments: SupportedBuildSystemOnPlatform, ) - func importOfMissedDepWarningVerifyingErrorFlow( - data: BuildData - ) async throws { - let buildSystem = data.buildSystem - let config = data.config + func importOfMissedDepWarningVerifyingErrorFlow(buildSystem: BuildSystemProvider.Kind) async throws { try await withKnownIssue("SWBINTTODO: Test fails because the warning message regarding missing imports is expected to be more verbose and actionable at the SwiftPM level with mention of the involved targets. This needs to be investigated. See case targetDiagnostic(TargetDiagnosticInfo) as a message type that may help.") { try await fixture(name: "Miscellaneous/ImportOfMissingDependency") { path in let fullPath = try resolveSymlinks(path) let error = await #expect(throws: SwiftPMError.self ) { - try await build( + try await self.build( ["--explicit-target-dependency-import-check=error"], packagePath: fullPath, - configuration: config, buildSystem: buildSystem, ) } @@ -278,20 +261,13 @@ struct BuildCommandTestCases { } @Test( - arguments: getBuildData(for: SupportedBuildSystemOnPlatform), + arguments: SupportedBuildSystemOnPlatform, ) - func importOfMissedDepWarningVerifyingDefaultDoesNotRunTheCheck( - data: BuildData, - ) async throws { + func importOfMissedDepWarningVerifyingDefaultDoesNotRunTheCheck(buildSystem: BuildSystemProvider.Kind) async throws { try await fixture(name: "Miscellaneous/ImportOfMissingDependency") { path in let fullPath = try resolveSymlinks(path) let error = await #expect(throws: SwiftPMError.self ) { - try await build( - [], - packagePath: fullPath, - configuration: data.config, - buildSystem: data.buildSystem, - ) + try await self.build([], packagePath: fullPath, buildSystem: buildSystem) } guard case SwiftPMError.executionFailure(_, _, let stderr) = try #require(error) else { Issue.record("Expected error did not occur") @@ -316,7 +292,7 @@ struct BuildCommandTestCases { try await fixture(name: "ValidLayouts/SingleModule/ExecutableNew") { fixturePath in let fullPath = try resolveSymlinks(fixturePath) // Test symlink. - try await execute(packagePath: fullPath, configuration: configuration, buildSystem: buildSystem) + try await self.execute(packagePath: fullPath, configuration: configuration, buildSystem: buildSystem) let actualDebug = try resolveSymlinks(fullPath.appending(components: buildSystem.binPath(for: configuration))) let expectedDebug = try fullPath.appending(components: buildSystem.binPath(for: configuration)) #expect(actualDebug == expectedDebug) @@ -327,88 +303,61 @@ struct BuildCommandTestCases { } @Test( - .IssueWindowsLongPath, - arguments: getBuildData(for: SupportedBuildSystemOnPlatform), + arguments: SupportedBuildSystemOnPlatform, ) func buildExistingExecutableProductIsSuccessfull( - data: BuildData, + buildSystem: BuildSystemProvider.Kind, ) async throws { - try await withKnownIssue("Failures possibly due to long file paths", isIntermittent: true) { + try await withKnownIssue("Failures possibly due to long file paths") { try await fixture(name: "Miscellaneous/MultipleExecutables") { fixturePath in let fullPath = try resolveSymlinks(fixturePath) - let result = try await build( - ["--product", "exec1"], - packagePath: fullPath, - configuration: data.config, - buildSystem: data.buildSystem, - ) + let result = try await build(["--product", "exec1"], packagePath: fullPath, buildSystem: buildSystem,) #expect(result.binContents.contains(executableName("exec1"))) #expect(!result.binContents.contains("exec2.build")) } } when: { - ProcessInfo.hostOperatingSystem == .windows && data.buildSystem == .swiftbuild + ProcessInfo.hostOperatingSystem == .windows && buildSystem == .swiftbuild } } @Test( - .issue("https://github.com/swiftlang/swift-package-manager/issues/9137", relationship: .defect), - .IssueWindowsCannotSaveAttachment, - arguments: getBuildData(for: SupportedBuildSystemOnPlatform), + .SWBINTTODO("Found multiple targets named 'lib1'"), + arguments: SupportedBuildSystemOnPlatform, ) func buildExistingLibraryProductIsSuccessfull( - data: BuildData, + buildSystem: BuildSystemProvider.Kind, ) async throws { - let buildSystem = data.buildSystem - try await withKnownIssue(isIntermittent: true) { + try await withKnownIssue("Found multiple targets named 'lib1'") { try await fixture(name: "Miscellaneous/MultipleExecutables") { fixturePath in let fullPath = try resolveSymlinks(fixturePath) - let (_, stderr) = try await execute( - ["--product", "lib1"], - packagePath: fullPath, - configuration: data.config, - buildSystem: buildSystem, - ) - switch buildSystem { - case .native, .swiftbuild: - withKnownIssue("Found multiple targets named 'lib1'") { - #expect( - stderr.contains( - "'--product' cannot be used with the automatic product 'lib1'; building the default target instead" - ) - ) - } when: { - .swiftbuild == buildSystem - } - case .xcode: - // Do nothing. - break + let (_, stderr) = try await execute(["--product", "lib1"], packagePath: fullPath, buildSystem: buildSystem,) + if buildSystem != .xcode { + #expect( + stderr.contains( + "'--product' cannot be used with the automatic product 'lib1'; building the default target instead" + ) + ) } } } when: { - ProcessInfo.hostOperatingSystem == .windows && buildSystem == .swiftbuild + .swiftbuild == buildSystem } } @Test( - .issue("https://github.com/swiftlang/swift-package-manager/issues/9138", relationship: .defect), - arguments: getBuildData(for: SupportedBuildSystemOnPlatform), + .SWBINTTODO("Could not find target named 'exec2'"), + arguments: SupportedBuildSystemOnPlatform, ) func buildExistingTargetIsSuccessfull( - data: BuildData, + buildSystem: BuildSystemProvider.Kind, ) async throws { - let buildSystem = data.buildSystem try await withKnownIssue("Could not find target named 'exec2'") { try await fixture(name: "Miscellaneous/MultipleExecutables") { fixturePath in let fullPath = try resolveSymlinks(fixturePath) - let result = try await build( - ["--target", "exec2"], - packagePath: fullPath, - configuration: data.config, - buildSystem: buildSystem, - ) + let result = try await build(["--target", "exec2"], packagePath: fullPath, buildSystem: buildSystem,) #expect(result.binContents.contains("exec2.build")) #expect(!result.binContents.contains(executableName("exec1"))) } @@ -421,18 +370,16 @@ struct BuildCommandTestCases { } @Test( - arguments: getBuildData(for: SupportedBuildSystemOnPlatform), + arguments: SupportedBuildSystemOnPlatform, ) func buildProductAndTargetsFailsWithAMutuallyExclusiveMessage( - buildData: BuildData, + buildSystem: BuildSystemProvider.Kind, ) async throws { try await fixture(name: "Miscellaneous/MultipleExecutables") { fixturePath in let error = await #expect(throws: SwiftPMError.self ) { - try await execute( - ["--product", "exec1", "--target", "exec2"], - packagePath: fixturePath, - configuration: buildData.config, - buildSystem: buildData.buildSystem, + try await self.execute( + ["--product", "exec1", "--target", "exec2"], + packagePath: fixturePath,buildSystem: buildSystem, ) } // THEN I expect a failure @@ -445,18 +392,16 @@ struct BuildCommandTestCases { } @Test( - arguments: getBuildData(for: SupportedBuildSystemOnPlatform), + arguments: SupportedBuildSystemOnPlatform, ) func buildProductAndTestsFailsWithAMutuallyExclusiveMessage( - buildData: BuildData, + buildSystem: BuildSystemProvider.Kind, ) async throws { try await fixture(name: "Miscellaneous/MultipleExecutables") { fixturePath in let error = await #expect(throws: SwiftPMError.self ) { - try await execute( - ["--product", "exec1", "--build-tests"], - packagePath: fixturePath, - configuration: buildData.config, - buildSystem: buildData.buildSystem, + try await self.execute( + ["--product", "exec1", "--build-tests"], + packagePath: fixturePath,buildSystem: buildSystem, ) } // THEN I expect a failure @@ -469,18 +414,16 @@ struct BuildCommandTestCases { } @Test( - arguments: getBuildData(for: SupportedBuildSystemOnPlatform), + arguments: SupportedBuildSystemOnPlatform, ) func buildTargetAndTestsFailsWithAMutuallyExclusiveMessage( - data: BuildData, + buildSystem: BuildSystemProvider.Kind, ) async throws { try await fixture(name: "Miscellaneous/MultipleExecutables") { fixturePath in let error = await #expect(throws: SwiftPMError.self ) { - try await execute( - ["--build-tests", "--target", "exec2"], - packagePath: fixturePath, - configuration: data.config, - buildSystem: data.buildSystem, + try await self.execute( + ["--build-tests", "--target", "exec2"], + packagePath: fixturePath,buildSystem: buildSystem, ) } // THEN I expect a failure @@ -493,18 +436,16 @@ struct BuildCommandTestCases { } @Test( - arguments: getBuildData(for: SupportedBuildSystemOnPlatform), + arguments: SupportedBuildSystemOnPlatform, ) func buildProductTargetAndTestsFailsWithAMutuallyExclusiveMessage( - data: BuildData, + buildSystem: BuildSystemProvider.Kind, ) async throws { try await fixture(name: "Miscellaneous/MultipleExecutables") { fixturePath in let error = await #expect(throws: SwiftPMError.self ) { - try await execute( - ["--build-tests", "--target", "exec2", "--product", "exec1"], - packagePath: fixturePath, - configuration: data.config, - buildSystem: data.buildSystem, + try await self.execute( + ["--build-tests", "--target", "exec2", "--product", "exec1"], + packagePath: fixturePath,buildSystem: buildSystem, ) } // THEN I expect a failure @@ -512,32 +453,22 @@ struct BuildCommandTestCases { Issue.record("Incorrect error was raised.") return } - withKnownIssue(isIntermittent: true) { - #expect(stderr.contains("error: '--product', '--target', and '--build-tests' are mutually exclusive"), "stout: \(stdout)") - } when: { - ( - ProcessInfo.hostOperatingSystem == .windows && ( - data.buildSystem == .native - || (data.buildSystem == .swiftbuild && data.config == .debug) - )) - } + #expect(stderr.contains("error: '--product', '--target', and '--build-tests' are mutually exclusive")) } } @Test( - arguments: getBuildData(for: SupportedBuildSystemOnPlatform), + arguments: SupportedBuildSystemOnPlatform, ) func buildUnknownProductFailsWithAppropriateMessage( - data: BuildData, + buildSystem: BuildSystemProvider.Kind, ) async throws { try await fixture(name: "Miscellaneous/MultipleExecutables") { fixturePath in let productName = "UnknownProduct" let error = await #expect(throws: SwiftPMError.self ) { - try await execute( - ["--product", productName], - packagePath: fixturePath, - configuration: data.config, - buildSystem: data.buildSystem, + try await self.execute( + ["--product", productName], + packagePath: fixturePath,buildSystem: buildSystem, ) } // THEN I expect a failure @@ -546,34 +477,30 @@ struct BuildCommandTestCases { return } - switch data.buildSystem { - case .native: - #expect(stderr.contains("error: no product named '\(productName)'")) - case .swiftbuild, .xcode: - let expectedErrorMessageRegex = try Regex("error: Could not find target named '\(productName).*'") - #expect( - stderr.contains(expectedErrorMessageRegex), - "expect log not emitted.\nstdout: '\(stdout)'\n\nstderr: '\(stderr)'", - ) + if .native == buildSystem { + #expect(stderr.contains("error: no product named '\(productName)'")) + } else { + let expectedErrorMessageRegex = try Regex("error: Could not find target named '\(productName).*'") + #expect( + stderr.contains(expectedErrorMessageRegex), + "expect log not emitted.\nstdout: '\(stdout)'\n\nstderr: '\(stderr)'", + ) } } } @Test( - arguments: getBuildData(for: SupportedBuildSystemOnPlatform), + arguments: SupportedBuildSystemOnPlatform, ) func buildUnknownTargetFailsWithAppropriateMessage( - data: BuildData, + buildSystem: BuildSystemProvider.Kind, ) async throws { try await fixture(name: "Miscellaneous/MultipleExecutables") { fixturePath in - let buildSystem = data.buildSystem let targetName = "UnknownTargetName" let error = await #expect(throws: SwiftPMError.self ) { - try await execute( - ["--target", targetName], - packagePath: fixturePath, - configuration: data.config, - buildSystem: buildSystem, + try await self.execute( + ["--target", targetName], + packagePath: fixturePath,buildSystem: buildSystem, ) } // THEN I expect a failure @@ -582,11 +509,10 @@ struct BuildCommandTestCases { return } let expectedErrorMessage: String - switch buildSystem { - case .native: - expectedErrorMessage = "error: no target named '\(targetName)'" - case .swiftbuild, .xcode: - expectedErrorMessage = "error: Could not find target named '\(targetName)'" + if .native == buildSystem { + expectedErrorMessage = "error: no target named '\(targetName)'" + } else { + expectedErrorMessage = "error: Could not find target named '\(targetName)'" } #expect( stderr.contains(expectedErrorMessage), @@ -596,43 +522,43 @@ struct BuildCommandTestCases { } @Test( - arguments: getBuildData(for: SupportedBuildSystemOnPlatform), ["ClangExecSingleFile", "SwiftExecSingleFile", "SwiftExecMultiFile"], + arguments: SupportedBuildSystemOnPlatform, ) - func atMainSupport( - data: BuildData, - executable: String, - ) async throws { - let buildSystem = data.buildSystem - let config = data.config - try await withKnownIssue( - "SWBINTTODO: File not found or missing libclang errors on non-macOS platforms. This needs to be investigated", - isIntermittent: true, - ) { + func atMainSupport(buildSystem: BuildSystemProvider.Kind) async throws { + try await withKnownIssue("SWBINTTODO: File not found or missing libclang errors on non-macOS platforms. This needs to be investigated") { try await fixture(name: "Miscellaneous/AtMainSupport") { fixturePath in let fullPath = try resolveSymlinks(fixturePath) - let result = try await build(["--product", executable], packagePath: fullPath, configuration: config, buildSystem: buildSystem) - #expect(result.binContents.contains(executableName(executable))) + + do { + let result = try await build(["--product", "ClangExecSingleFile"], packagePath: fullPath, buildSystem: buildSystem) + #expect(result.binContents.contains(executableName("ClangExecSingleFile"))) + } + + do { + let result = try await build(["--product", "SwiftExecSingleFile"], packagePath: fullPath, buildSystem: buildSystem) + #expect(result.binContents.contains(executableName("SwiftExecSingleFile"))) + } + + do { + let result = try await build(["--product", "SwiftExecMultiFile"], packagePath: fullPath, buildSystem: buildSystem) + #expect(result.binContents.contains(executableName("SwiftExecMultiFile"))) + } } } when: { - ProcessInfo.hostOperatingSystem == .windows && buildSystem == .swiftbuild + ![.macOS, .linux].contains(ProcessInfo.hostOperatingSystem) && buildSystem == .swiftbuild } } @Test( - arguments: getBuildData(for: SupportedBuildSystemOnPlatform), + arguments: SupportedBuildSystemOnPlatform, ) func nonReachableProductsAndTargetsFunctional( - data: BuildData, + buildSystem: BuildSystemProvider.Kind, ) async throws { try await fixture(name: "Miscellaneous/UnreachableTargets") { fixturePath in let aPath = fixturePath.appending("A") - let result = try await build( - [], - packagePath: aPath, - configuration: data.config, - buildSystem: data.buildSystem, - ) + let result = try await build([], packagePath: aPath, buildSystem: buildSystem) #expect(!result.binContents.contains("bexec")) #expect(!result.binContents.contains("BTarget2.build")) #expect(!result.binContents.contains("cexec")) @@ -641,24 +567,20 @@ struct BuildCommandTestCases { } @Test( - arguments: getBuildData(for: SupportedBuildSystemOnAllPlatforms), + arguments: SupportedBuildSystemOnPlatform, ) func nonReachableProductsAndTargetsFunctionalWhereDependencyContainsADependentProducts( - data: BuildData, + buildSystem: BuildSystemProvider.Kind, ) async throws { - let buildSystem = data.buildSystem + // skipped on Xcode + // known failures in SwiftBuild try await withKnownIssue("SWBINTTODO: Test failed. This needs to be investigated") { try await fixture(name: "Miscellaneous/UnreachableTargets") { fixturePath in let aPath = fixturePath.appending("A") // Dependency contains a dependent product - let result = try await build( - ["--product", "bexec"], - packagePath: aPath, - configuration: data.config, - buildSystem: buildSystem, - ) + let result = try await build(["--product", "bexec"], packagePath: aPath, buildSystem: buildSystem) #expect(result.binContents.contains("BTarget2.build")) #expect(result.binContents.contains(executableName("bexec"))) #expect(!result.binContents.contains(executableName("aexec"))) @@ -682,35 +604,28 @@ struct BuildCommandTestCases { #expect(!result.moduleContents.contains("CTarget.swiftinterface")) } } when: { - buildSystem == .swiftbuild + buildSystem != .native } } @Test( - .issue("https://github.com/swiftlang/swift-package-manager/pull/9130", relationship: .fixedBy), - arguments: getBuildData(for: SupportedBuildSystemOnPlatform), + arguments: SupportedBuildSystemOnPlatform, ) func parseableInterfaces( - data: BuildData, + buildSystem: BuildSystemProvider.Kind, ) async throws { - let buildSystem = data.buildSystem try await fixture(name: "Miscellaneous/ParseableInterfaces") { fixturePath in - try await withKnownIssue(isIntermittent: ProcessInfo.hostOperatingSystem == .windows) { - let result = try await build( - ["--enable-parseable-module-interfaces"], - packagePath: fixturePath, - configuration: data.config, - buildSystem: buildSystem, - ) + try await withKnownIssue { + let result = try await build(["--enable-parseable-module-interfaces"], packagePath: fixturePath, buildSystem: buildSystem) switch buildSystem { case .native: #expect(result.moduleContents.contains("A.swiftinterface")) #expect(result.moduleContents.contains("B.swiftinterface")) - case .swiftbuild, .xcode: - let moduleARegex = try Regex(#"A[.]swiftmodule[/].*[.]swiftinterface"#) - let moduleBRegex = try Regex(#"B[.]swiftmodule[/].*[.]swiftmodule"#) - #expect(result.moduleContents.contains { $0.contains(moduleARegex) }) - #expect(result.moduleContents.contains { $0.contains(moduleBRegex) }) + default: + let moduleARegex = try Regex(#"A[.]swiftmodule[/].*[.]swiftinterface"#) + let moduleBRegex = try Regex(#"B[.]swiftmodule[/].*[.]swiftmodule"#) + #expect(result.moduleContents.contains { $0.contains(moduleARegex) }) + #expect(result.moduleContents.contains { $0.contains(moduleBRegex) }) } } when: { // errors with SwiftBuild on Windows possibly due to long path on windows only for swift build @@ -720,25 +635,19 @@ struct BuildCommandTestCases { } @Test( - arguments: getBuildData(for: SupportedBuildSystemOnPlatform), + arguments: SupportedBuildSystemOnPlatform, ) func automaticParseableInterfacesWithLibraryEvolution( - data: BuildData, + buildSystem: BuildSystemProvider.Kind, ) async throws { - let buildSystem = data.buildSystem try await withKnownIssue { try await fixture(name: "Miscellaneous/LibraryEvolution") { fixturePath in - let result = try await build( - [], - packagePath: fixturePath, - configuration: data.config, - buildSystem: buildSystem, - ) + let result = try await build([], packagePath: fixturePath, buildSystem: buildSystem) switch buildSystem { case .native: #expect(result.moduleContents.contains("A.swiftinterface")) #expect(result.moduleContents.contains("B.swiftinterface")) - case .swiftbuild, .xcode: + default: let moduleARegex = try Regex(#"A[.]swiftmodule[/].*[.]swiftinterface"#) let moduleBRegex = try Regex(#"B[.]swiftmodule[/].*[.]swiftmodule"#) withKnownIssue("SWBINTTODO: Test failed because of missing 'A.swiftmodule/*.swiftinterface' files") { @@ -755,21 +664,16 @@ struct BuildCommandTestCases { } @Test( - arguments: getBuildData(for: SupportedBuildSystemOnPlatform), + arguments: SupportedBuildSystemOnPlatform, ) func buildCompleteMessage( - data: BuildData, + buildSystem: BuildSystemProvider.Kind, ) async throws { - let buildSystem = data.buildSystem try await withKnownIssue { try await fixture(name: "DependencyResolution/Internal/Simple") { fixturePath in let buildCompleteRegex = try Regex(#"Build complete!\s?(\([0-9]*\.[0-9]*\s*s(econds)?\))?"#) do { - let result = try await execute( - packagePath: fixturePath, - configuration: data.config, - buildSystem: buildSystem, - ) + let result = try await execute(packagePath: fixturePath, buildSystem: buildSystem) // This test fails to match the 'Compiling' regex; rdar://101815761 // XCTAssertMatch(result.stdout, .regex("\\[[1-9][0-9]*\\/[1-9][0-9]*\\] Compiling")) let lines = result.stdout.split(whereSeparator: { $0.isNewline }) @@ -779,20 +683,12 @@ struct BuildCommandTestCases { do { // test second time, to stabilize the cache - try await execute( - packagePath: fixturePath, - configuration: data.config, - buildSystem: buildSystem, - ) + try await self.execute(packagePath: fixturePath, buildSystem: buildSystem) } do { // test third time, to make sure message is presented even when nothing to build (cached) - let result = try await execute( - packagePath: fixturePath, - configuration: data.config, - buildSystem: buildSystem, - ) + let result = try await execute(packagePath: fixturePath, buildSystem: buildSystem) // This test fails to match the 'Compiling' regex; rdar://101815761 // XCTAssertNoMatch(result.stdout, .regex("\\[[1-9][0-9]*\\/[1-9][0-9]*\\] Compiling")) let lines = result.stdout.split(whereSeparator: { $0.isNewline }) @@ -801,18 +697,17 @@ struct BuildCommandTestCases { } } } when: { - buildSystem == .swiftbuild && (ProcessInfo.hostOperatingSystem == .windows) + buildSystem == .swiftbuild && ((ProcessInfo.hostOperatingSystem == .windows)) } } @Test( - arguments: getBuildData(for: SupportedBuildSystemOnPlatform), + arguments: SupportedBuildSystemOnPlatform, BuildConfiguration.allCases, ) func buildStartMessage( - data: BuildData, + buildSystem: BuildSystemProvider.Kind, + configuration: BuildConfiguration, ) async throws { - let buildSystem = data.buildSystem - let configuration = data.config try await fixture(name: "DependencyResolution/Internal/Simple") { fixturePath in let result = try await execute([], packagePath: fixturePath, configuration: configuration, buildSystem: buildSystem, throwIfCommandFails: false) let expectedString: String @@ -823,27 +718,22 @@ struct BuildCommandTestCases { expectedString = "production" } - switch buildSystem { - case .native, .swiftbuild: - #expect( - result.stdout.contains("Building for \(expectedString)"), - "expect log not emitted. got stdout: '\(result.stdout)'\n\nstderr '\(result.stderr)'", - ) - case .xcode: - // Xcode build system does not emit the build started message. - break + withKnownIssue("Xcode build system does not emit the build started message.") { + #expect( + result.stdout.contains("Building for \(expectedString)"), + "expect log not emitted. got stdout: '\(result.stdout)'\n\nstderr '\(result.stderr)'") + } when: { + buildSystem == .xcode } } } @Test( - .IssueWindowsLongPath, - arguments: getBuildData(for: SupportedBuildSystemOnPlatform), + arguments: SupportedBuildSystemOnPlatform, ) func buildSystemDefaultSettings( - data: BuildData, + buildSystem: BuildSystemProvider.Kind, ) async throws { - let buildSystem = data.buildSystem try await withKnownIssue("Sometimes failed to build due to a possible path issue", isIntermittent: true) { try await fixture(name: "ValidLayouts/SingleModule/ExecutableNew") { fixturePath in // try await building using XCBuild with default parameters. This should succeed. We build verbosely so we get @@ -851,7 +741,7 @@ struct BuildCommandTestCases { let output: (stdout: String, stderr: String) = try await execute( ["-v"], packagePath: fixturePath, - configuration: data.config, + configuration: .debug, buildSystem: buildSystem, ) @@ -867,20 +757,18 @@ struct BuildCommandTestCases { #expect(output.stdout.contains("Build complete!")) } } when: { - (buildSystem == .swiftbuild && ProcessInfo.hostOperatingSystem == .windows) - || (buildSystem == .native && data.config == .release && ProcessInfo.hostOperatingSystem == .windows) + buildSystem == .swiftbuild && ProcessInfo.hostOperatingSystem == .windows } } @Test( .disabled("Disabled for now because it is hitting 'IR generation failure: Cannot read legacy layout file' in CI (rdar://88828632)"), - arguments: getBuildData(for: [BuildSystemProvider.Kind.swiftbuild, .xcode]), + arguments: [BuildSystemProvider.Kind.swiftbuild, .xcode], BuildConfiguration.allCases ) func xcodeBuildSystemWithAdditionalBuildFlags( - data: BuildData + buildSystem: BuildSystemProvider.Kind, + configuration: BuildConfiguration ) async throws { - let configuration = data.config - let buildSystem = data.buildSystem try await fixture(name: "ValidLayouts/SingleModule/ExecutableMixed") { fixturePath in // try await building using XCBuild with additional flags. This should succeed. We build verbosely so we get // full command lines. @@ -907,22 +795,20 @@ struct BuildCommandTestCases { @Test( .requireHostOS(.macOS), - arguments: getBuildData(for: [BuildSystemProvider.Kind.swiftbuild, .xcode]), + arguments: [BuildSystemProvider.Kind.xcode], ) func buildSystemOverrides( - data: BuildData, + buildSystem: BuildSystemProvider.Kind, ) async throws { - let buildSystem = data.buildSystem - let config = data.config try await withKnownIssue { try await fixture(name: "ValidLayouts/SingleModule/ExecutableNew") { fixturePath in let swiftCompilerPath = try UserToolchain.default.swiftCompilerPath // try await building without specifying overrides. This should succeed, and should use the default // compiler path. - let defaultOutput = try await execute( + let defaultOutput = try await self.execute( ["--vv"], packagePath: fixturePath, - configuration: config, + configuration: .debug, buildSystem: buildSystem, ).stdout #expect(defaultOutput.contains(swiftCompilerPath.pathString)) @@ -931,14 +817,14 @@ struct BuildCommandTestCases { // we need to set the executable to use for the manifest itself to the default one, since it defaults to // SWIFT_EXEC if not provided. let error = await #expect(throws: SwiftPMError.self ) { - try await execute( + try await self.execute( ["--vv"], environment: [ "SWIFT_EXEC": "/usr/bin/false", "SWIFT_EXEC_MANIFEST": swiftCompilerPath.pathString, ], packagePath: fixturePath, - configuration: config, + configuration: .debug, buildSystem: buildSystem, ) } @@ -955,13 +841,12 @@ struct BuildCommandTestCases { } @Test( - arguments: getBuildData(for: SupportedBuildSystemOnPlatform), + arguments: SupportedBuildSystemOnPlatform, BuildConfiguration.allCases ) func printLLBuildManifestJobGraph( - data: BuildData, + buildSystem: BuildSystemProvider.Kind, + configuration: BuildConfiguration ) async throws { - let buildSystem = data.buildSystem - let configuration = data.config try await fixture(name: "DependencyResolution/Internal/Simple") { fixturePath in let output = try await execute( ["--print-manifest-job-graph"], @@ -1011,13 +896,12 @@ struct BuildCommandTestCases { @Test( .bug("https://github.com/swiftlang/swift-package-manager/issues/8659", "SWIFT_EXEC override is not working"), .SWBINTTODO("Test fails because the dummy-swiftc used in the test isn't accepted by swift-build. This needs to be investigated"), - arguments: getBuildData(for: SupportedBuildSystemOnPlatform), + arguments: SupportedBuildSystemOnPlatform, ) func swiftGetVersion( - data: BuildData, + buildSystem: BuildSystemProvider.Kind, ) async throws { - let buildSystem = data.buildSystem - let config = data.config + try await fixture(name: "Miscellaneous/Simple") { fixturePath in func findSwiftGetVersionFile() throws -> AbsolutePath { let buildArenaPath = fixturePath.appending(components: ".build", "debug") @@ -1035,20 +919,13 @@ struct BuildCommandTestCases { "CUSTOM_SWIFT_VERSION": "1.0", ] - try await withKnownIssue( - "https://github.com/swiftlang/swift-package-manager/issues/8659, SWIFT_EXEC override is not working", - isIntermittent: (buildSystem == .native && config == .release) - ){ + try await withKnownIssue("https://github.com/swiftlang/swift-package-manager/issues/8659, SWIFT_EXEC override is not working"){ + + // Build with a swiftc that returns version 1.0, we expect a successful build which compiles our one source // file. do { - let result = try await execute( - ["--verbose"], - environment: environment, - packagePath: fixturePath, - configuration: config, - buildSystem: buildSystem, - ) + let result = try await execute(["--verbose"], environment: environment, packagePath: fixturePath, buildSystem: buildSystem) #expect( result.stdout.contains("\(dummySwiftcPath.pathString) -module-name"), "compilation task missing from build result: \(result.stdout)", @@ -1065,13 +942,7 @@ struct BuildCommandTestCases { // Build again with that same version, we do not expect any compilation tasks. do { - let result = try await execute( - ["--verbose"], - environment: environment, - packagePath: fixturePath, - configuration: config, - buildSystem: buildSystem, - ) + let result = try await execute(["--verbose"], environment: environment, packagePath: fixturePath, buildSystem: buildSystem) #expect( !result.stdout.contains("\(dummySwiftcPath.pathString) -module-name"), "compilation task present in build result: \(result.stdout)", @@ -1089,13 +960,7 @@ struct BuildCommandTestCases { // Build again with a swiftc that returns version 2.0, we expect compilation happening once more. do { environment["CUSTOM_SWIFT_VERSION"] = "2.0" - let result = try await execute( - ["--verbose"], - environment: environment, - packagePath: fixturePath, - configuration: config, - buildSystem: buildSystem, - ) + let result = try await execute(["--verbose"], environment: environment, packagePath: fixturePath, buildSystem: buildSystem) #expect( result.stdout.contains("\(dummySwiftcPath.pathString) -module-name"), "compilation task missing from build result: \(result.stdout)", @@ -1110,9 +975,7 @@ struct BuildCommandTestCases { #expect(actualVersion == "2.0") } } when: { - (ProcessInfo.hostOperatingSystem == .windows) - || ([.xcode, .swiftbuild].contains(buildSystem)) - || (buildSystem == .native && config == .release) + (ProcessInfo.hostOperatingSystem == .windows) || ([.xcode, .swiftbuild].contains(buildSystem)) } } } @@ -1129,18 +992,18 @@ struct BuildCommandTestCases { #if os(macOS) // try await building with default parameters. This should succeed. We build verbosely so we get full command // lines. - var buildResult = try await build(["-v"], packagePath: fixturePath, configuration: .debug, buildSystem: buildSystem,) + var buildResult = try await build(["-v"], packagePath: fixturePath, buildSystem: buildSystem,) // TODO verification of the ad-hoc code signing can be done by `swift run` of the executable in these cases once swiftbuild build system is working with that #expect(buildResult.stdout.contains("codesign --force --sign - --entitlements")) - buildResult = try await build(["-v"], packagePath: fixturePath, configuration:.debug, buildSystem: buildSystem,) + buildResult = try await self.build(["-v"], packagePath: fixturePath, configuration:.debug, buildSystem: buildSystem,) #expect(buildResult.stdout.contains("codesign --force --sign - --entitlements")) // Build with different combinations of the entitlement flag and debug/release build configurations. - buildResult = try await build( + buildResult = try await self.build( ["--enable-get-task-allow-entitlement", "-v"], packagePath: fixturePath, configuration: .release, @@ -1149,7 +1012,7 @@ struct BuildCommandTestCases { #expect(buildResult.stdout.contains("codesign --force --sign - --entitlements")) - buildResult = try await build( + buildResult = try await self.build( ["--enable-get-task-allow-entitlement", "-v"], packagePath: fixturePath, configuration: .debug, @@ -1158,7 +1021,7 @@ struct BuildCommandTestCases { #expect(buildResult.stdout.contains("codesign --force --sign - --entitlements")) - buildResult = try await build( + buildResult = try await self.build( ["--disable-get-task-allow-entitlement", "-v"], packagePath: fixturePath, configuration: .debug, @@ -1167,7 +1030,7 @@ struct BuildCommandTestCases { #expect(!buildResult.stdout.contains("codesign --force --sign - --entitlements")) - buildResult = try await build( + buildResult = try await self.build( ["--disable-get-task-allow-entitlement", "-v"], packagePath: fixturePath, configuration: .release, @@ -1176,15 +1039,15 @@ struct BuildCommandTestCases { #expect(!buildResult.stdout.contains("codesign --force --sign - --entitlements")) #else - var buildResult = try await build(["-v"], packagePath: fixturePath, configuration: .debug, buildSystem: buildSystem,) + var buildResult = try await self.build(["-v"], packagePath: fixturePath, buildSystem: buildSystem,) #expect(!buildResult.stdout.contains("codesign --force --sign - --entitlements")) - buildResult = try await build(["-v"], packagePath: fixturePath, configuration: .release,buildSystem: buildSystem,) + buildResult = try await self.build(["-v"], packagePath: fixturePath, configuration: .release,buildSystem: buildSystem,) #expect(!buildResult.stdout.contains("codesign --force --sign - --entitlements")) - buildResult = try await build( + buildResult = try await self.build( ["--disable-get-task-allow-entitlement", "-v"], packagePath: fixturePath, configuration: .release, @@ -1194,7 +1057,7 @@ struct BuildCommandTestCases { #expect(!buildResult.stdout.contains("codesign --force --sign - --entitlements")) #expect(buildResult.stderr.contains(SwiftCommandState.entitlementsMacOSWarning)) - buildResult = try await build( + buildResult = try await self.build( ["--enable-get-task-allow-entitlement", "-v"], packagePath: fixturePath, configuration: .release, @@ -1205,7 +1068,7 @@ struct BuildCommandTestCases { #expect(buildResult.stderr.contains(SwiftCommandState.entitlementsMacOSWarning)) #endif - buildResult = try await build(["-v"], packagePath: fixturePath, configuration: .release, buildSystem: buildSystem) + buildResult = try await self.build(["-v"], packagePath: fixturePath, configuration: .release, buildSystem: buildSystem) #expect(!buildResult.stdout.contains("codesign --force --sign - --entitlements")) } @@ -1217,134 +1080,229 @@ struct BuildCommandTestCases { @Test( .requireHostOS(.linux), .SWBINTTODO("Swift build doesn't currently ignore Linux main when linking on Linux. This needs further investigation."), - arguments: getBuildData(for: SupportedBuildSystemOnPlatform), + arguments: SupportedBuildSystemOnPlatform, BuildConfiguration.allCases, ) func ignoresLinuxMain( - data: BuildData, + buildSystem: BuildSystemProvider.Kind, + configuration: BuildConfiguration, ) async throws { - let buildSystem = data.buildSystem - let configuration = data.config - try await fixture(name: "Miscellaneous/TestDiscovery/IgnoresLinuxMain") { fixturePath in - let buildResult = try await build( - ["-v", "--build-tests", "--enable-test-discovery"], - packagePath: fixturePath, - configuration: configuration, - cleanAfterward: false, - buildSystem: buildSystem, - ) - let testBinaryPath = buildResult.binPath.appending("IgnoresLinuxMainPackageTests.xctest") + try await withKnownIssue { + try await fixture(name: "Miscellaneous/TestDiscovery/IgnoresLinuxMain") { fixturePath in + let buildResult = try await self.build( + ["-v", "--build-tests", "--enable-test-discovery"], + packagePath: fixturePath, + configuration: configuration, + cleanAfterward: false, + buildSystem: buildSystem, + ) + let testBinaryPath = buildResult.binPath.appending("IgnoresLinuxMainPackageTests.xctest") - switch buildSystem { - case .native: - expectFileExists(at: testBinaryPath) - _ = try await AsyncProcess.checkNonZeroExit(arguments: [testBinaryPath.pathString]) - case .swiftbuild: - // there are no additional check - break - case .xcode: - Issue.record("Test expectations have not been implemented.") + _ = try await AsyncProcess.checkNonZeroExit(arguments: [testBinaryPath.pathString]) } + } when: { + buildSystem == .swiftbuild } } - @Test( - arguments: getBuildData(for: SupportedBuildSystemOnPlatform),[ - ["--verbose"], - ["-Xswiftc", "-diagnostic-style=llvm"], - ] - ) - func doesNotRebuildWithFlags( - data: BuildData, - flags: [String], - ) async throws { - func buildSystemAndOutputLocation( - buildSystem: BuildSystemProvider.Kind, - configuration: BuildConfiguration, - ) throws -> Basics.RelativePath { + private static func buildSystemAndOutputLocation() throws -> [(BuildSystemProvider.Kind, Basics.RelativePath)] { + return try SupportedBuildSystemOnPlatform.map { buildSystem in let triple = try UserToolchain.default.targetTriple.withoutVersion() let base = try RelativePath(validating: ".build") - let path = try base.appending(components: buildSystem.binPath(for: configuration, scratchPath: [])) + let path = try base.appending(components: buildSystem.binPath(for: .debug, scratchPath: [])) switch buildSystem { case .xcode: - return triple.platformName() == "macosx" ? path.appending("ExecutableNew") : path + return ( + buildSystem, + triple.platformName() == "macosx" ? path.appending("ExecutableNew") : path .appending("ExecutableNew.swiftmodule") .appending("Project") .appending("\(triple).swiftsourceinfo") + ) case .swiftbuild: - return triple.platformName() == "macosx" ? path.appending("ExecutableNew") : path + return ( + buildSystem, + triple.platformName() == "macosx" ? path.appending("ExecutableNew") : path .appending("ExecutableNew.swiftmodule") .appending("Project") .appending("\(triple).swiftsourceinfo") + ) case .native: - return path.appending("ExecutableNew.build") + return ( + buildSystem, + path.appending("ExecutableNew.build") .appending("main.swift.o") + ) + } + } + } + + @Test(arguments: try buildSystemAndOutputLocation()) + func doesNotRebuildWithVerboseFlag( + buildSystem: BuildSystemProvider.Kind, + outputFile: Basics.RelativePath + ) async throws { + try await withKnownIssue("Sometimes failed to build due to a possible path issue", isIntermittent: true) { + try await fixture(name: "ValidLayouts/SingleModule/ExecutableNew") { fixturePath in + _ = try await self.build( + [], + packagePath: fixturePath, + cleanAfterward: false, + buildSystem: buildSystem, + ) + + let mainOFile = fixturePath.appending(outputFile) + let initialMainOMtime = try FileManager.default.attributesOfItem(atPath: mainOFile.pathString)[.modificationDate] as? Date + + _ = try await self.build( + ["--verbose"], + packagePath: fixturePath, + cleanAfterward: false, + buildSystem: buildSystem, + ) + + let subsequentMainOMtime = try FileManager.default.attributesOfItem(atPath: mainOFile.pathString)[.modificationDate] as? Date + #expect(initialMainOMtime == subsequentMainOMtime, "Expected no rebuild to occur when using the verbose flag, but the file was modified.") } + } when: { + buildSystem == .swiftbuild && ProcessInfo.hostOperatingSystem == .windows } + } + @Test(arguments: try buildSystemAndOutputLocation()) + func doesNotRebuildWithSwiftcArgsThatDontAffectIncrementalBuilds( + buildSystem: BuildSystemProvider.Kind, + outputFile: Basics.RelativePath + ) async throws { try await withKnownIssue("Sometimes failed to build due to a possible path issue", isIntermittent: true) { try await fixture(name: "ValidLayouts/SingleModule/ExecutableNew") { fixturePath in - _ = try await build( + _ = try await self.build( [], packagePath: fixturePath, - configuration: data.config, cleanAfterward: false, - buildSystem: data.buildSystem, + buildSystem: buildSystem, ) - let mainOFile = try fixturePath.appending(buildSystemAndOutputLocation(buildSystem: data.buildSystem, configuration: data.config)) + + let mainOFile = fixturePath.appending(outputFile) let initialMainOMtime = try FileManager.default.attributesOfItem(atPath: mainOFile.pathString)[.modificationDate] as? Date - _ = try await build( - flags, + _ = try await self.build( + ["-Xswiftc", "-diagnostic-style=llvm"], packagePath: fixturePath, - configuration: data.config, cleanAfterward: false, - buildSystem: data.buildSystem, + buildSystem: buildSystem, ) let subsequentMainOMtime = try FileManager.default.attributesOfItem(atPath: mainOFile.pathString)[.modificationDate] as? Date - #expect(initialMainOMtime == subsequentMainOMtime, "Expected no rebuild to occur when using flags \(flags), but the file was modified.") + #expect(initialMainOMtime == subsequentMainOMtime, "Expected no rebuild to occur when supplying -diagnostic-style, but the file was modified.") + } + } when: { + buildSystem == .swiftbuild && ProcessInfo.hostOperatingSystem == .windows + } + } + + @Test( + .SWBINTTODO("Test failed because of missing plugin support in the PIF builder. This can be reinvestigated after the support is there."), + .tags( + Tag.Feature.CodeCoverage, + Tag.Feature.Command.Test, + ), + arguments: SupportedBuildSystemOnPlatform, + ) + func executingTestsWithCoverageWithoutCodeBuiltWithCoverageGeneratesAFailure( + buildSystem: BuildSystemProvider.Kind, + ) async throws { + try await withKnownIssue(isIntermittent: (ProcessInfo.hostOperatingSystem == .linux && buildSystem == .swiftbuild)) { + try await fixture(name: "Miscellaneous/TestDiscovery/Simple") { path in + _ = try await self.build( + ["--build-tests"], + packagePath: path, + cleanAfterward: false, + buildSystem: buildSystem, + ) + await #expect(throws: (any Error).self ) { + try await executeSwiftTest( + path, + extraArgs: [ + "--skip-build", + "--enable-code-coverage", + ], + throwIfCommandFails: true, + buildSystem: buildSystem, + ) + } } } when: { - data.buildSystem == .swiftbuild && ProcessInfo.hostOperatingSystem == .windows + buildSystem == .xcode || (buildSystem == .swiftbuild && [.linux, .windows].contains(ProcessInfo.hostOperatingSystem)) } } @Test( - arguments: getBuildData(for: SupportedBuildSystemOnAllPlatforms), + .SWBINTTODO("Test failed because of missing plugin support in the PIF builder. This can be reinvestigated after the support is there."), + .tags( + Tag.Feature.CodeCoverage, + Tag.Feature.Command.Test, + ), + arguments: SupportedBuildSystemOnPlatform, ) - func parseAsLibraryCriteria( - buildData: BuildData, + func executingTestsWithCoverageWithCodeBuiltWithCoverageGeneratesCodecove( + buildSystem: BuildSystemProvider.Kind, ) async throws { + // Test that enabling code coverage during building produces the expected folder. try await withKnownIssue { - try await fixture(name: "Miscellaneous/ParseAsLibrary") { fixturePath in + try await fixture(name: "Miscellaneous/TestDiscovery/Simple") { path in + let buildResult = try await self.build( + ["--build-tests", "--enable-code-coverage"], + packagePath: path, + cleanAfterward: false, + buildSystem: buildSystem, + ) + try await executeSwiftTest( + path, + extraArgs: [ + "--skip-build", + "--enable-code-coverage", + ], + throwIfCommandFails: true, + buildSystem: buildSystem, + ) + let codeCovPath = buildResult.binPath.appending("codecov") + let codeCovFiles = try localFileSystem.getDirectoryContents(codeCovPath) + #expect(codeCovFiles.count > 0) + } + } when: { + [.swiftbuild, .xcode].contains(buildSystem) + } + } + + @Test(arguments: [BuildSystemProvider.Kind.native, .swiftbuild]) + func parseAsLibraryCriteria(buildSystem: BuildSystemProvider.Kind) async throws { + try await withKnownIssue { + try await fixture(name: "Miscellaneous/ParseAsLibrary") { fixturePath in _ = try await executeSwiftBuild( fixturePath, - configuration: buildData.config, - buildSystem: buildData.buildSystem, + buildSystem: buildSystem, throwIfCommandFails: true ) } - } when: { - ProcessInfo.hostOperatingSystem == .windows && - buildData.buildSystem == .swiftbuild - } + } when: { + ProcessInfo.hostOperatingSystem == .windows && + buildSystem == .swiftbuild + } } @Test( - arguments: getBuildData(for: SupportedBuildSystemOnPlatform), + arguments: SupportedBuildSystemOnPlatform, ) func fatalErrorDisplayedCorrectNumberOfTimesWhenSingleXCTestHasFatalErrorInBuildCompilation( - data: BuildData, + buildSystem: BuildSystemProvider.Kind, ) async throws { let expected = 0 try await fixture(name: "Miscellaneous/Errors/FatalErrorInSingleXCTest/TypeLibrary") { fixturePath in // WHEN swift-build --build-tests is executed" let error = await #expect(throws: SwiftPMError.self ) { - try await execute( + try await self.execute( ["--build-tests"], - packagePath: fixturePath, - configuration: data.config, - buildSystem: data.buildSystem, + packagePath: fixturePath,buildSystem: buildSystem, ) } // THEN I expect a failure @@ -1364,14 +1322,13 @@ struct BuildCommandTestCases { } @Test( - .issue("https://github.com/swiftlang/swift-package-manager/issues/8844", relationship: .defect), - arguments: getBuildData(for: SupportedBuildSystemOnPlatform), + .bug("https://github.com/swiftlang/swift-package-manager/issues/8844"), + arguments: SupportedBuildSystemOnPlatform, BuildConfiguration.allCases ) func swiftBuildQuietLogLevel( - data: BuildData, + buildSystem: BuildSystemProvider.Kind, + configuration: BuildConfiguration ) async throws { - let buildSystem = data.buildSystem - let configuration = data.config try await withKnownIssue { // GIVEN we have a simple test package try await fixture(name: "Miscellaneous/SwiftBuild") { fixturePath in @@ -1394,7 +1351,7 @@ struct BuildCommandTestCases { } @Test( - .issue("https://github.com/swiftlang/swift-package-manager/issues/8844", relationship: .defect), + .bug("https://github.com/swiftlang/swift-package-manager/issues/8844"), arguments: SupportedBuildSystemOnPlatform, BuildConfiguration.allCases ) func swiftBuildQuietLogLevelWithError( @@ -1427,18 +1384,17 @@ struct BuildCommandTestCases { return } - switch buildSystem { - case .swiftbuild: - // THEN we should see output in stderr - #expect(stderr.isEmpty == false) - // AND no content in stdout - #expect(stdout.isEmpty) - case .native, .xcode: - // THEN we should see content in stdout - #expect(stdout.isEmpty == false) - // AND no output in stderr - #expect(stderr.isEmpty) - } + if buildSystem == .swiftbuild { + // THEN we should see output in stderr + #expect(stderr.isEmpty == false) + // AND no content in stdout + #expect(stdout.isEmpty) + } else { + // THEN we should see content in stdout + #expect(stdout.isEmpty == false) + // AND no output in stderr + #expect(stderr.isEmpty) + } } } diff --git a/Tests/CommandsTests/RunCommandTests.swift b/Tests/CommandsTests/RunCommandTests.swift index 1eee96e52a2..d282ab16002 100644 --- a/Tests/CommandsTests/RunCommandTests.swift +++ b/Tests/CommandsTests/RunCommandTests.swift @@ -91,8 +91,8 @@ struct RunCommandTests { } @Test( - .IssueWindowsPathTestsFailures, - .IssueWindowsRelativePathAssert, + .bug("https://github.com/swiftlang/swift-package-manager/issues/8511"), + .bug("https://github.com/swiftlang/swift-package-manager/issues/8602"), .SWBINTTODO("Test package fails to build on Windows"), arguments: SupportedBuildSystemOnPlatform, ) @@ -135,8 +135,8 @@ struct RunCommandTests { } @Test( - .IssueWindowsPathTestsFailures, - .IssueWindowsRelativePathAssert, + .bug("https://github.com/swiftlang/swift-package-manager/issues/8511"), + .bug("https://github.com/swiftlang/swift-package-manager/issues/8602"), arguments: SupportedBuildSystemOnPlatform, ) func productArgumentPassing( @@ -237,8 +237,8 @@ struct RunCommandTests { @Test( - .IssueWindowsPathTestsFailures, - .IssueWindowsRelativePathAssert, + .bug("https://github.com/swiftlang/swift-package-manager/issues/8511"), + .bug("https://github.com/swiftlang/swift-package-manager/issues/8602"), arguments: SupportedBuildSystemOnPlatform, ) func unreachableExecutable( diff --git a/Tests/CommandsTests/Sanitizer+ExtensionsTests.swift b/Tests/CommandsTests/Sanitizer+ExtensionsTests.swift deleted file mode 100644 index c7008f269b1..00000000000 --- a/Tests/CommandsTests/Sanitizer+ExtensionsTests.swift +++ /dev/null @@ -1,33 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift open source project -// -// Copyright (c) 2024 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See http://swift.org/LICENSE.txt for license information -// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// -//===----------------------------------------------------------------------===// - -import Testing -import enum PackageModel.Sanitizer - -@Suite( - .tags( - Tag.TestSize.small, - ), -) -struct SanitizerExtensionTests { - @Test( - arguments: Sanitizer.allCases - ) - func creatingSanitizers(sanitizer: Sanitizer) throws { - #expect(sanitizer == Sanitizer(argument: sanitizer.shortName)) - } - - @Test - func invalidSanitizer() throws { - #expect(Sanitizer(argument: "invalid") == nil) - } -} diff --git a/Tests/CommandsTests/TestCommandTests.swift b/Tests/CommandsTests/TestCommandTests.swift index 10dce1188a8..008094e18f2 100644 --- a/Tests/CommandsTests/TestCommandTests.swift +++ b/Tests/CommandsTests/TestCommandTests.swift @@ -1064,7 +1064,7 @@ struct TestCommandTests { } @Test( - .IssueWindowsPathTestsFailures, + .issue("https://github.com/swiftlang/swift-package-manager/issues/8511", relationship: .defect), .issue("https://github.com/swiftlang/swift-package-manager/issues/8602", relationship: .defect), arguments: SupportedBuildSystemOnAllPlatforms, BuildConfiguration.allCases, ) diff --git a/Tests/FunctionalTests/PluginTests.swift b/Tests/FunctionalTests/PluginTests.swift index 3352f0ba2f0..7f4413ab84e 100644 --- a/Tests/FunctionalTests/PluginTests.swift +++ b/Tests/FunctionalTests/PluginTests.swift @@ -32,7 +32,7 @@ import Foundation ) final class PluginTests { @Test( - .IssueWindowsRelativePathAssert, + .bug("https://github.com/swiftlang/swift-package-manager/issues/8602"), .bug("https://github.com/swiftlang/swift-package-manager/issues/8791"), .requiresSwiftConcurrencySupport, ) @@ -69,7 +69,7 @@ final class PluginTests { } @Test( - .IssueWindowsRelativePathAssert, + .bug("https://github.com/swiftlang/swift-package-manager/issues/8602"), .bug("https://github.com/swiftlang/swift-package-manager/issues/8786"), .requiresSwiftConcurrencySupport, ) @@ -100,7 +100,7 @@ final class PluginTests { } @Test( - .IssueWindowsRelativePathAssert, + .bug("https://github.com/swiftlang/swift-package-manager/issues/8602"), .bug("https://github.com/swiftlang/swift-package-manager/issues/8774"), .requiresSwiftConcurrencySupport, ) @@ -139,7 +139,7 @@ final class PluginTests { } @Test( - .IssueWindowsRelativePathAssert, + .bug("https://github.com/swiftlang/swift-package-manager/issues/8602"), .bug("https://github.com/swiftlang/swift-package-manager/issues/8774"), .requiresSwiftConcurrencySupport, ) @@ -178,7 +178,7 @@ final class PluginTests { } @Test( - .IssueWindowsRelativePathAssert, + .bug("https://github.com/swiftlang/swift-package-manager/issues/8602"), .bug("https://github.com/swiftlang/swift-package-manager/issues/8774"), .requiresSwiftConcurrencySupport, ) @@ -249,7 +249,7 @@ final class PluginTests { } @Test( - .IssueWindowsRelativePathAssert, + .bug("https://github.com/swiftlang/swift-package-manager/issues/8602"), .bug("https://github.com/swiftlang/swift-package-manager/issues/8774"), .requiresSwiftConcurrencySupport, ) @@ -286,7 +286,7 @@ final class PluginTests { } @Test( - .IssueWindowsRelativePathAssert, + .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"), .requiresSwiftConcurrencySupport, @@ -322,7 +322,7 @@ final class PluginTests { } @Test( - .IssueWindowsRelativePathAssert, + .bug("https://github.com/swiftlang/swift-package-manager/issues/8602"), .bug("https://github.com/swiftlang/swift-package-manager/issues/8774"), .requiresSwiftConcurrencySupport, ) @@ -432,7 +432,7 @@ final class PluginTests { @Test( .bug("https://github.com/swiftlang/swift-package-manager/issues/8794"), - .IssueWindowsRelativePathAssert, + .bug("https://github.com/swiftlang/swift-package-manager/issues/8602"), .requiresSwiftConcurrencySupport, arguments: SupportedBuildSystemOnAllPlatforms, ) @@ -870,7 +870,7 @@ final class PluginTests { } @Test( - .IssueWindowsRelativePathAssert, + .bug("https://github.com/swiftlang/swift-package-manager/issues/8602"), .requiresSwiftConcurrencySupport, arguments: [BuildSystemProvider.Kind.native, .swiftbuild] ) @@ -1365,7 +1365,7 @@ final class PluginTests { struct SnippetTests { @Test( .bug("https://github.com/swiftlang/swift-package-manager/issues/8774"), - .IssueWindowsRelativePathAssert, + .bug("https://github.com/swiftlang/swift-package-manager/issues/8602"), .requiresSwiftConcurrencySupport, arguments: getBuildData(for: SupportedBuildSystemOnAllPlatforms), ) @@ -1614,7 +1614,7 @@ final class PluginTests { @Test( .bug("https://github.com/swiftlang/swift-package-manager/issues/8774"), - .IssueWindowsRelativePathAssert, + .bug("https://github.com/swiftlang/swift-package-manager/issues/8602"), .requiresSwiftConcurrencySupport, arguments: SupportedBuildSystemOnAllPlatforms, ) @@ -1661,7 +1661,7 @@ final class PluginTests { } @Test( - .IssueWindowsRelativePathAssert, + .bug("https://github.com/swiftlang/swift-package-manager/issues/8602"), .bug("https://github.com/swiftlang/swift-package-manager/issues/8791"), .requiresSwiftConcurrencySupport, ) @@ -1697,7 +1697,7 @@ final class PluginTests { } @Test( - .IssueWindowsRelativePathAssert, + .bug("https://github.com/swiftlang/swift-package-manager/issues/8602"), .bug("https://github.com/swiftlang/swift-package-manager/issues/8791"), .requiresSwiftConcurrencySupport, ) diff --git a/Tests/FunctionalTests/TraitTests.swift b/Tests/FunctionalTests/TraitTests.swift index 7138b7522a8..59e4623796a 100644 --- a/Tests/FunctionalTests/TraitTests.swift +++ b/Tests/FunctionalTests/TraitTests.swift @@ -28,8 +28,8 @@ import _InternalTestSupport ) struct TraitTests { @Test( - .IssueWindowsPathTestsFailures, - .IssueWindowsRelativePathAssert, + .bug("https://github.com/swiftlang/swift-package-manager/issues/8511"), + .bug("https://github.com/swiftlang/swift-package-manager/issues/8602"), .IssueProductTypeForObjectLibraries, .tags( Tag.Feature.Command.Run, @@ -69,8 +69,8 @@ struct TraitTests { } @Test( - .IssueWindowsPathTestsFailures, - .IssueWindowsRelativePathAssert, + .bug("https://github.com/swiftlang/swift-package-manager/issues/8511"), + .bug("https://github.com/swiftlang/swift-package-manager/issues/8602"), .IssueProductTypeForObjectLibraries, .tags( Tag.Feature.Command.Run, @@ -120,8 +120,8 @@ struct TraitTests { } @Test( - .IssueWindowsPathTestsFailures, - .IssueWindowsRelativePathAssert, + .bug("https://github.com/swiftlang/swift-package-manager/issues/8511"), + .bug("https://github.com/swiftlang/swift-package-manager/issues/8602"), .IssueProductTypeForObjectLibraries, .tags( Tag.Feature.Command.Run, @@ -168,8 +168,8 @@ struct TraitTests { } @Test( - .IssueWindowsPathTestsFailures, - .IssueWindowsRelativePathAssert, + .bug("https://github.com/swiftlang/swift-package-manager/issues/8511"), + .bug("https://github.com/swiftlang/swift-package-manager/issues/8602"), .IssueProductTypeForObjectLibraries, .tags( Tag.Feature.Command.Run, @@ -220,8 +220,8 @@ struct TraitTests { } @Test( - .IssueWindowsPathTestsFailures, - .IssueWindowsRelativePathAssert, + .bug("https://github.com/swiftlang/swift-package-manager/issues/8511"), + .bug("https://github.com/swiftlang/swift-package-manager/issues/8602"), .IssueProductTypeForObjectLibraries, .tags( Tag.Feature.Command.Run, @@ -257,8 +257,8 @@ struct TraitTests { } @Test( - .IssueWindowsPathTestsFailures, - .IssueWindowsRelativePathAssert, + .bug("https://github.com/swiftlang/swift-package-manager/issues/8511"), + .bug("https://github.com/swiftlang/swift-package-manager/issues/8602"), .IssueProductTypeForObjectLibraries, .tags( Tag.Feature.Command.Run, @@ -301,8 +301,8 @@ struct TraitTests { } @Test( - .IssueWindowsPathTestsFailures, - .IssueWindowsRelativePathAssert, + .bug("https://github.com/swiftlang/swift-package-manager/issues/8511"), + .bug("https://github.com/swiftlang/swift-package-manager/issues/8602"), .IssueProductTypeForObjectLibraries, .tags( Tag.Feature.Command.Run, @@ -356,8 +356,8 @@ struct TraitTests { } @Test( - .IssueWindowsPathTestsFailures, - .IssueWindowsRelativePathAssert, + .bug("https://github.com/swiftlang/swift-package-manager/issues/8511"), + .bug("https://github.com/swiftlang/swift-package-manager/issues/8602"), .IssueProductTypeForObjectLibraries, .tags( Tag.Feature.Command.Run, @@ -439,8 +439,8 @@ struct TraitTests { } @Test( - .IssueWindowsPathTestsFailures, - .IssueWindowsRelativePathAssert, + .bug("https://github.com/swiftlang/swift-package-manager/issues/8511"), + .bug("https://github.com/swiftlang/swift-package-manager/issues/8602"), .tags( Tag.Feature.Command.Test, ), @@ -650,7 +650,7 @@ struct TraitTests { DEFINE1 disabled DEFINE2 disabled DEFINE3 disabled - + """ ), ("Package10", @@ -661,7 +661,7 @@ struct TraitTests { DEFINE1 disabled DEFINE2 disabled DEFINE3 disabled - + """ ), ("ExtraTrait,Package10", @@ -673,7 +673,7 @@ struct TraitTests { DEFINE1 disabled DEFINE2 disabled DEFINE3 disabled - + """ ) ) diff --git a/Tests/IntegrationTests/SwiftPMTests.swift b/Tests/IntegrationTests/SwiftPMTests.swift index c2fd11b8666..2dc780d92f0 100644 --- a/Tests/IntegrationTests/SwiftPMTests.swift +++ b/Tests/IntegrationTests/SwiftPMTests.swift @@ -13,9 +13,7 @@ import _IntegrationTestSupport import _InternalTestSupport import Testing import Basics -import enum PackageModel.BuildConfiguration import struct SPMBuildCore.BuildSystemProvider - @Suite( .tags(Tag.TestSize.large) ) @@ -221,28 +219,20 @@ private struct SwiftPMTests { } } - @Test( - .requireSwift6_2, - arguments: SupportedBuildSystemOnAllPlatforms - ) - func testCodeCoverageMergedAcrossSubprocesses( - buildSystem: BuildSystemProvider.Kind, - ) async throws { - let config = BuildConfiguration.debug - try await withTemporaryDirectory(removeTreeOnDeinit: false) { tmpDir in + @Test(.requireSwift6_2) + func testCodeCoverageMergedAcrossSubprocesses() async throws { + try await withTemporaryDirectory { tmpDir in let packagePath = tmpDir.appending(component: "test-package-coverage") try localFileSystem.createDirectory(packagePath) try await executeSwiftPackage( packagePath, - configuration: config, extraArgs: ["init", "--type", "empty"], - buildSystem: buildSystem, + buildSystem: .native, ) try await executeSwiftPackage( packagePath, - configuration: config, extraArgs: ["add-target", "--type", "test", "ReproTests"], - buildSystem: buildSystem, + buildSystem: .native, ) try localFileSystem.writeFileContents( AbsolutePath(validating: "Tests/ReproTests/Subject.swift", relativeTo: packagePath), @@ -270,73 +260,66 @@ private struct SwiftPMTests { ) let expectedCoveragePath = try await executeSwiftTest( packagePath, - configuration: config, extraArgs: ["--show-coverage-path"], - buildSystem: buildSystem, + buildSystem: .native, ).stdout.trimmingCharacters(in: .whitespacesAndNewlines) try await executeSwiftTest( packagePath, - configuration: config, extraArgs: ["--enable-code-coverage", "--disable-xctest"], - buildSystem: buildSystem, + buildSystem: .native, ) let coveragePath = try AbsolutePath(validating: expectedCoveragePath) // Check the coverage path exists. - try withKnownIssue { - // the CoveragePath file does not exists in Linux platform build - expectFileExists(at: coveragePath) + #expect(localFileSystem.exists(coveragePath)) - // This resulting coverage file should be merged JSON, with a schema that valiades against this subset. - struct Coverage: Codable { - var data: [Entry] - struct Entry: Codable { - var files: [File] - struct File: Codable { - var filename: String - var summary: Summary - struct Summary: Codable { - var functions: Functions - struct Functions: Codable { - var count, covered: Int - var percent: Double - } + // This resulting coverage file should be merged JSON, with a schema that valiades against this subset. + struct Coverage: Codable { + var data: [Entry] + struct Entry: Codable { + var files: [File] + struct File: Codable { + var filename: String + var summary: Summary + struct Summary: Codable { + var functions: Functions + struct Functions: Codable { + var count, covered: Int + var percent: Double } } } } - let coverageJSON = try localFileSystem.readFileContents(coveragePath) - let coverage = try JSONDecoder().decode(Coverage.self, from: Data(coverageJSON.contents)) + } + let coverageJSON = try localFileSystem.readFileContents(coveragePath) + let coverage = try JSONDecoder().decode(Coverage.self, from: Data(coverageJSON.contents)) - // Check for 100% coverage for Subject.swift, which should happen because the per-PID files got merged. - let subjectCoverage = try #require(coverage.data.first?.files.first(where: { $0.filename.hasSuffix("Subject.swift") })) - #expect(subjectCoverage.summary.functions.count == 2) - #expect(subjectCoverage.summary.functions.covered == 2) - #expect(subjectCoverage.summary.functions.percent == 100) + // Check for 100% coverage for Subject.swift, which should happen because the per-PID files got merged. + let subjectCoverage = coverage.data.first?.files.first(where: { $0.filename.hasSuffix("Subject.swift") }) + #expect(subjectCoverage?.summary.functions.count == 2) + #expect(subjectCoverage?.summary.functions.covered == 2) + #expect(subjectCoverage?.summary.functions.percent == 100) - // Check the directory with the coverage path contains the profraw files. - let coverageDirectory = coveragePath.parentDirectory - let coverageDirectoryContents = try localFileSystem.getDirectoryContents(coverageDirectory) + // Check the directory with the coverage path contains the profraw files. + let coverageDirectory = coveragePath.parentDirectory + let coverageDirectoryContents = try localFileSystem.getDirectoryContents(coverageDirectory) - // SwiftPM uses an LLVM_PROFILE_FILE that ends with ".%p.profraw", which we validated in the test above. - // Let's first check all the files have the expected extension. - let profrawFiles = coverageDirectoryContents.filter { $0.hasSuffix(".profraw") } + // SwiftPM uses an LLVM_PROFILE_FILE that ends with ".%p.profraw", which we validated in the test above. + // Let's first check all the files have the expected extension. + let profrawFiles = coverageDirectoryContents.filter { $0.hasSuffix(".profraw") } - // Then check that %p expanded as we expected: to something that plausibly looks like a PID. - for profrawFile in profrawFiles { - let shouldBePID = try #require(profrawFile.split(separator: ".").dropLast().last) - #expect(Int(shouldBePID) != nil) - } + // Then check that %p expanded as we expected: to something that plausibly looks like a PID. + for profrawFile in profrawFiles { + let shouldBePID = try #require(profrawFile.split(separator: ".").dropLast().last) + #expect(Int(shouldBePID) != nil) + } - // Group the files by binary identifier (have a different prefix, before the per-PID suffix). - let groups = Dictionary(grouping: profrawFiles) { path in path.split(separator: ".").dropLast(2) }.values + // Group the files by binary identifier (have a different prefix, before the per-PID suffix). + let groups = Dictionary(grouping: profrawFiles) { path in path.split(separator: ".").dropLast(2) }.values - // Check each group has 3 files: one per PID (the above suite has 2 exit tests => 2 forks => 3 PIDs total). - for binarySpecificProfrawFiles in groups { - #expect(binarySpecificProfrawFiles.count == 3) - } - } when: { - ProcessInfo.hostOperatingSystem == .linux && buildSystem == .swiftbuild + // Check each group has 3 files: one per PID (the above suite has 2 exit tests => 2 forks => 3 PIDs total). + for binarySpecificProfrawFiles in groups { + #expect(binarySpecificProfrawFiles.count == 3) } } } diff --git a/Tests/PackageGraphTests/ModulesGraphTests.swift b/Tests/PackageGraphTests/ModulesGraphTests.swift index 7145a61ea3d..55699e5c739 100644 --- a/Tests/PackageGraphTests/ModulesGraphTests.swift +++ b/Tests/PackageGraphTests/ModulesGraphTests.swift @@ -113,7 +113,7 @@ struct ModulesGraphTests { } @Test( - .IssueWindowsPathTestsFailures, + .issue("https://github.com/swiftlang/swift-package-manager/issues/8511", relationship: .defect), ) func basic() throws { try withKnownIssue {