test: three suites build and run on a 32-bit WASI target
Some checks failed
rules-freshness / rules (push) Failing after 13s

A literal above 2^31 is not an Int on wasm32, so those cases stay on 64-bit targets; WASI has no threads, so the nesting parse runs on the caller's stack there; the report files are written without the atomic rename WASI does not offer.
This commit is contained in:
Mihaela Mihaljevic 2026-11-14 19:18:06 +01:00
parent 0f9164be1b
commit 108447bcab
3 changed files with 41 additions and 17 deletions

View File

@ -8,11 +8,16 @@ struct NumericCodingLadderTests {
#expect(try PureYAML.decode(Int8.self, from: .int(100)) == 100)
#expect(try PureYAML.decode(Int16.self, from: .int(30000)) == 30000)
#expect(try PureYAML.decode(Int32.self, from: .int(2_000_000_000)) == 2_000_000_000)
#expect(try PureYAML.decode(Int64.self, from: .int(9_000_000_000)) == 9_000_000_000)
#if !arch(wasm32)
// `Model.Value.int` holds an `Int`; on a 32-bit platform no `Int` is above 2^31 - 1, so these cannot be written there.
#expect(try PureYAML.decode(Int64.self, from: .int(9_000_000_000)) == 9_000_000_000)
#expect(try PureYAML.decode(UInt32.self, from: .int(4_000_000_000)) == 4_000_000_000)
#endif
#expect(try PureYAML.decode(Int64.self, from: .int(2_000_000_000)) == 2_000_000_000)
#expect(try PureYAML.decode(UInt.self, from: .int(42)) == 42)
#expect(try PureYAML.decode(UInt8.self, from: .int(200)) == 200)
#expect(try PureYAML.decode(UInt16.self, from: .int(60000)) == 60000)
#expect(try PureYAML.decode(UInt32.self, from: .int(4_000_000_000)) == 4_000_000_000)
#expect(try PureYAML.decode(UInt32.self, from: .int(2_000_000_000)) == 2_000_000_000)
#expect(try PureYAML.decode(UInt64.self, from: .int(42)) == 42)
}
@ -20,10 +25,14 @@ struct NumericCodingLadderTests {
func test_outOfRangeDecodeReportsExactTypePerWidth() {
expectDecodeOutOfRange(Int8.self, "Int8", .int(1000))
expectDecodeOutOfRange(Int16.self, "Int16", .int(40000))
expectDecodeOutOfRange(Int32.self, "Int32", .int(5_000_000_000))
#if !arch(wasm32)
// Not writable as an `Int` on a 32-bit platform, where every `Int` fits an `Int32`.
expectDecodeOutOfRange(Int32.self, "Int32", .int(5_000_000_000))
expectDecodeOutOfRange(UInt32.self, "UInt32", .int(5_000_000_000))
#endif
expectDecodeOutOfRange(UInt8.self, "UInt8", .int(300))
expectDecodeOutOfRange(UInt16.self, "UInt16", .int(70000))
expectDecodeOutOfRange(UInt32.self, "UInt32", .int(5_000_000_000))
expectDecodeOutOfRange(UInt32.self, "UInt32", .int(-1))
// Negative into an unsigned width is also out of range.
expectDecodeOutOfRange(UInt8.self, "UInt8", .int(-1))
expectDecodeOutOfRange(UInt.self, "UInt", .int(-1))

View File

@ -16,10 +16,10 @@ struct ParsingNestingLimitTests {
var otherError: (any Error)?
}
private func parseOnGenerousStack(_ yaml: String) -> ParseOutcome {
let outcome = ParseOutcome()
let done = DispatchSemaphore(value: 0)
let thread = Thread {
#if os(WASI)
/// WASI has no threads, so the parse runs on the caller's stack; the runtime's own stack size is what is tested there.
private func parseOnGenerousStack(_ yaml: String) -> ParseOutcome {
let outcome = ParseOutcome()
do {
outcome.value = try PureYAML.parse(yaml)
} catch let error as PureYAML.Parsing.ParseError {
@ -27,13 +27,28 @@ struct ParsingNestingLimitTests {
} catch {
outcome.otherError = error
}
done.signal()
return outcome
}
thread.stackSize = 16 * 1024 * 1024
thread.start()
done.wait()
return outcome
}
#else
private func parseOnGenerousStack(_ yaml: String) -> ParseOutcome {
let outcome = ParseOutcome()
let done = DispatchSemaphore(value: 0)
let thread = Thread {
do {
outcome.value = try PureYAML.parse(yaml)
} catch let error as PureYAML.Parsing.ParseError {
outcome.parseError = error
} catch {
outcome.otherError = error
}
done.signal()
}
thread.stackSize = 16 * 1024 * 1024
thread.start()
done.wait()
return outcome
}
#endif
@Test("Deeply nested flow collections throw nestingTooDeep instead of overflowing the stack")
func test_deepFlowThrowsCleanly() {

View File

@ -230,7 +230,7 @@ private func writeAndRead(report: PureYAML.Validation.BatchReport) throws -> Str
let file = directory.appendingPathComponent("validation-report.md")
try report.markdownDescription(title: "YAML Production Validation")
.write(to: file, atomically: true, encoding: .utf8)
.write(to: file, atomically: false, encoding: .utf8)
return try String(contentsOf: file, encoding: .utf8)
}
@ -245,8 +245,8 @@ private func writeAndReadMachineReports(
let yamlFile = directory.appendingPathComponent("validation-report.yaml")
let jsonFile = directory.appendingPathComponent("validation-report.json")
try report.yamlDescription(title: title).write(to: yamlFile, atomically: true, encoding: .utf8)
try report.jsonDescription(title: title).write(to: jsonFile, atomically: true, encoding: .utf8)
try report.yamlDescription(title: title).write(to: yamlFile, atomically: false, encoding: .utf8)
try report.jsonDescription(title: title).write(to: jsonFile, atomically: false, encoding: .utf8)
return try (
String(contentsOf: yamlFile, encoding: .utf8),
String(contentsOf: jsonFile, encoding: .utf8)