Skip to content

Commit 4d7c7a4

Browse files
Wrap test into NS_FOUNDATION_ALLOWS_TESTABLE_IMPORT / rename _Error -> Error
1 parent 0418fc3 commit 4d7c7a4

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

Foundation/Stream.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ open class Stream: NSObject {
114114
// InputStream is an abstract class representing the base functionality of a read stream.
115115
// Subclassers are required to implement these methods.
116116
open class InputStream: Stream {
117-
enum _Error: Error {
117+
enum Error: Swift.Error {
118118
case cantSeekInputStream
119119
}
120120

@@ -159,7 +159,7 @@ open class InputStream: Stream {
159159
return Stream.Status(rawValue: UInt(CFReadStreamGetStatus(_stream)))!
160160
}
161161

162-
open override var streamError: Error? {
162+
open override var streamError: Swift.Error? {
163163
return CFReadStreamCopyError(_stream)
164164
}
165165
}
@@ -234,7 +234,7 @@ extension InputStream {
234234
return
235235
}
236236

237-
guard position < Int.max else { throw _Error.cantSeekInputStream }
237+
guard position < Int.max else { throw Error.cantSeekInputStream }
238238

239239
let bufferSize = 1024
240240
var remainingBytes = Int(position)
@@ -243,7 +243,7 @@ extension InputStream {
243243

244244
guard let pointer = buffer.baseAddress?.assumingMemoryBound(to: UInt8.self) else {
245245
buffer.deallocate()
246-
throw _Error.cantSeekInputStream
246+
throw Error.cantSeekInputStream
247247
}
248248

249249
if self.streamStatus == .notOpen {
@@ -253,14 +253,14 @@ extension InputStream {
253253
while remainingBytes > 0 && self.hasBytesAvailable {
254254
let read = self.read(pointer, maxLength: min(bufferSize, remainingBytes))
255255
if read == -1 {
256-
throw _Error.cantSeekInputStream
256+
throw Error.cantSeekInputStream
257257
}
258258
remainingBytes -= read
259259
}
260260

261261
buffer.deallocate()
262262
if remainingBytes != 0 {
263-
throw _Error.cantSeekInputStream
263+
throw Error.cantSeekInputStream
264264
}
265265
}
266266
}

TestFoundation/TestStream.swift

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
88
//
99

10-
#if (os(Linux) || os(Android))
11-
@testable import Foundation
12-
#else
13-
@testable import SwiftFoundation
10+
#if NS_FOUNDATION_ALLOWS_TESTABLE_IMPORT
11+
#if (os(Linux) || os(Android))
12+
@testable import Foundation
13+
#else
14+
@testable import SwiftFoundation
15+
#endif
1416
#endif
1517

16-
1718
private extension Data {
1819
init(reading input: InputStream) {
1920
self.init()
@@ -142,6 +143,7 @@ class TestStream : XCTestCase {
142143
}
143144

144145
func test_InputStreamSeekToPosition() {
146+
#if NS_FOUNDATION_ALLOWS_TESTABLE_IMPORT
145147
let str = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras congue laoreet facilisis. Sed porta tristique orci. Fusce ut nisl dignissim, tempor tortor id, molestie neque. Nam non tincidunt mi. Integer ac diam quis leo aliquam congue et non magna. In porta mauris suscipit erat pulvinar, sed fringilla quam ornare. Nulla vulputate et ligula vitae sollicitudin. Nulla vel vehicula risus. Quisque eu urna ullamcorper, tincidunt ante vitae, aliquet sem. Suspendisse nec turpis placerat, porttitor ex vel, tristique orci. Maecenas pretium, augue non elementum imperdiet, diam ex vestibulum tortor, non ultrices ante enim iaculis ex. Fusce ut nisl dignissim, tempor tortor id, molestie neque. Nam non tincidunt mi. Integer ac diam quis leo aliquam congue et non magna. In porta mauris suscipit erat pulvinar, sed fringilla quam ornare. Nulla vulputate et ligula vitae sollicitudin. Nulla vel vehicula risus. Quisque eu urna ullamcorper, tincidunt ante vitae, aliquet sem. Suspendisse nec turpis placerat, porttitor ex vel, tristique orci. Maecenas pretium, augue non elementum imperdiet, diam ex vestibulum tortor, non ultrices ante enim iaculis ex.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras congue laoreet facilisis. Sed porta tristique orci. Fusce ut nisl dignissim, tempor tortor id, molestie neque. Nam non tincidunt mi. Integer ac diam quis leo aliquam congue et non magna. In porta mauris suscipit erat pulvinar, sed fringilla quam ornare. Nulla vulputate et ligula vitae sollicitudin. Nulla vel vehicula risus. Quisque eu urna ullamcorper, tincidunt ante vitae, aliquet sem. Suspendisse nec turpis placerat, porttitor ex vel."
146148
XCTAssert(str.count > 1024) // str.count must be bigger than buffersize inside InputStream.seek func.
147149

@@ -178,11 +180,14 @@ class TestStream : XCTestCase {
178180
do {
179181
try testSubdata(UInt64(str.count + 1)) // out of boundaries
180182
XCTFail()
181-
} catch let error as InputStream._Error {
183+
} catch let error as InputStream.Error {
182184
XCTAssertEqual(error, .cantSeekInputStream)
183185
} catch {
184186
XCTFail()
185187
}
188+
#else
189+
print("NS_FOUNDATION_ALLOWS_TESTABLE_IMPORT is not defined, skip it")
190+
#endif
186191
}
187192

188193
func test_outputStreamCreationToFile() {

0 commit comments

Comments
 (0)