@@ -21,7 +21,7 @@ final class ZipTests: XCTestCase {
21
21
22
22
func test_unzip( ) async throws {
23
23
// Test basic unzip behaviour we expect from the library we use
24
- try withTempDir { tempDir in
24
+ try await withTempDir { tempDir in
25
25
let tempURL = URL ( fileURLWithPath: tempDir)
26
26
let zipFile = fixtureUrl ( for: " out.zip " )
27
27
let outDir = tempURL. appendingPathComponent ( " out " )
@@ -41,7 +41,7 @@ final class ZipTests: XCTestCase {
41
41
42
42
func test_zip_roundtrip( ) async throws {
43
43
// Test basic zip roundtrip
44
- try withTempDir { tempDir in
44
+ try await withTempDir { tempDir in
45
45
// temp
46
46
let tempURL = URL ( fileURLWithPath: tempDir)
47
47
@@ -57,14 +57,6 @@ final class ZipTests: XCTestCase {
57
57
let fileB = subdir. appendingPathComponent ( " b.txt " )
58
58
try " b " . write ( to: fileB, atomically: true , encoding: . utf8)
59
59
60
- // temp/subdir/subsubdir
61
- let subsubdir = subdir. appendingPathComponent ( " subsubdir " )
62
- try FileManager . default. createDirectory ( at: subsubdir, withIntermediateDirectories: false )
63
-
64
- // temp/subdir/subdir/c.txt
65
- let fileC = subsubdir. appendingPathComponent ( " c.txt " )
66
- try " c " . write ( to: fileC, atomically: true , encoding: . utf8)
67
-
68
60
let zipFile = tempURL. appendingPathComponent ( " out.zip " )
69
61
try Zipper . zip ( paths: [ fileA, subdir] , to: zipFile)
70
62
XCTAssert ( FileManager . default. fileExists ( atPath: zipFile. path) )
@@ -77,101 +69,10 @@ final class ZipTests: XCTestCase {
77
69
// roundtrip/subdir/b.txt
78
70
let fileA = roundtrip. appendingPathComponent ( " a.txt " )
79
71
let fileB = roundtrip. appendingPathComponent ( " subdir " ) . appendingPathComponent ( " b.txt " )
80
- let fileC = roundtrip. appendingPathComponent ( " subdir " ) . appendingPathComponent ( " subsubdir " ) . appendingPathComponent ( " c.txt " )
81
72
XCTAssert ( FileManager . default. fileExists ( atPath: fileA. path) )
82
73
XCTAssert ( FileManager . default. fileExists ( atPath: fileB. path) )
83
- XCTAssert ( FileManager . default. fileExists ( atPath: fileC. path) )
84
74
XCTAssertEqual ( try String ( contentsOf: fileA) , " a " )
85
75
XCTAssertEqual ( try String ( contentsOf: fileB) , " b " )
86
- XCTAssertEqual ( try String ( contentsOf: fileC) , " c " )
87
- }
88
- }
89
- }
90
-
91
- func test_zip_roundtrip_shellTool( ) async throws {
92
- try XCTSkipIf ( !FileManager. default. fileExists ( atPath: Zipper . zip. path) )
93
-
94
- // Test basic zip roundtrip with the shellTool method
95
- try withTempDir { tempDir in
96
- // temp
97
- let tempURL = URL ( fileURLWithPath: tempDir)
98
-
99
- // temp/a.txt
100
- let fileA = tempURL. appendingPathComponent ( " a.txt " )
101
- try " a " . write ( to: fileA, atomically: true , encoding: . utf8)
102
-
103
- // temp/subdir/
104
- let subdir = tempURL. appendingPathComponent ( " subdir " )
105
- try FileManager . default. createDirectory ( at: subdir, withIntermediateDirectories: false )
106
-
107
- // temp/subdir/b.txt
108
- let fileB = subdir. appendingPathComponent ( " b.txt " )
109
- try " b " . write ( to: fileB, atomically: true , encoding: . utf8)
110
-
111
- // temp/subdir/subsubdir
112
- let subsubdir = subdir. appendingPathComponent ( " subsubdir " )
113
- try FileManager . default. createDirectory ( at: subsubdir, withIntermediateDirectories: false )
114
-
115
- // temp/subdir/subdir/c.txt
116
- let fileC = subsubdir. appendingPathComponent ( " c.txt " )
117
- try " c " . write ( to: fileC, atomically: true , encoding: . utf8)
118
-
119
- let zipFile = tempURL. appendingPathComponent ( " out.zip " )
120
- try Zipper . zip ( paths: [ fileA, subdir] , to: zipFile, method: . zipTool)
121
- XCTAssert ( FileManager . default. fileExists ( atPath: zipFile. path) )
122
-
123
- do { // unzip what we zipped and check results
124
- let roundtrip = tempURL. appendingPathComponent ( " roundtrip " )
125
- try Zipper . unzip ( from: zipFile, to: roundtrip)
126
- XCTAssert ( FileManager . default. fileExists ( atPath: roundtrip. path) )
127
- // roundtrip/a.txt
128
- // roundtrip/subdir/b.txt
129
- let fileA = roundtrip. appendingPathComponent ( " a.txt " )
130
- let fileB = roundtrip. appendingPathComponent ( " subdir " ) . appendingPathComponent ( " b.txt " )
131
- let fileC = roundtrip. appendingPathComponent ( " subdir " ) . appendingPathComponent ( " subsubdir " ) . appendingPathComponent ( " c.txt " )
132
- XCTAssert ( FileManager . default. fileExists ( atPath: fileA. path) )
133
- XCTAssert ( FileManager . default. fileExists ( atPath: fileB. path) )
134
- XCTAssert ( FileManager . default. fileExists ( atPath: fileC. path) )
135
- XCTAssertEqual ( try String ( contentsOf: fileA) , " a " )
136
- XCTAssertEqual ( try String ( contentsOf: fileB) , " b " )
137
- XCTAssertEqual ( try String ( contentsOf: fileC) , " c " )
138
- }
139
- }
140
- }
141
-
142
- func test_zip_roundtrip_shellTool_relative_paths( ) async throws {
143
- try XCTSkipIf ( !FileManager. default. fileExists ( atPath: Zipper . zip. path) )
144
-
145
- // Test basic zip roundtrip with the shellTool method and relative paths
146
- try withTempDir { tempDir in
147
- // DocBundle components
148
- // metadataURL: tempDir/metadata.json
149
- // sourceURL: tempDir/.docs/owner/repo/ref
150
- // should be zipped as
151
- // - metadata.json
152
- // - ref
153
- // at the top level as relative paths.
154
- let tempURL = URL ( fileURLWithPath: tempDir)
155
- let metadataURL = tempURL. appendingPathComponent ( " metadata.json " )
156
- try " metadata " . write ( to: metadataURL, atomically: true , encoding: . utf8)
157
- let sourceURL = tempURL. appendingPathComponent ( " docs/owner/repo/ref " )
158
- try FileManager . default. createDirectory ( at: sourceURL, withIntermediateDirectories: true )
159
- let indexHTML = sourceURL. appendingPathComponent ( " index.html " )
160
- try " index " . write ( to: indexHTML, atomically: true , encoding: . utf8)
161
-
162
- // MUT
163
- let zipFile = tempURL. appendingPathComponent ( " out.zip " )
164
- try Zipper . zip ( paths: [ metadataURL, sourceURL] , to: zipFile, method: . zipTool)
165
-
166
- do { // validate
167
- let unzipDir = tempURL. appendingPathComponent ( " unzip " )
168
- try Zipper . unzip ( from: zipFile, to: unzipDir)
169
- let metadataURL = unzipDir. appendingPathComponent ( " metadata.json " )
170
- let indexHTML = unzipDir. appendingPathComponent ( " ref/index.html " )
171
- XCTAssert ( FileManager . default. fileExists ( atPath: metadataURL. path) )
172
- XCTAssert ( FileManager . default. fileExists ( atPath: indexHTML. path) )
173
- XCTAssertEqual ( try String ( contentsOf: metadataURL) , " metadata " )
174
- XCTAssertEqual ( try String ( contentsOf: indexHTML) , " index " )
175
76
}
176
77
}
177
78
}
0 commit comments