Skip to content

Commit 0b23073

Browse files
authored
Tests: Ensure we get clean test fixtures (#8507)
### Motivation: When running tests ensure the *test fixtures* we copy over to temporary directories don't carry over any previous build information. ### Modifications: When copying packages from `/Fixtures/**` we now ensure we delete any `.build` or `.swiftpm` directories, if any.
1 parent 861a871 commit 0b23073

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

Sources/_InternalTestSupport/misc.swift

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,22 @@ fileprivate func verifyFixtureExists(at fixtureSubpath: RelativePath, file: Stat
173173
return fixtureDir
174174
}
175175

176-
fileprivate func setup(fixtureDir: AbsolutePath, in tmpDirPath: AbsolutePath, copyName: String, createGitRepo: Bool = true) throws -> AbsolutePath {
176+
fileprivate func setup(
177+
fixtureDir: AbsolutePath,
178+
in tmpDirPath: AbsolutePath,
179+
copyName: String,
180+
createGitRepo: Bool = true
181+
) throws -> AbsolutePath {
177182
func copy(from srcDir: AbsolutePath, to dstDir: AbsolutePath) throws {
178-
#if os(Windows)
183+
#if os(Windows)
179184
try localFileSystem.copy(from: srcDir, to: dstDir)
180-
#else
185+
#else
181186
try systemQuietly("cp", "-R", "-H", srcDir.pathString, dstDir.pathString)
182-
#endif
187+
#endif
188+
189+
// Ensure we get a clean test fixture.
190+
try localFileSystem.removeFileTree(dstDir.appending(component: ".build"))
191+
try localFileSystem.removeFileTree(dstDir.appending(component: ".swiftpm"))
183192
}
184193

185194
// The fixture contains either a checkout or just a Git directory.

Tests/CommandsTests/BuildCommandTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ class BuildCommandTestCases: CommandsBuildProviderTestCase {
209209
func testSymlink() async throws {
210210
try await fixture(name: "ValidLayouts/SingleModule/ExecutableNew") { fixturePath in
211211
let fullPath = try resolveSymlinks(fixturePath)
212-
let targetPath = try fullPath.appending(
213-
components: ".build",
212+
let targetPath = try fullPath.appending(components:
213+
".build",
214214
UserToolchain.default.targetTriple.platformBuildPathComponent
215215
)
216216
// Test symlink.

0 commit comments

Comments
 (0)