Skip to content

Commit ebbec50

Browse files
authored
Merge pull request #80217 from glessard/stdlibUnittest-wasi-skip
[StdlibUnittest] add a TestRunPredicate for WASI
2 parents a84db8f + d4eb4bd commit ebbec50

File tree

2 files changed

+51
-30
lines changed

2 files changed

+51
-30
lines changed

Diff for: stdlib/private/StdlibUnittest/StdlibUnittest.swift

+13
Original file line numberDiff line numberDiff line change
@@ -2444,6 +2444,8 @@ public enum TestRunPredicate : CustomStringConvertible {
24442444

24452445
case haikuAny(reason: String)
24462446

2447+
case wasiAny(reason: String)
2448+
24472449
case objCRuntime(/*reason:*/ String)
24482450
case nativeRuntime(/*reason:*/ String)
24492451

@@ -2565,6 +2567,9 @@ public enum TestRunPredicate : CustomStringConvertible {
25652567
case .haikuAny(reason: let reason):
25662568
return "haikuAny(*, reason: \(reason))"
25672569

2570+
case .wasiAny(reason: let reason):
2571+
return "wasiAny(*, reason: \(reason))"
2572+
25682573
case .objCRuntime(let reason):
25692574
return "Objective-C runtime, reason: \(reason))"
25702575
case .nativeRuntime(let reason):
@@ -2947,6 +2952,14 @@ public enum TestRunPredicate : CustomStringConvertible {
29472952
return false
29482953
}
29492954

2955+
case .wasiAny:
2956+
switch _getRunningOSVersion() {
2957+
case .wasi:
2958+
return true
2959+
default:
2960+
return false
2961+
}
2962+
29502963
case .objCRuntime:
29512964
#if _runtime(_ObjC)
29522965
return true

Diff for: test/stdlib/UnsafeRawBufferPointer.swift

+38-30
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,8 @@ UnsafeRawBufferPointerTestSuite.test("initFromArray") {
131131
expectEqual(array2, array1)
132132
}
133133

134-
#if !os(WASI)
135-
// Trap tests aren't available on WASI.
136-
UnsafeRawBufferPointerTestSuite.test("initializeMemory(as:from:).underflow") {
134+
UnsafeRawBufferPointerTestSuite.test("initializeMemory(as:from:).underflow")
135+
.skip(.wasiAny(reason: "Trap tests aren't supported on WASI.")).code {
137136
let buffer = UnsafeMutableRawBufferPointer.allocate(
138137
byteCount: 30,
139138
alignment: MemoryLayout<UInt64>.alignment
@@ -152,7 +151,8 @@ UnsafeRawBufferPointerTestSuite.test("initializeMemory(as:from:).underflow") {
152151
expectEqualSequence([5, 4, 3],bound)
153152
}
154153

155-
UnsafeRawBufferPointerTestSuite.test("initializeMemory(as:from:).overflow") {
154+
UnsafeRawBufferPointerTestSuite.test("initializeMemory(as:from:).overflow")
155+
.skip(.wasiAny(reason: "Trap tests aren't supported on WASI.")).code {
156156
let buffer = UnsafeMutableRawBufferPointer.allocate(
157157
byteCount: 30,
158158
alignment: MemoryLayout<UInt64>.alignment
@@ -170,7 +170,6 @@ UnsafeRawBufferPointerTestSuite.test("initializeMemory(as:from:).overflow") {
170170
expected.withUnsafeBytes { expectEqualSequence($0,buffer[0..<idx]) }
171171
expectEqualSequence([5, 4, 3],bound)
172172
}
173-
#endif
174173

175174
UnsafeRawBufferPointerTestSuite.test("initializeMemory(as:from:).exact") {
176175
let buffer = UnsafeMutableRawBufferPointer.allocate(
@@ -187,15 +186,13 @@ UnsafeRawBufferPointerTestSuite.test("initializeMemory(as:from:).exact") {
187186
expectEqualSequence([5, 4, 3],bound)
188187
}
189188

190-
#if !os(WASI)
191-
// Trap tests aren't available on WASI.
192-
UnsafeRawBufferPointerTestSuite.test("initializeMemory(as:from:).invalidNilPtr") {
189+
UnsafeRawBufferPointerTestSuite.test("initializeMemory(as:from:).invalidNilPtr")
190+
.skip(.wasiAny(reason: "Trap tests aren't supported on WASI.")).code {
193191
let buffer = UnsafeMutableRawBufferPointer(start: nil, count: 0)
194192
let source: [Int64] = [5, 4, 3, 2, 1]
195193
expectCrashLater()
196194
_ = buffer.initializeMemory(as: Int64.self, from: source)
197195
}
198-
#endif
199196

200197
UnsafeRawBufferPointerTestSuite.test("initializeMemory(as:from:).validNilPtr") {
201198
let buffer = UnsafeMutableRawBufferPointer(start: nil, count: 0)
@@ -305,9 +302,8 @@ UnsafeRawBufferPointerTestSuite.test("inBounds") {
305302
expectEqualSequence(firstHalf, secondHalf)
306303
}
307304

308-
#if !os(WASI)
309-
// Trap tests aren't available on WASI.
310-
UnsafeRawBufferPointerTestSuite.test("subscript.get.underflow") {
305+
UnsafeRawBufferPointerTestSuite.test("subscript.get.underflow")
306+
.skip(.wasiAny(reason: "Trap tests aren't supported on WASI.")).code {
311307
let buffer = UnsafeMutableRawBufferPointer.allocate(
312308
byteCount: 2,
313309
alignment: MemoryLayout<UInt>.alignment
@@ -323,7 +319,8 @@ UnsafeRawBufferPointerTestSuite.test("subscript.get.underflow") {
323319
_ = bytes[-1]
324320
}
325321

326-
UnsafeRawBufferPointerTestSuite.test("subscript.get.overflow") {
322+
UnsafeRawBufferPointerTestSuite.test("subscript.get.overflow")
323+
.skip(.wasiAny(reason: "Trap tests aren't supported on WASI.")).code {
327324
let buffer = UnsafeMutableRawBufferPointer.allocate(
328325
byteCount: 2,
329326
alignment: MemoryLayout<UInt>.alignment
@@ -339,7 +336,8 @@ UnsafeRawBufferPointerTestSuite.test("subscript.get.overflow") {
339336
_ = bytes[1]
340337
}
341338

342-
UnsafeRawBufferPointerTestSuite.test("subscript.set.underflow") {
339+
UnsafeRawBufferPointerTestSuite.test("subscript.set.underflow")
340+
.skip(.wasiAny(reason: "Trap tests aren't supported on WASI.")).code {
343341
let buffer = UnsafeMutableRawBufferPointer.allocate(
344342
byteCount: 2,
345343
alignment: MemoryLayout<UInt>.alignment
@@ -355,7 +353,8 @@ UnsafeRawBufferPointerTestSuite.test("subscript.set.underflow") {
355353
bytes[-1] = 0
356354
}
357355

358-
UnsafeRawBufferPointerTestSuite.test("subscript.set.overflow") {
356+
UnsafeRawBufferPointerTestSuite.test("subscript.set.overflow")
357+
.skip(.wasiAny(reason: "Trap tests aren't supported on WASI.")).code {
359358
let buffer = UnsafeMutableRawBufferPointer.allocate(
360359
byteCount: 2,
361360
alignment: MemoryLayout<UInt>.alignment
@@ -371,7 +370,8 @@ UnsafeRawBufferPointerTestSuite.test("subscript.set.overflow") {
371370
bytes[1] = 0
372371
}
373372

374-
UnsafeRawBufferPointerTestSuite.test("subscript.range.get.underflow") {
373+
UnsafeRawBufferPointerTestSuite.test("subscript.range.get.underflow")
374+
.skip(.wasiAny(reason: "Trap tests aren't supported on WASI.")).code {
375375
let buffer = UnsafeMutableRawBufferPointer.allocate(
376376
byteCount: 3,
377377
alignment: MemoryLayout<UInt>.alignment
@@ -387,7 +387,8 @@ UnsafeRawBufferPointerTestSuite.test("subscript.range.get.underflow") {
387387
_ = bytes[-1..<1]
388388
}
389389

390-
UnsafeRawBufferPointerTestSuite.test("subscript.range.get.overflow") {
390+
UnsafeRawBufferPointerTestSuite.test("subscript.range.get.overflow")
391+
.skip(.wasiAny(reason: "Trap tests aren't supported on WASI.")).code {
391392
let buffer = UnsafeMutableRawBufferPointer.allocate(
392393
byteCount: 3,
393394
alignment: MemoryLayout<UInt>.alignment
@@ -403,7 +404,8 @@ UnsafeRawBufferPointerTestSuite.test("subscript.range.get.overflow") {
403404
_ = bytes[1..<3]
404405
}
405406

406-
UnsafeRawBufferPointerTestSuite.test("subscript.range.set.underflow") {
407+
UnsafeRawBufferPointerTestSuite.test("subscript.range.set.underflow")
408+
.skip(.wasiAny(reason: "Trap tests aren't supported on WASI.")).code {
407409
let buffer = UnsafeMutableRawBufferPointer.allocate(
408410
byteCount: 3,
409411
alignment: MemoryLayout<UInt>.alignment
@@ -419,7 +421,8 @@ UnsafeRawBufferPointerTestSuite.test("subscript.range.set.underflow") {
419421
bytes[-1..<1] = bytes[0..<2]
420422
}
421423

422-
UnsafeRawBufferPointerTestSuite.test("subscript.range.set.overflow") {
424+
UnsafeRawBufferPointerTestSuite.test("subscript.range.set.overflow")
425+
.skip(.wasiAny(reason: "Trap tests aren't supported on WASI.")).code {
423426
let buffer = UnsafeMutableRawBufferPointer.allocate(
424427
byteCount: 3,
425428
alignment: MemoryLayout<UInt>.alignment
@@ -436,7 +439,8 @@ UnsafeRawBufferPointerTestSuite.test("subscript.range.set.overflow") {
436439
bytes[1..<3] = bytes[0..<2]
437440
}
438441

439-
UnsafeRawBufferPointerTestSuite.test("subscript.range.narrow") {
442+
UnsafeRawBufferPointerTestSuite.test("subscript.range.narrow")
443+
.skip(.wasiAny(reason: "Trap tests aren't supported on WASI.")).code {
440444
let buffer = UnsafeMutableRawBufferPointer.allocate(
441445
byteCount: 3,
442446
alignment: MemoryLayout<UInt>.alignment
@@ -450,7 +454,8 @@ UnsafeRawBufferPointerTestSuite.test("subscript.range.narrow") {
450454
buffer[0..<3] = buffer[0..<2]
451455
}
452456

453-
UnsafeRawBufferPointerTestSuite.test("subscript.range.wide") {
457+
UnsafeRawBufferPointerTestSuite.test("subscript.range.wide")
458+
.skip(.wasiAny(reason: "Trap tests aren't supported on WASI.")).code {
454459
let buffer = UnsafeMutableRawBufferPointer.allocate(
455460
byteCount: 3,
456461
alignment: MemoryLayout<UInt>.alignment
@@ -463,7 +468,6 @@ UnsafeRawBufferPointerTestSuite.test("subscript.range.wide") {
463468
// Performs a valid byte-wise copy but triggers a debug bounds check.
464469
buffer[0..<2] = buffer[0..<3]
465470
}
466-
#endif
467471

468472
UnsafeRawBufferPointerTestSuite.test("_copyContents") {
469473
let a = Array<UInt8>(0..<20)
@@ -477,9 +481,8 @@ UnsafeRawBufferPointerTestSuite.test("_copyContents") {
477481
expectEqual(written, a.count)
478482
}
479483

480-
#if !os(WASI)
481-
// Trap tests aren't available on WASI.
482-
UnsafeRawBufferPointerTestSuite.test("copyMemory.overflow") {
484+
UnsafeRawBufferPointerTestSuite.test("copyMemory.overflow")
485+
.skip(.wasiAny(reason: "Trap tests aren't supported on WASI.")).code {
483486
let buffer = UnsafeMutableRawBufferPointer.allocate(
484487
byteCount: 3,
485488
alignment: MemoryLayout<UInt>.alignment
@@ -495,7 +498,6 @@ UnsafeRawBufferPointerTestSuite.test("copyMemory.overflow") {
495498
UnsafeMutableRawBufferPointer(rebasing: bytes).copyMemory(
496499
from: UnsafeRawBufferPointer(buffer))
497500
}
498-
#endif
499501

500502
// Use copyBytes without contiguous storage
501503
UnsafeRawBufferPointerTestSuite.test("copyBytes.withoutContiguousStorage") {
@@ -510,9 +512,8 @@ UnsafeRawBufferPointerTestSuite.test("copyBytes.withoutContiguousStorage") {
510512
}
511513
}
512514

513-
#if !os(WASI)
514-
// Trap tests aren't available on WASI.
515-
UnsafeRawBufferPointerTestSuite.test("copyBytes.sequence.overflow") {
515+
UnsafeRawBufferPointerTestSuite.test("copyBytes.sequence.overflow")
516+
.skip(.wasiAny(reason: "Trap tests aren't supported on WASI.")).code {
516517
let buffer = UnsafeMutableRawBufferPointer.allocate(
517518
byteCount: 3,
518519
alignment: MemoryLayout<UInt>.alignment
@@ -530,6 +531,7 @@ UnsafeRawBufferPointerTestSuite.test("copyBytes.sequence.overflow") {
530531
}
531532

532533
UnsafeRawBufferPointerTestSuite.test("load.before")
534+
.skip(.wasiAny(reason: "Trap tests aren't supported on WASI."))
533535
.skip(.custom(
534536
{ !_isDebugAssertConfiguration() },
535537
reason: "This tests a debug precondition."))
@@ -542,6 +544,7 @@ UnsafeRawBufferPointerTestSuite.test("load.before")
542544
}
543545

544546
UnsafeRawBufferPointerTestSuite.test("load.after")
547+
.skip(.wasiAny(reason: "Trap tests aren't supported on WASI."))
545548
.skip(.custom(
546549
{ !_isDebugAssertConfiguration() },
547550
reason: "This tests a debug precondition.."))
@@ -566,6 +569,7 @@ UnsafeRawBufferPointerTestSuite.test("load.aligned") {
566569
}
567570

568571
UnsafeRawBufferPointerTestSuite.test("load.invalid")
572+
.skip(.wasiAny(reason: "Trap tests aren't supported on WASI."))
569573
.skip(.custom({ !_isDebugAssertConfiguration() }, // require debugAssert
570574
reason: "This tests a debug precondition.."))
571575
.code {
@@ -594,6 +598,7 @@ UnsafeRawBufferPointerTestSuite.test("load.unaligned")
594598
}
595599

596600
UnsafeRawBufferPointerTestSuite.test("store.before")
601+
.skip(.wasiAny(reason: "Trap tests aren't supported on WASI."))
597602
.skip(.custom(
598603
{ !_isDebugAssertConfiguration() },
599604
reason: "This tests a debug precondition.."))
@@ -605,6 +610,7 @@ UnsafeRawBufferPointerTestSuite.test("store.before")
605610
}
606611
}
607612
UnsafeRawBufferPointerTestSuite.test("store.after")
613+
.skip(.wasiAny(reason: "Trap tests aren't supported on WASI."))
608614
.skip(.custom(
609615
{ !_isDebugAssertConfiguration() },
610616
reason: "This tests a debug precondition.."))
@@ -641,6 +647,7 @@ UnsafeRawBufferPointerTestSuite.test("store.unaligned")
641647
}
642648

643649
UnsafeRawBufferPointerTestSuite.test("store.invalid")
650+
.skip(.wasiAny(reason: "Trap tests aren't supported on WASI."))
644651
.skip(.custom({ !_isDebugAssertConfiguration() }, // require debugAssert
645652
reason: "This tests a debug precondition.."))
646653
.require(.stdlib_5_7)
@@ -666,6 +673,7 @@ UnsafeRawBufferPointerTestSuite.test("store.valid") {
666673
}
667674

668675
UnsafeRawBufferPointerTestSuite.test("copy.bytes.overflow")
676+
.skip(.wasiAny(reason: "Trap tests aren't supported on WASI."))
669677
.skip(.custom(
670678
{ !_isDebugAssertConfiguration() },
671679
reason: "This tests a debug precondition.."))
@@ -682,6 +690,7 @@ UnsafeRawBufferPointerTestSuite.test("copy.bytes.overflow")
682690
}
683691

684692
UnsafeRawBufferPointerTestSuite.test("copy.sequence.overflow")
693+
.skip(.wasiAny(reason: "Trap tests aren't supported on WASI."))
685694
.skip(.custom(
686695
{ !_isDebugAssertConfiguration() },
687696
reason: "This tests a debug precondition.."))
@@ -695,7 +704,6 @@ UnsafeRawBufferPointerTestSuite.test("copy.sequence.overflow")
695704
}
696705
}
697706
}
698-
#endif
699707

700708
UnsafeRawBufferPointerTestSuite.test("copy.overlap") {
701709
let bytes = UnsafeMutableRawBufferPointer.allocate(

0 commit comments

Comments
 (0)