Skip to content

Commit 626d7bd

Browse files
committed
Tests: Convert Most Basics/FileSystem/* to Swift Testing
Convert test from XCTest to Swift Testing. - Tests/BasicsTests/FileSystem/PathShimTests.swift - Tests/BasicsTests/FileSystem/PathTests.swift - Tests/BasicsTests/FileSystem/TemporaryFileTests.swift - Tests/BasicsTests/FileSystem/VFSTests.swift relates to: #8433
1 parent f2a0006 commit 626d7bd

File tree

4 files changed

+620
-442
lines changed

4 files changed

+620
-442
lines changed

Tests/BasicsTests/FileSystem/PathShimTests.swift

+23-22
Original file line numberDiff line numberDiff line change
@@ -12,64 +12,65 @@
1212

1313
import Basics
1414
import Foundation
15-
import XCTest
15+
import Testing
1616

17-
class PathShimTests: XCTestCase {
18-
func testRescursiveDirectoryCreation() {
19-
// For the tests we'll need a temporary directory.
17+
struct PathShimTests {
18+
@Test
19+
func rescursiveDirectoryCreation() {
2020
try! withTemporaryDirectory(removeTreeOnDeinit: true) { path in
2121
// Create a directory under several ancestor directories.
2222
let dirPath = path.appending(components: "abc", "def", "ghi", "mno", "pqr")
2323
try! makeDirectories(dirPath)
2424

2525
// Check that we were able to actually create the directory.
26-
XCTAssertTrue(localFileSystem.isDirectory(dirPath))
26+
#expect(localFileSystem.isDirectory(dirPath))
2727

2828
// Check that there's no error if we try to create the directory again.
29-
try! makeDirectories(dirPath)
29+
#expect(throws: Never.self) {
30+
try! makeDirectories(dirPath)
31+
}
3032
}
3133
}
3234
}
3335

34-
class WalkTests: XCTestCase {
35-
func testNonRecursive() throws {
36-
#if os(Android)
36+
struct WalkTests {
37+
@Test
38+
func nonRecursive() throws {
39+
#if os(Android)
3740
let root = "/system"
3841
var expected: [AbsolutePath] = [
3942
"\(root)/usr",
4043
"\(root)/bin",
4144
"\(root)/etc",
4245
]
43-
#elseif os(Windows)
46+
let expectedCount = 3
47+
#elseif os(Windows)
4448
let root = ProcessInfo.processInfo.environment["SystemRoot"]!
4549
var expected: [AbsolutePath] = [
4650
"\(root)/System32",
4751
"\(root)/SysWOW64",
4852
]
49-
#else
53+
let expectedCount = (root as NSString).pathComponents.count + 2
54+
#else
5055
let root = ""
5156
var expected: [AbsolutePath] = [
5257
"/usr",
5358
"/bin",
5459
"/sbin",
5560
]
56-
#endif
61+
let expectedCount = 2
62+
#endif
5763
for x in try walk(AbsolutePath(validating: "\(root)/"), recursively: false) {
5864
if let i = expected.firstIndex(of: x) {
5965
expected.remove(at: i)
6066
}
61-
#if os(Android)
62-
XCTAssertEqual(3, x.components.count)
63-
#elseif os(Windows)
64-
XCTAssertEqual((root as NSString).pathComponents.count + 2, x.components.count)
65-
#else
66-
XCTAssertEqual(2, x.components.count)
67-
#endif
67+
#expect(x.components.count == expectedCount, "Actual is not as expected")
6868
}
69-
XCTAssertEqual(expected.count, 0)
69+
#expect(expected.count == 0)
7070
}
7171

72-
func testRecursive() {
72+
@Test
73+
func recursive() {
7374
let root = AbsolutePath(#file).parentDirectory.parentDirectory.parentDirectory.parentDirectory
7475
.appending(component: "Sources")
7576
var expected = [
@@ -82,6 +83,6 @@ class WalkTests: XCTestCase {
8283
expected.remove(at: i)
8384
}
8485
}
85-
XCTAssertEqual(expected, [])
86+
#expect(expected == [])
8687
}
8788
}

0 commit comments

Comments
 (0)