fix(tests): normalize lastPathComponent for Linux Foundation

Darwin's Foundation returns String from URL.lastPathComponent;
swift-corelibs-foundation on this toolchain returns String?. The three
uses in TaggedNodeCorpusRoundTripTests (a sort comparator and two
Testing.Comment interpolations) compiled on Darwin but failed the
Linux build outright, an unrelated pre-existing gap surfaced while
verifying the anchor-expansion-bomb fix on the Linux CI relay.

An explicit `(url.lastPathComponent as String?) ?? ""` coercion makes
both platforms produce a uniform String? before the `??`, rather than
picking one platform's non-optional type and breaking the other.

Verified via a full clean macOS build and test run (674 tests, all
passing) and swiftformat/swiftlint --strict clean.
This commit is contained in:
Mihaela Mihaljevic 2026-07-18 23:43:59 +02:00
parent 1bbf715fa5
commit d465f500e3
2 changed files with 16 additions and 3 deletions

View File

@ -446,6 +446,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
produce. A document with genuinely wide but non-exponential alias
reuse (the same anchor referenced thousands of times at one level, no
nesting) still parses normally.
- `TaggedNodeCorpusRoundTripTests` now normalizes `URL.lastPathComponent`
through an explicit `as String?` coercion before use: this toolchain's
swift-corelibs-foundation returns `String?` where Darwin's Foundation
returns `String`, and the mismatch failed the Linux build outright
(an unrelated pre-existing gap surfaced while verifying the
anchor-expansion fix above on the Linux CI relay).
## [0.2.0] - 2026-07-05

View File

@ -19,7 +19,14 @@ struct TaggedNodeCorpusRoundTripTests {
))
var accepted = 0
var rejected = 0
for url in urls.sorted(by: { $0.lastPathComponent < $1.lastPathComponent }) {
/// `URL.lastPathComponent` is `String` on Darwin's Foundation but `String?` on this
/// toolchain's swift-corelibs-foundation; the explicit `as String?` upcast/coercion makes
/// both platforms produce a uniform `String?` here so `?? ""` compiles identically either
/// way, rather than picking one platform's non-optional type and breaking the other.
func name(_ url: URL) -> String {
(url.lastPathComponent as String?) ?? ""
}
for url in urls.sorted(by: { name($0) < name($1) }) {
let source = try String(contentsOf: url, encoding: .utf8)
let parsed: PureYAML.Tagged.Node
do {
@ -34,11 +41,11 @@ struct TaggedNodeCorpusRoundTripTests {
do {
reparsed = try PureYAML.parseTagged(dumped)
} catch {
Issue.record("\(url.lastPathComponent): dump produced unparseable YAML: \(error)")
Issue.record("\(name(url)): dump produced unparseable YAML: \(error)")
continue
}
if let detail = firstDivergence(parsed, reparsed, path: "$") {
Issue.record("\(url.lastPathComponent): \(detail)")
Issue.record("\(name(url)): \(detail)")
}
}
#expect(accepted > 0)