|
9 | 9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
10 | 10 | // |
11 | 11 | //===----------------------------------------------------------------------===// |
| 12 | +import Foundation |
| 13 | +import TSCTestSupport |
| 14 | +import Testing |
12 | 15 |
|
13 | 16 | @testable import Basics |
14 | | -import TSCTestSupport |
15 | | -import XCTest |
16 | 17 |
|
17 | | -final class FileSystemTests: XCTestCase { |
18 | | - func testStripFirstLevelComponent() throws { |
| 18 | +struct FileSystemTests { |
| 19 | + @Test |
| 20 | + func stripFirstLevelComponent() throws { |
19 | 21 | let fileSystem = InMemoryFileSystem() |
20 | 22 |
|
21 | 23 | let rootPath = AbsolutePath("/root") |
22 | 24 | try fileSystem.createDirectory(rootPath) |
23 | 25 |
|
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 { |
26 | 28 | let path = rootPath.appending("dir\(index)") |
27 | 29 | try fileSystem.createDirectory(path, recursive: false) |
28 | 30 | } |
29 | 31 |
|
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 { |
32 | 34 | let path = rootPath.appending("file\(index)") |
33 | 35 | try fileSystem.writeFileContents(path, string: "\(index)") |
34 | 36 | } |
35 | 37 |
|
36 | 38 | do { |
37 | 39 | let contents = try fileSystem.getDirectoryContents(.root) |
38 | | - XCTAssertEqual(contents.count, 1) |
| 40 | + #expect(contents.count == 1) |
39 | 41 | } |
40 | 42 |
|
41 | 43 | try fileSystem.stripFirstLevel(of: .root) |
42 | 44 |
|
43 | 45 | do { |
44 | 46 | let contents = Set(try fileSystem.getDirectoryContents(.root)) |
45 | | - XCTAssertEqual(contents.count, totalDirectories + totalFiles) |
| 47 | + #expect(contents.count == totalDirectories + totalFiles) |
46 | 48 |
|
47 | | - for index in 0 ..< totalDirectories { |
48 | | - XCTAssertTrue(contents.contains("dir\(index)")) |
| 49 | + for index in 0..<totalDirectories { |
| 50 | + #expect(contents.contains("dir\(index)")) |
49 | 51 | } |
50 | | - for index in 0 ..< totalFiles { |
51 | | - XCTAssertTrue(contents.contains("file\(index)")) |
| 52 | + for index in 0..<totalFiles { |
| 53 | + #expect(contents.contains("file\(index)")) |
52 | 54 | } |
53 | 55 | } |
54 | 56 | } |
55 | 57 |
|
56 | | - func testStripFirstLevelComponentErrors() throws { |
| 58 | + @Test |
| 59 | + func stripFirstLevelComponentErrors() throws { |
| 60 | + let functionUnderTest = "stripFirstLevel" |
57 | 61 | do { |
58 | 62 | 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) |
61 | 66 | } |
62 | 67 | } |
63 | 68 |
|
64 | 69 | do { |
65 | 70 | let fileSystem = InMemoryFileSystem() |
66 | | - for index in 0 ..< 3 { |
| 71 | + for index in 0..<3 { |
67 | 72 | let path = AbsolutePath.root.appending("dir\(index)") |
68 | 73 | try fileSystem.createDirectory(path, recursive: false) |
69 | 74 | } |
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) |
72 | 78 | } |
73 | 79 | } |
74 | 80 |
|
75 | 81 | do { |
76 | 82 | let fileSystem = InMemoryFileSystem() |
77 | | - for index in 0 ..< 3 { |
| 83 | + for index in 0..<3 { |
78 | 84 | let path = AbsolutePath.root.appending("file\(index)") |
79 | 85 | try fileSystem.writeFileContents(path, string: "\(index)") |
80 | 86 | } |
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) |
83 | 90 | } |
84 | 91 | } |
85 | 92 |
|
86 | 93 | do { |
87 | 94 | let fileSystem = InMemoryFileSystem() |
88 | 95 | let path = AbsolutePath.root.appending("file") |
89 | 96 | 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) |
92 | 100 | } |
93 | 101 | } |
94 | 102 | } |
|
0 commit comments