Skip to content

Commit 622505b

Browse files
committed
Allow Tests using Temp Dir to run in parallel
1 parent c22960b commit 622505b

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

CodeEditTests/Features/CodeFile/CodeFileDocumentTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import SwiftUI
1010
import Testing
1111
@testable import CodeEdit
1212

13-
@Suite(.serialized)
13+
@Suite
1414
struct CodeFileDocumentTests {
1515
let defaultString = "func test() { }"
1616

CodeEditTests/Features/Documents/WorkspaceDocument+SearchState+FindAndReplaceTests.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import XCTest
99
@testable import CodeEdit
1010

11-
// swiftlint:disable:next type_body_length
12-
final class FindAndReplaceTests: XCTestCase {
11+
@MainActor
12+
final class FindAndReplaceTests: XCTestCase { // swiftlint:disable:this type_body_length
1313
private var directory: URL!
1414
private var files: [CEWorkspaceFile] = []
1515
private var mockWorkspace: WorkspaceDocument!
@@ -34,8 +34,8 @@ final class FindAndReplaceTests: XCTestCase {
3434
try? FileManager.default.removeItem(at: directory)
3535
try FileManager.default.createDirectory(at: directory, withIntermediateDirectories: true)
3636

37-
mockWorkspace = try await WorkspaceDocument(for: directory, withContentsOf: directory, ofType: "")
38-
searchState = await mockWorkspace.searchState
37+
mockWorkspace = try WorkspaceDocument(for: directory, withContentsOf: directory, ofType: "")
38+
searchState = mockWorkspace.searchState
3939

4040
// Add a few files
4141
let folder1 = directory.appending(path: "Folder 2")
@@ -64,7 +64,7 @@ final class FindAndReplaceTests: XCTestCase {
6464
files[1].parent = folder1File
6565
files[2].parent = folder2File
6666

67-
await mockWorkspace.searchState?.addProjectToIndex()
67+
mockWorkspace.searchState?.addProjectToIndex()
6868

6969
// NOTE: This is a temporary solution. In the future, a file watcher should track file updates
7070
// and trigger an index update.

CodeEditTests/Features/Editor/EditorStateRestorationTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Testing
99
import Foundation
1010
@testable import CodeEdit
1111

12-
@Suite(.serialized)
12+
@Suite
1313
struct EditorStateRestorationTests {
1414
@Test
1515
func createsDatabase() throws {

CodeEditTests/Utils/withTempDir.swift

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@
66
//
77

88
import Foundation
9+
import Testing
910

1011
func withTempDir(_ test: (URL) async throws -> Void) async throws {
11-
let tempDirURL = try createAndClearDir()
12+
guard let currentTest = Test.current else {
13+
#expect(Bool(false))
14+
return
15+
}
16+
let tempDirURL = try createAndClearDir(file: currentTest.sourceLocation.fileID + currentTest.name)
1217
do {
1318
try await test(tempDirURL)
1419
} catch {
@@ -19,7 +24,11 @@ func withTempDir(_ test: (URL) async throws -> Void) async throws {
1924
}
2025

2126
func withTempDir(_ test: (URL) throws -> Void) throws {
22-
let tempDirURL = try createAndClearDir()
27+
guard let currentTest = Test.current else {
28+
#expect(Bool(false))
29+
return
30+
}
31+
let tempDirURL = try createAndClearDir(file: currentTest.sourceLocation.fileID + currentTest.name)
2332
do {
2433
try test(tempDirURL)
2534
} catch {
@@ -29,9 +38,10 @@ func withTempDir(_ test: (URL) throws -> Void) throws {
2938
try clearDir(tempDirURL)
3039
}
3140

32-
private func createAndClearDir() throws -> URL {
41+
private func createAndClearDir(file: String) throws -> URL {
42+
let file = file.components(separatedBy: CharacterSet(charactersIn: "/:?%*|\"<>")).joined()
3343
let tempDirURL = FileManager.default.temporaryDirectory
34-
.appending(path: "CodeEditTestDirectory", directoryHint: .isDirectory)
44+
.appending(path: "CodeEditTestDirectory" + file, directoryHint: .isDirectory)
3545

3646
// If it exists, delete it before the test
3747
try clearDir(tempDirURL)

0 commit comments

Comments
 (0)