Skip to content

Commit c424e13

Browse files
committed
Merge branch 'fix/frizlab/wasi_and_android' into develop
2 parents a3eb48a + aa657bf commit c424e13

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#if os(WASI)
2+
import Foundation
3+
4+
5+
6+
typealias Pipe = FakePipe
7+
/* We create a fake pipe on WASI as creating a pipe is not possible. */
8+
final class FakePipe {
9+
10+
init() {
11+
/* For some reasons, creating the file with `FakePipe.fm.createFile(atPath: filepath, contents: nil)` fails.
12+
* Instead we use the Data.write(to:) method which works. */
13+
guard (try? Data().write(to: fileURL)) != nil else {
14+
fatalError("\u{1B}[91;1mCould not create temporary file.\u{1B}[0m\n\u{1B}[31;1mPlease make sure to run the test with the `--dir \"\(fileURL.deletingLastPathComponent().path)\"` option.\u{1B}[0m")
15+
}
16+
}
17+
18+
deinit {
19+
_ = try? FakePipe.fm.removeItem(at: fileURL)
20+
}
21+
22+
var fileHandleForWriting: FileHandle {
23+
try! FileHandle(forWritingTo: fileURL)
24+
}
25+
26+
var fileHandleForReading: FileHandle {
27+
try! FileHandle(forReadingFrom: fileURL)
28+
}
29+
30+
private static let fm = FileManager.default
31+
32+
private let fileURL = FakePipe.fm.temporaryDirectory.appendingPathComponent("json-logger-test-\(UUID()).txt")
33+
private var filepath: String {
34+
fileURL.absoluteURL.path
35+
}
36+
37+
}
38+
#endif

0 commit comments

Comments
 (0)