Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Fixtures/Coverage/Simple/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// 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"]
),
]
)
10 changes: 10 additions & 0 deletions Fixtures/Coverage/Simple/Sources/Simple/Simple.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// 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"
}
24 changes: 24 additions & 0 deletions Fixtures/Coverage/Simple/Tests/SimpleTests/SimpleTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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")
}
}
31 changes: 28 additions & 3 deletions Sources/Commands/SwiftTestCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import ArgumentParser

@_spi(SwiftPMInternal)
import Basics
import struct Basics.Triple

import _Concurrency

Expand Down Expand Up @@ -597,7 +598,11 @@ 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,
)
}
}

Expand All @@ -619,7 +624,6 @@ public struct SwiftTestCommand: AsyncSwiftCommand {
}
}
args += ["-o", productsBuildParameters.codeCovDataFile.pathString]

try await AsyncProcess.checkNonZeroExit(arguments: args)
}

Expand All @@ -632,11 +636,17 @@ 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)",
testBinary.pathString
] + archArgs + [
testBinary.pathString,
]
let result = try await AsyncProcess.popen(arguments: args)

Expand Down Expand Up @@ -709,6 +719,21 @@ 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)
Expand Down
5 changes: 3 additions & 2 deletions Sources/SwiftBuildSupport/SwiftBuildSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1077,8 +1077,9 @@ public final class SwiftBuildSystem: SPMBuildCore.BuildSystem {

private static func constructTestingSettingsOverrides(from parameters: BuildParameters.Testing) -> [String: String] {
var settings: [String: String] = [:]
// TODO: enableCodeCoverage
// explicitlyEnabledTestability

// Coverage settings
settings["CLANG_COVERAGE_MAPPING"] = parameters.enableCodeCoverage ? "YES" : "NO"

switch parameters.explicitlyEnabledTestability {
case true:
Expand Down
7 changes: 7 additions & 0 deletions Sources/_InternalTestSupport/SwiftTesting+TraitsBug.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ 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(
Expand Down
24 changes: 19 additions & 5 deletions Tests/BasicsTests/FileSystem/PathTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ 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"),
Expand Down Expand Up @@ -110,6 +111,7 @@ struct PathTests {
}

@Test(
.IssueWindowsPathTestsFailures,
arguments: [
(path: "/./a", expected: (windows ? #"\"# : "/")),
(path: "/../..", expected: (windows ? #"\"# : "/")),
Expand Down Expand Up @@ -143,6 +145,7 @@ struct PathTests {
}

@Test(
.IssueWindowsPathTestsFailures,
arguments: [
(path: "/../..", expected: "/"),
]
Expand Down Expand Up @@ -178,6 +181,7 @@ struct PathTests {
}

@Test(
.IssueWindowsPathTestsFailures,
arguments: [
(path: "/../..", expected: "/"),
]
Expand All @@ -204,6 +208,7 @@ struct PathTests {
#expect(actual == expectedPath)
}
@Test(
.IssueWindowsPathTestsFailures,
arguments: [
(path: "/", numParentDirectoryCalls: 1, expected: "/"),
(path: "/", numParentDirectoryCalls: 2, expected: "/"),
Expand All @@ -215,6 +220,7 @@ struct PathTests {
}

@Test(
.IssueWindowsPathTestsFailures,
arguments: [
(path: "/bar/../foo/..//", numParentDirectoryCalls: 2, expected: "/"),
(path: "/bar/../foo/..//yabba/a/b", numParentDirectoryCalls: 2, expected: "/yabba")
Expand All @@ -231,6 +237,7 @@ struct PathTests {
}

@Test(
.IssueWindowsPathTestsFailures,
arguments: [
(path: "/", expected: ["/"]),
(path: "/.", expected: ["/"]),
Expand Down Expand Up @@ -368,6 +375,7 @@ 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"),
Expand Down Expand Up @@ -440,7 +448,8 @@ struct PathTests {
}

@Test(
arguments: [
.IssueWindowsPathTestsFailures,
arguments: [
(path: "../a/..", expected: "."),
(path: "a/..", expected: "."),
(path: "a/../////../////./////", expected: "."),
Expand Down Expand Up @@ -481,6 +490,7 @@ struct PathTests {
}

@Test(
.IssueWindowsPathTestsFailures,
arguments: [
(path: "a/..", expected: "."),
(path: "a/../////../////./////", expected: ".."),
Expand Down Expand Up @@ -519,6 +529,7 @@ struct PathTests {
}

@Test(
.IssueWindowsPathTestsFailures,
arguments: [
(path: "../..", expected: ".."),
(path: "../a/..", expected: ".."),
Expand Down Expand Up @@ -560,7 +571,8 @@ struct PathTests {
}

@Test(
arguments:[
.IssueWindowsPathTestsFailures,
arguments:[
"a.",
".a",
"",
Expand Down Expand Up @@ -601,6 +613,7 @@ struct PathTests {
}

@Test(
.IssueWindowsPathTestsFailures,
arguments: [
(path: "foo/bar/..", expected: ["foo"]),
(path: "bar/../foo", expected: ["foo"]),
Expand All @@ -622,21 +635,22 @@ struct PathTests {
}
}

@Test
@Test(
.IssueWindowsPathTestsFailures,
)
func relativePathValidation() throws {
#expect(throws: Never.self) {
try RelativePath(validating: "a/b/c/d")
}

withKnownIssue {
withKnownIssue("https://github.com/swiftlang/swift-package-manager/issues/8511: \\") {
#expect {try RelativePath(validating: "/a/b/d")} throws: { error in
("\(error)" == "invalid relative path '/a/b/d'; relative path should not begin with '/'")
}
} when: {
ProcessInfo.hostOperatingSystem == .windows
}
}

}

@Test
Expand Down
14 changes: 4 additions & 10 deletions Tests/BasicsTests/HTTPClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,8 @@ struct HTTPClientTests {
var request = HTTPClient.Request(method: .get, url: "http://test")
request.options.validResponseCodes = [200]

do {
let response = try await httpClient.execute(request)
Issue.record("unexpected success \(response)")
} catch {
#expect(error as? HTTPClientError == .badResponseStatusCode(statusCode))
await #expect(throws: HTTPClientError.badResponseStatusCode(statusCode)) {
try await httpClient.execute(request)
}
}

Expand Down Expand Up @@ -407,11 +404,8 @@ struct HTTPClientTests {
var request = HTTPClient.Request(url: "http://test")
request.options.maximumResponseSizeInBytes = 10

do {
let response = try await httpClient.execute(request)
Issue.record("unexpected success \(response)")
} catch {
#expect(error as? HTTPClientError == .responseTooLarge(maxSize * 2))
await #expect(throws: HTTPClientError.responseTooLarge(maxSize * 2)) {
try await httpClient.execute(request)
}
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/BuildTests/PluginsBuildPlanTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct PluginsBuildPlanTests {
.tags(
.Feature.Command.Build,
),
.issue("https://github.com/swiftlang/swift-package-manager/issues/8511", relationship: .defect), // Fails to build the project to due to incorrect Path handling
.IssueWindowsPathTestsFailures, // Fails to build the project to due to incorrect Path handling
arguments: BuildConfiguration.allCases,
)
func buildToolsDatabasePath(
Expand Down
Loading