Skip to content

Miscellaneous bookkeeping/cleanup of _TestDiscovery. #1055

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions Sources/TestingMacros/Support/TestContentGeneration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,10 @@ enum TestContentKind: UInt32 {
/// This kind value as a comment (`/* 'abcd' */`) if it looks like it might be
/// a [FourCC](https://en.wikipedia.org/wiki/FourCC) value, or `nil` if not.
var commentRepresentation: Trivia {
switch self {
case .testDeclaration:
.blockComment("/* 'test' */")
case .exitTest:
.blockComment("/* 'exit' */")
let stringValue = withUnsafeBytes(of: self.rawValue.bigEndian) { bytes in
String(decoding: bytes, as: Unicode.ASCII.self)
}
return .blockComment("/* '\(stringValue)' */")
}
}

Expand Down
2 changes: 2 additions & 0 deletions Sources/_TestDiscovery/DiscoverableAsTestContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ public protocol DiscoverableAsTestContent: Sendable, ~Copyable {
#endif
}

#if !SWT_NO_LEGACY_TEST_DISCOVERY
extension DiscoverableAsTestContent where Self: ~Copyable {
public static var _testContentTypeNameHint: String {
"__🟡$"
}
}
#endif
10 changes: 5 additions & 5 deletions Sources/_TestDiscovery/SectionBounds.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ extension SectionBounds.Kind {
/// The Mach-O segment and section name for this instance as a pair of
/// null-terminated UTF-8 C strings and pass them to a function.
///
/// The values of this property within this function are instances of
/// `StaticString` rather than `String` because the latter's inner storage is
/// sometimes Objective-C-backed and touching it here can cause a recursive
/// access to an internal libobjc lock, whereas `StaticString`'s internal
/// storage is immediately available.
/// The values of this property are instances of `StaticString` rather than
/// `String` because the latter's inner storage is sometimes backed by
/// Objective-C and touching it here can cause a recursive access to an
/// internal libobjc lock, whereas `StaticString`'s internal storage is
/// immediately available.
fileprivate var segmentAndSectionName: (segmentName: StaticString, sectionName: StaticString) {
switch self {
case .testContent:
Expand Down
13 changes: 6 additions & 7 deletions Sources/_TestDiscovery/TestContentKind.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ extension TestContentKind: Codable {}

extension TestContentKind: ExpressibleByStringLiteral, ExpressibleByIntegerLiteral {
@inlinable public init(stringLiteral stringValue: StaticString) {
precondition(stringValue.utf8CodeUnitCount == MemoryLayout<UInt32>.stride, #""\#(stringValue)".utf8CodeUnitCount = \#(stringValue.utf8CodeUnitCount), expected \#(MemoryLayout<UInt32>.stride)"#)
let rawValue = stringValue.withUTF8Buffer { stringValue in
precondition(stringValue.count == MemoryLayout<UInt32>.stride, #""\#(stringValue)".utf8CodeUnitCount = \#(stringValue.count), expected \#(MemoryLayout<UInt32>.stride)"#)
let bigEndian = UnsafeRawBufferPointer(stringValue).loadUnaligned(as: UInt32.self)
return UInt32(bigEndian: bigEndian)
}
Expand All @@ -81,12 +81,11 @@ extension TestContentKind: CustomStringConvertible {
/// value, or `nil` if not.
private var _fourCCValue: String? {
withUnsafeBytes(of: rawValue.bigEndian) { bytes in
if bytes.allSatisfy(Unicode.ASCII.isASCII) {
let characters = String(decoding: bytes, as: Unicode.ASCII.self)
let allAlphanumeric = characters.allSatisfy { $0.isLetter || $0.isWholeNumber }
if allAlphanumeric {
return characters
}
let allPrintableASCII = bytes.allSatisfy { byte in
Unicode.ASCII.isASCII(byte) && 0 != isprint(CInt(byte))
}
if allPrintableASCII {
return String(decoding: bytes, as: Unicode.ASCII.self)
}
return nil
}
Expand Down
1 change: 1 addition & 0 deletions Sources/_TestingInternals/include/Includes.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
///
/// - Note: Avoid including headers that aren't actually used.

#include <ctype.h>
#include <errno.h>
#include <inttypes.h>
/// Guard against including `signal.h` on WASI. The `signal.h` header file
Expand Down