Skip to content

Commit 879236b

Browse files
authored
Tests: Enable BasicsTests/FileSystem/* Tests on Windows (Swift Testing) (#8450)
Convert posted test from XCTest to Swift Testing, while updating to ensuring we mark the tests that currently fail on windows. Tests/BasicsTests/FileSystem/FileSystemTests.swift Tests/BasicsTests/FileSystem/PathShimTests.swift Tests/BasicsTests/FileSystem/PathTests.swift Tests/BasicsTests/FileSystem/TemporaryFileTests.swift Tests/BasicsTests/FileSystem/VFSTests.swift Depends on swiftlang/swift#81217 Partially Addresses: #8433 Issue: rdar://148248105
1 parent 96d86b0 commit 879236b

File tree

6 files changed

+1089
-729
lines changed

6 files changed

+1089
-729
lines changed

Tests/BasicsTests/FileSystem/FileSystemTests.swift

+33-25
Original file line numberDiff line numberDiff line change
@@ -9,86 +9,94 @@
99
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1010
//
1111
//===----------------------------------------------------------------------===//
12+
import Foundation
13+
import TSCTestSupport
14+
import Testing
1215

1316
@testable import Basics
14-
import TSCTestSupport
15-
import XCTest
1617

17-
final class FileSystemTests: XCTestCase {
18-
func testStripFirstLevelComponent() throws {
18+
struct FileSystemTests {
19+
@Test
20+
func stripFirstLevelComponent() throws {
1921
let fileSystem = InMemoryFileSystem()
2022

2123
let rootPath = AbsolutePath("/root")
2224
try fileSystem.createDirectory(rootPath)
2325

24-
let totalDirectories = Int.random(in: 0 ..< 100)
25-
for index in 0 ..< totalDirectories {
26+
let totalDirectories = Int.random(in: 0..<100)
27+
for index in 0..<totalDirectories {
2628
let path = rootPath.appending("dir\(index)")
2729
try fileSystem.createDirectory(path, recursive: false)
2830
}
2931

30-
let totalFiles = Int.random(in: 0 ..< 100)
31-
for index in 0 ..< totalFiles {
32+
let totalFiles = Int.random(in: 0..<100)
33+
for index in 0..<totalFiles {
3234
let path = rootPath.appending("file\(index)")
3335
try fileSystem.writeFileContents(path, string: "\(index)")
3436
}
3537

3638
do {
3739
let contents = try fileSystem.getDirectoryContents(.root)
38-
XCTAssertEqual(contents.count, 1)
40+
#expect(contents.count == 1)
3941
}
4042

4143
try fileSystem.stripFirstLevel(of: .root)
4244

4345
do {
4446
let contents = Set(try fileSystem.getDirectoryContents(.root))
45-
XCTAssertEqual(contents.count, totalDirectories + totalFiles)
47+
#expect(contents.count == totalDirectories + totalFiles)
4648

47-
for index in 0 ..< totalDirectories {
48-
XCTAssertTrue(contents.contains("dir\(index)"))
49+
for index in 0..<totalDirectories {
50+
#expect(contents.contains("dir\(index)"))
4951
}
50-
for index in 0 ..< totalFiles {
51-
XCTAssertTrue(contents.contains("file\(index)"))
52+
for index in 0..<totalFiles {
53+
#expect(contents.contains("file\(index)"))
5254
}
5355
}
5456
}
5557

56-
func testStripFirstLevelComponentErrors() throws {
58+
@Test
59+
func stripFirstLevelComponentErrors() throws {
60+
let functionUnderTest = "stripFirstLevel"
5761
do {
5862
let fileSystem = InMemoryFileSystem()
59-
XCTAssertThrowsError(try fileSystem.stripFirstLevel(of: .root), "expected error") { error in
60-
XCTAssertMatch((error as? StringError)?.description, .contains("requires single top level directory"))
63+
#expect(throws: StringError("\(functionUnderTest) requires single top level directory"))
64+
{
65+
try fileSystem.stripFirstLevel(of: .root)
6166
}
6267
}
6368

6469
do {
6570
let fileSystem = InMemoryFileSystem()
66-
for index in 0 ..< 3 {
71+
for index in 0..<3 {
6772
let path = AbsolutePath.root.appending("dir\(index)")
6873
try fileSystem.createDirectory(path, recursive: false)
6974
}
70-
XCTAssertThrowsError(try fileSystem.stripFirstLevel(of: .root), "expected error") { error in
71-
XCTAssertMatch((error as? StringError)?.description, .contains("requires single top level directory"))
75+
#expect(throws: StringError("\(functionUnderTest) requires single top level directory"))
76+
{
77+
try fileSystem.stripFirstLevel(of: .root)
7278
}
7379
}
7480

7581
do {
7682
let fileSystem = InMemoryFileSystem()
77-
for index in 0 ..< 3 {
83+
for index in 0..<3 {
7884
let path = AbsolutePath.root.appending("file\(index)")
7985
try fileSystem.writeFileContents(path, string: "\(index)")
8086
}
81-
XCTAssertThrowsError(try fileSystem.stripFirstLevel(of: .root), "expected error") { error in
82-
XCTAssertMatch((error as? StringError)?.description, .contains("requires single top level directory"))
87+
#expect(throws: StringError("\(functionUnderTest) requires single top level directory"))
88+
{
89+
try fileSystem.stripFirstLevel(of: .root)
8390
}
8491
}
8592

8693
do {
8794
let fileSystem = InMemoryFileSystem()
8895
let path = AbsolutePath.root.appending("file")
8996
try fileSystem.writeFileContents(path, string: "")
90-
XCTAssertThrowsError(try fileSystem.stripFirstLevel(of: .root), "expected error") { error in
91-
XCTAssertMatch((error as? StringError)?.description, .contains("requires single top level directory"))
97+
#expect(throws: StringError("\(functionUnderTest) requires single top level directory"))
98+
{
99+
try fileSystem.stripFirstLevel(of: .root)
92100
}
93101
}
94102
}

0 commit comments

Comments
 (0)