Skip to content

Commit df272e7

Browse files
committed
Restore tests
1 parent d039ea0 commit df272e7

File tree

2 files changed

+23
-22
lines changed

2 files changed

+23
-22
lines changed

Sources/Testing/Attachments/Test.Attachment.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ extension Test.Attachment where AttachableValue == Test.AnyAttachable {
8585
///
8686
/// - Parameters:
8787
/// - attachment: The attachment to type-erase.
88-
fileprivate init(_ attachment: Test.Attachment<some Test.Attachable & Sendable & Copyable>) {
88+
package init(_ attachment: Test.Attachment<some Test.Attachable & Sendable & Copyable>) {
8989
self.init(
9090
_attachableValue: Test.AnyAttachable(attachableValue: attachment.attachableValue),
9191
fileSystemPath: attachment.fileSystemPath,

Tests/TestingTests/AttachmentTests.swift

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
@testable @_spi(Experimental) @_spi(ForToolsIntegrationOnly) import Testing
1212
private import _TestingInternals
13+
1314
#if canImport(Foundation)
1415
import Foundation
1516
@_spi(Experimental) import _Testing_Foundation
@@ -82,7 +83,7 @@ struct AttachmentTests {
8283

8384
@Test func writeAttachmentWithMultiplePathExtensions() throws {
8485
let attachableValue = MySendableAttachable(string: "<!doctype html>")
85-
let attachment = Test.Attachment(attachableValue, named: "loremipsum.tgz.gif.jpeg.html")
86+
let attachment = Test.Attachment(attachableValue, named: "loremipsum.tar.gz.gif.jpeg.html")
8687

8788
// Write the attachment to disk once to ensure the original filename is not
8889
// available and we add a suffix.
@@ -98,22 +99,30 @@ struct AttachmentTests {
9899
remove(filePath)
99100
}
100101
let fileName = try #require(filePath.split { $0 == "/" || $0 == #"\"# }.last)
101-
#expect(fileName == "loremipsum-\(suffix).tgz.gif.jpeg.html")
102+
#expect(fileName == "loremipsum-\(suffix).tar.gz.gif.jpeg.html")
102103
try compare(attachableValue, toContentsOfFileAtPath: filePath)
103104
}
104105

105106
#if os(Windows)
106107
static let maximumNameCount = Int(_MAX_FNAME)
108+
static let reservedNames: [String] = {
109+
// Return the list of COM ports that are NOT configured (and so will fail
110+
// to open for writing.)
111+
(0...9).lazy
112+
.map { "COM\($0)" }
113+
.filter { !PathFileExistsA($0) }
114+
}()
107115
#else
108116
static let maximumNameCount = Int(NAME_MAX)
117+
static let reservedNames: [String] = []
109118
#endif
110119

111120
@Test(arguments: [
112121
#"/\:"#,
113122
String(repeating: "a", count: maximumNameCount),
114123
String(repeating: "a", count: maximumNameCount + 1),
115124
String(repeating: "a", count: maximumNameCount + 2),
116-
]) func writeAttachmentWithBadName(name: String) throws {
125+
] + reservedNames) func writeAttachmentWithBadName(name: String) throws {
117126
let attachableValue = MySendableAttachable(string: "<!doctype html>")
118127
let attachment = Test.Attachment(attachableValue, named: name)
119128

@@ -240,7 +249,7 @@ struct AttachmentTests {
240249

241250
#expect(attachment.preferredName == temporaryFileName)
242251
#expect(throws: Never.self) {
243-
try attachment.withUnsafeBufferPointer { buffer in
252+
try attachment.attachableValue.withUnsafeBufferPointer(for: attachment) { buffer in
244253
#expect(buffer.count == data.count)
245254
}
246255
}
@@ -357,22 +366,21 @@ struct AttachmentTests {
357366
name = "\(name).\(ext)"
358367
}
359368

360-
func open<T>(_ attachment: borrowing Test.Attachment<T>) throws where T: Test.Attachable {
361-
try attachment.attachableValue.withUnsafeBufferPointer(for: attachment) { bytes in
362-
#expect(bytes.first == args.firstCharacter.asciiValue)
363-
let decodedStringValue = try args.decode(Data(bytes))
364-
#expect(decodedStringValue == "stringly speaking")
365-
}
366-
}
367-
369+
let attachmentCopy: Test.Attachment<Test.AnyAttachable>
368370
if args.forSecureCoding {
369371
let attachableValue = MySecureCodingAttachable(string: "stringly speaking")
370372
let attachment = Test.Attachment(attachableValue, named: name)
371-
try open(attachment)
373+
attachmentCopy = Test.Attachment<Test.AnyAttachable>(attachment)
372374
} else {
373375
let attachableValue = MyCodableAttachable(string: "stringly speaking")
374376
let attachment = Test.Attachment(attachableValue, named: name)
375-
try open(attachment)
377+
attachmentCopy = Test.Attachment<Test.AnyAttachable>(attachment)
378+
}
379+
380+
try attachmentCopy.withUnsafeBufferPointer { bytes in
381+
#expect(bytes.first == args.firstCharacter.asciiValue)
382+
let decodedStringValue = try args.decode(Data(bytes))
383+
#expect(decodedStringValue == "stringly speaking")
376384
}
377385
}
378386

@@ -460,13 +468,6 @@ extension AttachmentTests {
460468
let value: Substring = "abc123"[...]
461469
try test(value)
462470
}
463-
464-
#if canImport(Foundation)
465-
@Test func data() throws {
466-
let value = try #require("abc123".data(using: .utf8))
467-
try test(value)
468-
}
469-
#endif
470471
}
471472
}
472473

0 commit comments

Comments
 (0)