Skip to content

Commit 3dad0aa

Browse files
committed
Test: Merge IntegrationTests into Tests
Consolidate all the tests into a single folders. This change only moves the IntegrationTests/Sources and IntegrationTests/Tests to their respective directory and update tests to make use of the existing executeSwift* functions. A subsequent change will find better homes for the tests under Tests/IntegrationTests.
1 parent 6bf9ba6 commit 3dad0aa

File tree

57 files changed

+387
-450
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+387
-450
lines changed

IntegrationTests/Package.swift

Lines changed: 0 additions & 35 deletions
This file was deleted.

IntegrationTests/README.md

Lines changed: 0 additions & 13 deletions
This file was deleted.

Package.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,6 @@ let package = Package(
775775
.unsafeFlags(["-static"]),
776776
]
777777
),
778-
779778
.target(
780779
/** Test for thread-sanitizer. */
781780
name: "tsan_utils",
@@ -827,6 +826,13 @@ let package = Package(
827826
name: "LLBuildManifestTests",
828827
dependencies: ["Basics", "LLBuildManifest", "_InternalTestSupport"]
829828
),
829+
.testTarget(
830+
name: "IntegrationTests",
831+
dependencies: [
832+
"_InternalTestSupport",
833+
"SPMBuildCore",
834+
]
835+
),
830836
.testTarget(
831837
name: "WorkspaceTests",
832838
dependencies: ["Workspace", "_InternalTestSupport"]
@@ -983,6 +989,7 @@ if ProcessInfo.processInfo.environment["SWIFTCI_DISABLE_SDK_DEPENDENT_TESTS"] ==
983989
"dummy-swiftc",
984990
]
985991
),
992+
986993
])
987994
}
988995
#endif

IntegrationTests/Sources/IntegrationTestSupport/Helpers.swift renamed to Sources/_InternalTestSupport/Helpers.swift

Lines changed: 41 additions & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010

1111
import Foundation
1212
import Testing
13-
import TSCBasic
14-
import TSCTestSupport
13+
import Basics
14+
import struct TSCBasic.ProcessResult
15+
import class TSCBasic.Process
1516
import enum TSCUtility.Git
1617

