Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ public struct DefaultPluginScriptRunner: PluginScriptRunner, Cancellable {
#endif
process.environment = .init(env)

process.currentDirectoryURL = workingDirectory.asURL
//process.currentDirectoryURL = workingDirectory.asURL

// Set up a pipe for sending structured messages to the plugin on its stdin.
let stdinPipe = Pipe()
Expand Down
2 changes: 1 addition & 1 deletion Sources/SourceControl/Repository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public struct RepositorySpecifier: Hashable, Sendable {
if basename.hasSuffix(".git") {
basename = String(basename.dropLast(4))
}
if basename == "/" {
if basename == "/" || basename == "\\" {
return ""
}
return basename
Expand Down
12 changes: 7 additions & 5 deletions Sources/_InternalTestSupport/SwiftPMProduct.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,16 @@ extension SwiftPM {
}

public var xctestBinaryPath: AbsolutePath {
Self.xctestBinaryPath(for: RelativePath("swift-package-manager"))
get throws {
try Self.xctestBinaryPath(for: RelativePath("swift-package-manager"))
}
}

public static func xctestBinaryPath(for executableName: RelativePath) -> AbsolutePath {
public static func xctestBinaryPath(for executableName: RelativePath) throws -> AbsolutePath {
do {
return try resolveBinDir().appending(executableName)
} catch {
fatalError("Unable to determine xctestBinaryPath")
throw StringError("Unable to determine xctestBinaryPath")
}
}
}
Expand Down Expand Up @@ -134,7 +136,7 @@ extension SwiftPM {
#endif
// FIXME: We use this private environment variable hack to be able to
// create special conditions in swift-build for swiftpm tests.
environment["SWIFTPM_TESTS_MODULECACHE"] = self.xctestBinaryPath.parentDirectory.pathString
environment["SWIFTPM_TESTS_MODULECACHE"] = try self.xctestBinaryPath.parentDirectory.pathString

// Unset the internal env variable that allows skipping certain tests.
environment["_SWIFTPM_SKIP_TESTS_LIST"] = nil
Expand All @@ -143,7 +145,7 @@ extension SwiftPM {
environment[key] = value
}

var completeArgs = [Self.xctestBinaryPath(for: RelativePath(self.executableName)).pathString]
var completeArgs = try [Self.xctestBinaryPath(for: RelativePath(self.executableName)).pathString]
if let packagePath = packagePath {
completeArgs += ["--package-path", packagePath.pathString]
}
Expand Down
5 changes: 4 additions & 1 deletion Sources/_InternalTestSupport/Toolchain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ package func resolveBinDir() throws -> AbsolutePath {
#if os(macOS)
return try macOSBundleRoot()
#else
return try AbsolutePath(validating: CommandLine.arguments[0], relativeTo: localFileSystem.currentWorkingDirectory!).parentDirectory
guard let cwd = localFileSystem.currentWorkingDirectory else {
throw StringError("Current working directory unavailable!")
}
return try AbsolutePath(validating: CommandLine.arguments[0], relativeTo: cwd).parentDirectory
#endif
}

Expand Down
12 changes: 9 additions & 3 deletions Sources/_InternalTestSupport/misc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ public func testWithTemporaryDirectory<Result>(
.replacing(":", with: "_")
return try await withTemporaryDirectory(prefix: "spm-tests-\(cleanedFunction)") { tmpDirPath in
defer {
let cwd = FileManager.default.currentDirectoryPath
print("TWT-FMCWD: \(cwd) - \(cleanedFunction)")
// Unblock and remove the tmp dir on deinit.
try? localFileSystem.chmod(.userWritable, path: tmpDirPath, options: [.recursive])
try? localFileSystem.removeFileTree(tmpDirPath)
Expand Down Expand Up @@ -131,6 +133,8 @@ public func testWithTemporaryDirectory<Result>(

defer {
// Unblock and remove the tmp dir on deinit.
let cwd = FileManager.default.currentDirectoryPath
print("FXT-FMCWD: \(cwd) - \(copyName)")
try? localFileSystem.chmod(.userWritable, path: tmpDirPath, options: [.recursive])
try? localFileSystem.removeFileTree(tmpDirPath)
}
Expand Down Expand Up @@ -212,7 +216,7 @@ public enum TestError: Error {
do {
// Make a suitable test directory name from the fixture subpath.
let fixtureSubpath = try RelativePath(validating: name)
let copyName = fixtureSubpath.components.joined(separator: "_")
let copyName = fixtureSubpath.components.last!

// Create a temporary directory for the duration of the block.
return try await withTemporaryDirectory(prefix: copyName) { tmpDirPath in
Expand Down Expand Up @@ -252,7 +256,7 @@ public enum TestError: Error {
do {
// Make a suitable test directory name from the fixture subpath.
let fixtureSubpath = try RelativePath(validating: name)
let copyName = fixtureSubpath.components.joined(separator: "_")
let copyName = fixtureSubpath.components.last!

// Create a temporary directory for the duration of the block.
return try await withTemporaryDirectory(
Expand All @@ -263,6 +267,8 @@ public enum TestError: Error {
defer {
if removeFixturePathOnDeinit {
// Unblock and remove the tmp dir on deinit.
let cwd = FileManager.default.currentDirectoryPath
print("FIX-FMCWD: \(cwd) - \(name)")
try? localFileSystem.chmod(.userWritable, path: tmpDirPath, options: [.recursive])
try? localFileSystem.removeFileTree(tmpDirPath)
}
Expand Down Expand Up @@ -708,4 +714,4 @@ public func executableName(_ name: String) -> String {
#else
return name
#endif
}
}
6 changes: 2 additions & 4 deletions Tests/BasicsTests/AsyncProcessTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,14 @@ final class AsyncProcessTests: XCTestCase {
}

func testPopenWithBufferLargerThanAllocated() throws {
try XCTSkipOnWindows(because: "https://github.com/swiftlang/swift-package-manager/issues/9031: test fails on windows.")

// Test buffer larger than that allocated.
try withTemporaryFile { file in
let count = 10000
let stream = BufferedOutputByteStream()
stream.send(Format.asRepeating(string: "a", count: count))
try localFileSystem.writeFileContents(file.path, bytes: stream.bytes)
file.fileHandle.write(Data(stream.bytes.contents))
let actualStreamCount = stream.bytes.count
XCTAssertTrue(actualStreamCount == count, "Actual stream count (\(actualStreamCount)) is not as exxpected (\(count))")
XCTAssertTrue(actualStreamCount == count, "Actual stream count (\(actualStreamCount)) is not as expected (\(count))")
let outputCount = try AsyncProcess.popen(arguments: catExecutableArgs + [file.path.pathString]).utf8Output().count
XCTAssert(outputCount == count, "Actual count (\(outputCount)) is not as expected (\(count))")
}
Expand Down
6 changes: 2 additions & 4 deletions Tests/BasicsTests/Serialization/SerializedJSONTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,16 @@ final class SerializedJSONTests: XCTestCase {
}

func testPathInterpolationFailsOnWindows() throws {
try XCTSkipOnWindows(because: "Expectations are not met. Possibly related to https://github.com/swiftlang/swift-package-manager/issues/8511")

#if os(Windows)
var path = try AbsolutePath(validating: #"\\?\C:\Users"#)
var json: SerializedJSON = "\(path)"

XCTAssertEqual(json.underlying, #"C:\\Users"#)
XCTAssertEqual(json.underlying, #"\\\\?\\C:\\Users"#)

path = try AbsolutePath(validating: #"\\.\UNC\server\share\"#)
json = "\(path)"

XCTAssertEqual(json.underlying, #"\\.\\UNC\\server\\share"#)
XCTAssertEqual(json.underlying, #"\\\\.\\UNC\\server\\share"#)
#endif
}
}
2 changes: 1 addition & 1 deletion Tests/BuildTests/IncrementalBuildTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ final class IncrementalBuildTests: XCTestCase {
try XCTSkipIf(!UserToolchain.default.supportsSDKDependentTests(), "skipping because test environment doesn't support this test")

try await fixtureXCTest(name: "ValidLayouts/SingleModule/Library") { fixturePath in
let dummySwiftcPath = SwiftPM.xctestBinaryPath(for: "dummy-swiftc")
let dummySwiftcPath = try SwiftPM.xctestBinaryPath(for: "dummy-swiftc")
let swiftCompilerPath = try UserToolchain.default.swiftCompilerPath
let environment: Environment = [
"SWIFT_EXEC": dummySwiftcPath.pathString,
Expand Down
51 changes: 29 additions & 22 deletions Tests/CommandsTests/BuildCommandTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ struct BuildCommandTestCases {
) async throws {
let buildSystem = data.buildSystem
try await fixture(name: "Miscellaneous/ParseableInterfaces") { fixturePath in
try await withKnownIssue(isIntermittent: ProcessInfo.hostOperatingSystem == .windows) {
try await withKnownIssue(isIntermittent: true) {
let result = try await build(
["--enable-parseable-module-interfaces"],
packagePath: fixturePath,
Expand Down Expand Up @@ -1148,24 +1148,31 @@ struct BuildCommandTestCases {
func swiftDriverRawOutputGetsNewlines(
buildSystem: BuildSystemProvider.Kind,
) async throws {
try await fixture(name: "DependencyResolution/Internal/Simple") { fixturePath in
// Building with `-wmo` should result in a `remark: Incremental compilation has been disabled: it is not
// compatible with whole module optimization` message, which should have a trailing newline. Since that
// message won't be there at all when the legacy compiler driver is used, we gate this check on whether the
// remark is there in the first place.
let result = try await execute(
["-Xswiftc", "-wmo"],
packagePath: fixturePath,
configuration: .release,
buildSystem: buildSystem,
)
if result.stdout.contains(
"remark: Incremental compilation has been disabled: it is not compatible with whole module optimization"
) {
#expect(result.stdout.contains("optimization\n"))
#expect(!result.stdout.contains("optimization["))
#expect(!result.stdout.contains("optimizationremark"))
try await withKnownIssue(
"error produced for this fixture",
isIntermittent: true,
) {
try await fixture(name: "DependencyResolution/Internal/Simple") { fixturePath in
// Building with `-wmo` should result in a `remark: Incremental compilation has been disabled: it is not
// compatible with whole module optimization` message, which should have a trailing newline. Since that
// message won't be there at all when the legacy compiler driver is used, we gate this check on whether the
// remark is there in the first place.
let result = try await execute(
["-Xswiftc", "-wmo"],
packagePath: fixturePath,
configuration: .release,
buildSystem: buildSystem,
)
if result.stdout.contains(
"remark: Incremental compilation has been disabled: it is not compatible with whole module optimization"
) {
#expect(result.stdout.contains("optimization\n"))
#expect(!result.stdout.contains("optimization["))
#expect(!result.stdout.contains("optimizationremark"))
}
}
} when: {
ProcessInfo.hostOperatingSystem == .windows && buildSystem == .swiftbuild
}
}

Expand Down Expand Up @@ -1193,7 +1200,7 @@ struct BuildCommandTestCases {
let filename = try #require(files.first { $0.hasPrefix("swift-version") })
return buildArenaPath.appending(component: filename)
}
let dummySwiftcPath = SwiftPM.xctestBinaryPath(for: "dummy-swiftc")
let dummySwiftcPath = try SwiftPM.xctestBinaryPath(for: "dummy-swiftc")
let swiftCompilerPath = try UserToolchain.default.swiftCompilerPath

var environment: Environment = [
Expand All @@ -1205,7 +1212,7 @@ struct BuildCommandTestCases {

try await withKnownIssue(
"https://github.com/swiftlang/swift-package-manager/issues/8659, SWIFT_EXEC override is not working",
isIntermittent: (buildSystem == .native && config == .release)
isIntermittent: true
){
// Build with a swiftc that returns version 1.0, we expect a successful build which compiles our one source
// file.
Expand Down Expand Up @@ -1300,7 +1307,7 @@ struct BuildCommandTestCases {
func getTaskAllowEntitlement(
buildSystem: BuildSystemProvider.Kind,
) async throws {
try await withKnownIssue(isIntermittent: (ProcessInfo.hostOperatingSystem == .linux)) {
try await withKnownIssue(isIntermittent: true) {
try await fixture(name: "ValidLayouts/SingleModule/ExecutableNew") { fixturePath in
#if os(macOS)
// try await building with default parameters. This should succeed. We build verbosely so we get full command
Expand Down Expand Up @@ -1512,7 +1519,7 @@ struct BuildCommandTestCases {
func parseAsLibraryCriteria(
buildData: BuildData,
) async throws {
try await withKnownIssue {
try await withKnownIssue(isIntermittent: true) {
try await fixture(name: "Miscellaneous/ParseAsLibrary") { fixturePath in
_ = try await executeSwiftBuild(
fixturePath,
Expand Down
6 changes: 3 additions & 3 deletions Tests/CommandsTests/CoverageTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct CoverageTests {
buildSystem: BuildSystemProvider.Kind,
) async throws {
let config = BuildConfiguration.debug
try await withKnownIssue(isIntermittent: (ProcessInfo.hostOperatingSystem == .linux && buildSystem == .swiftbuild)) {
try await withKnownIssue(isIntermittent: true) {
try await fixture(name: "Miscellaneous/TestDiscovery/Simple") { path in
_ = try await executeSwiftBuild(
path,
Expand Down Expand Up @@ -96,7 +96,7 @@ struct CoverageTests {
let codeCovPath = try AbsolutePath(validating: codeCovPathString)

// WHEN we build with coverage enabled
try await withKnownIssue {
try await withKnownIssue(isIntermittent: true) {
try await executeSwiftBuild(
path,
configuration: config,
Expand Down Expand Up @@ -157,7 +157,7 @@ struct CoverageTests {
try #require(!localFileSystem.exists(coveragePath))

// WHEN we test with coverage enabled
try await withKnownIssue {
try await withKnownIssue(isIntermittent: true) {
try await executeSwiftTest(
path,
configuration: buildData.config,
Expand Down
Loading
Loading