17-
public let sdkRoot: AbsolutePath? = {
18+
fileprivate let sdkRoot: AbsolutePath? = {
1819
if let environmentPath = ProcessInfo.processInfo.environment["SDK_ROOT"] {
1920
return try! AbsolutePath(validating: environmentPath)
2021
}
@@ -28,7 +29,7 @@ public let sdkRoot: AbsolutePath? = {
2829
#endif
2930
}()
3031

31-
public let toolchainPath: AbsolutePath = {
32+
fileprivate let toolchainPath: AbsolutePath = {
3233
if let environmentPath = ProcessInfo.processInfo.environment["TOOLCHAIN_PATH"] {
3334
return try! AbsolutePath(validating: environmentPath)
3435
}
@@ -55,7 +56,7 @@ public let clang: AbsolutePath = {
5556
return clangPath
5657
}()
5758

58-
public let xcodebuild: AbsolutePath = {
59+
fileprivate let xcodebuild: AbsolutePath = {
5960
#if os(macOS)
6061
let xcodebuildPath = try! AbsolutePath(
6162
validating: sh("xcrun", "--find", "xcodebuild").stdout.spm_chomp()
@@ -84,42 +85,46 @@ public let swiftc: AbsolutePath = {
8485
return swiftcPath
8586
}()
8687

87-
public let lldb: AbsolutePath = {
88-
if let environmentPath = ProcessInfo.processInfo.environment["LLDB_PATH"] {
89-
return try! AbsolutePath(validating: environmentPath)
90-
}
88+
// public let lldb: AbsolutePath = {
89+
// if let environmentPath = ProcessInfo.processInfo.environment["LLDB_PATH"] {
90+
// return try! AbsolutePath(validating: environmentPath)
91+
// }
9192

92-
// We check if it exists because lldb doesn't exist in Xcode's default toolchain.
93-
let toolchainLLDBPath = toolchainPath.appending(components: "usr", "bin", "lldb")
94-
if localFileSystem.exists(toolchainLLDBPath) {
95-
return toolchainLLDBPath
96-
}
93+
// // We check if it exists because lldb doesn't exist in Xcode's default toolchain.
94+
// let toolchainLLDBPath = toolchainPath.appending(components: "usr", "bin", "lldb")
95+
// if localFileSystem.exists(toolchainLLDBPath) {
96+
// return toolchainLLDBPath
97+
// }
9798

98-
#if os(macOS)
99-
let lldbPath = try! AbsolutePath(
100-
validating: sh("xcrun", "--find", "lldb").stdout.spm_chomp()
101-
)
102-
return lldbPath
103-
#else
104-
fatalError("LLDB_PATH environment variable required")
105-
#endif
106-
}()
99+
// #if os(macOS)
100+
// let lldbPath = try! AbsolutePath(
101+
// validating: sh("xcrun", "--find", "lldb").stdout.spm_chomp()
102+
// )
103+
// return lldbPath
104+
// #else
105+
// fatalError("LLDB_PATH environment variable required")
106+
// #endif
107+
// }()
107108

108-
public let swiftpmBinaryDirectory: AbsolutePath = {
109-
if let environmentPath = ProcessInfo.processInfo.environment["SWIFTPM_BIN_DIR"] {
110-
return try! AbsolutePath(validating: environmentPath)
111-
}
112109

113-
return swift.parentDirectory
114-
}()
115110

116-
public let swiftBuild: AbsolutePath = swiftpmBinaryDirectory.appending(component: "swift-build")
111+
// public let swiftpmBinaryDirectory: AbsolutePath = {
112+
// let envVarName = "SWIFTPM_BIN_DIR"
113+
// if let environmentPath = ProcessInfo.processInfo.environment[envVarName] {
114+
// return try! AbsolutePath(validating: environmentPath)
115+
// }
116+
117+
// // throw TestConfigurationErrors.EnvironmentVariableNotSet(name: envVarName)
118+
// return AbsolutePath("\(envVarName) was not set")
119+
// }()
117120

118-
public let swiftPackage: AbsolutePath = swiftpmBinaryDirectory.appending(component: "swift-package")
121+
// public let swiftBuild: AbsolutePath = swiftpmBinaryDirectory.appending(component: "swift-build")
119122

120-
public let swiftTest: AbsolutePath = swiftpmBinaryDirectory.appending(component: "swift-test")
123+
// public let swiftPackage: AbsolutePath = swiftpmBinaryDirectory.appending(component: "swift-package")
121124

122-
public let swiftRun: AbsolutePath = swiftpmBinaryDirectory.appending(component: "swift-run")
125+
// public let swiftTest: AbsolutePath = swiftpmBinaryDirectory.appending(component: "swift-test")
126+
127+
// public let swiftRun: AbsolutePath = swiftpmBinaryDirectory.appending(component: "swift-run")
123128

124129
public let isSelfHosted: Bool = {
125130
ProcessInfo.processInfo.environment["SWIFTCI_IS_SELF_HOSTED"] != nil
@@ -192,127 +197,8 @@ public func _sh(
192197
return result
193198
}
194199

195-
/// Test-helper function that runs a block of code on a copy of a test fixture
196-
/// package. The copy is made into a temporary directory, and the block is
197-
/// given a path to that directory. The block is permitted to modify the copy.
198-
/// The temporary copy is deleted after the block returns. The fixture name may
199-
/// contain `/` characters, which are treated as path separators, exactly as if
200-
/// the name were a relative path.
201-
public func fixture(
202-
name: String,
203-
file: StaticString = #file,
204-
line: UInt = #line,
205-
body: (AbsolutePath) throws -> Void
206-
) {
207-
do {
208-
// Make a suitable test directory name from the fixture subpath.
209-
let fixtureSubpath = try RelativePath(validating: name)
210-
let copyName = fixtureSubpath.components.joined(separator: "_")
211-
212-
// Create a temporary directory for the duration of the block.
213-
try withTemporaryDirectory(prefix: copyName) { tmpDirPath in
214-
215-
defer {
216-
// Unblock and remove the tmp dir on deinit.
217-
try? localFileSystem.chmod(.userWritable, path: tmpDirPath, options: [.recursive])
218-
try? localFileSystem.removeFileTree(tmpDirPath)
219-
}
220-
221-
// Construct the expected path of the fixture.
222-
// FIXME: This seems quite hacky; we should provide some control over where fixtures are found.
223-
let fixtureDir = try AbsolutePath(
224-
validating: "../../../Fixtures/\(name)",
225-
relativeTo: AbsolutePath(validating: #file)
226-
)
227-
228-
// Check that the fixture is really there.
229-
guard localFileSystem.isDirectory(fixtureDir) else {
230-
Issue.record(Comment("No such fixture: \(fixtureDir)"))
231-
return
232-
}
233-
234-
// The fixture contains either a checkout or just a Git directory.
235-
if localFileSystem.isFile(fixtureDir.appending(component: "Package.swift")) {
236-
// It's a single package, so copy the whole directory as-is.
237-
let dstDir = tmpDirPath.appending(component: copyName)
238-
#if os(Windows)
239-
try localFileSystem.copy(from: fixtureDir, to: dstDir)
240-
#else
241-
try systemQuietly("cp", "-R", "-H", fixtureDir.pathString, dstDir.pathString)
242-
#endif
243-
244-
// Invoke the block, passing it the path of the copied fixture.
245-
try body(dstDir)
246-
} else {
247-
// Copy each of the package directories and construct a git repo in it.
248-
for fileName in try! localFileSystem.getDirectoryContents(fixtureDir).sorted() {
249-
let srcDir = fixtureDir.appending(component: fileName)
250-
guard localFileSystem.isDirectory(srcDir) else { continue }
251-
let dstDir = tmpDirPath.appending(component: fileName)
252-
#if os(Windows)
253-
try localFileSystem.copy(from: srcDir, to: dstDir)
254-
#else
255-
try systemQuietly("cp", "-R", "-H", srcDir.pathString, dstDir.pathString)
256-
#endif
257-
initGitRepo(dstDir, tag: "1.2.3", addFile: false)
258-
}
259-
260-
// Invoke the block, passing it the path of the copied fixture.
261-
try body(tmpDirPath)
262-
}
263-
}
264-
} catch {
265-
Issue.record(error)
266-
}
267-
}
268-
269-
/// Test-helper function that creates a new Git repository in a directory. The new repository will contain
270-
/// exactly one empty file unless `addFile` is `false`, and if a tag name is provided, a tag with that name will be
271-
/// created.
272-
public func initGitRepo(
273-
_ dir: AbsolutePath,
274-
tag: String? = nil,
275-
addFile: Bool = true,
276-
file: StaticString = #file,
277-
line: UInt = #line
278-
) {
279-
initGitRepo(dir, tags: tag.flatMap { [$0] } ?? [], addFile: addFile, file: file, line: line)
280-
}
281-
282-
public func initGitRepo(
283-
_ dir: AbsolutePath,
284-
tags: [String],
285-
addFile: Bool = true,
286-
file: StaticString = #file,
287-
line: UInt = #line
288-
) {
289-
do {
290-
if addFile {
291-
let file = dir.appending(component: "file.swift")
292-
try localFileSystem.writeFileContents(file, bytes: "")
293-
}
294-
295-
try systemQuietly([Git.tool, "-C", dir.pathString, "init"])
296-
try systemQuietly([
297-
Git.tool, "-C", dir.pathString, "config", "user.email", "[email protected]",
298-
])
299-
try systemQuietly([
300-
Git.tool, "-C", dir.pathString, "config", "user.name", "Example Example",
301-
])
302-
try systemQuietly([Git.tool, "-C", dir.pathString, "config", "commit.gpgsign", "false"])
303-
try systemQuietly([Git.tool, "-C", dir.pathString, "add", "."])
304-
try systemQuietly([Git.tool, "-C", dir.pathString, "commit", "-m", "Add some files."])
305-
306-
for tag in tags {
307-
try systemQuietly([Git.tool, "-C", dir.pathString, "tag", tag])
308-
}
309-
} catch {
310-
Issue.record(error)
311-
}
312-
}
313-
314-
public func binaryTargetsFixture(_ closure: (AbsolutePath) throws -> Void) throws {
315-
fixture(name: "BinaryTargets") { fixturePath in
200+
public func binaryTargetsFixture<T>(_ closure: (AbsolutePath) async throws -> T) async throws {
201+
try await fixture(name: "BinaryTargets") { fixturePath in
316202
let inputsPath = fixturePath.appending(component: "Inputs")
317203
let packagePath = fixturePath.appending(component: "TestBinary")
318204

@@ -369,7 +255,7 @@ public func binaryTargetsFixture(_ closure: (AbsolutePath) throws -> Void) throw
369255
)
370256
}
371257

372-
try closure(packagePath)
258+
return try await closure(packagePath)
373259
}
374260
}
375261

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright (c) 2025 Apple Inc. and the Swift project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See http://swift.org/LICENSE.txt for license information
8+
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
*/
10+
11+
12+
public enum TestConfigurationErrors: Error {
13+
case EnvironmentVariableNotSet(name: String)
14+
}

0 commit comments

Comments
 (0)