# Are these "tuple splat" parameterized tests legit?

**URL:** <https://forums.swift.org/t/are-these-tuple-splat-parameterized-tests-legit/73250>\
**Category:** Swift Testing\
**Tags:** tuple\
**Created:** [July 18, 2024, 12:15am UTC](https://forums.swift.org/t/are-these-tuple-splat-parameterized-tests-legit/73250 "2024-07-18T00:15:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vanvoorden](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/vanvoorden/32/33619_2.png) [@vanvoorden](https://forums.swift.org/u/vanvoorden)\
**Post date:** [July 18, 2024, 12:15am UTC](https://forums.swift.org/t/are-these-tuple-splat-parameterized-tests-legit/73250/1 "2024-07-18T00:15:55Z")

</div>

Hi! I'm experimenting with parameterized testing in `swift-testing`. The documentation (and WWDC videos) I found highlight examples of:

- Passing a single sequence (to a test that accepts one parameter).
- Passing two sequences (to a test that accept two parameters).
- Passing one sequence of 2D tuples (to a test that accepts one parameter).

I have tests that would prefer to test three parameters. The workaround I have so far is to pass a single sequences of 3D tuples:

```swift
var array: Array<(x: Int, y: Int, z: Int)> {
  var array = Array<(x: Int, y: Int, z: Int)>()
  array.append((1, 2, 3))
  array.append((4, 5, 6))
  array.append((7, 8, 9))
  return array
}

@Test(arguments: array) func t1(arguments : (x: Int, y: Int, z: Int)) async throws {
  #expect(arguments.x != .zero)
  #expect(arguments.y != .zero)
  #expect(arguments.z != .zero)
}

```

This test builds (and passes)… but I notice that I also have the option of parameterizing the test _directly_ over the tuple elements:

```swift
var array: Array<(x: Int, y: Int, z: Int)> {
  var array = Array<(x: Int, y: Int, z: Int)>()
  array.append((1, 2, 3))
  array.append((4, 5, 6))
  array.append((7, 8, 9))
  return array
}

@Test(arguments: array) func t2(x: Int, y: Int, z: Int) async throws {
  #expect(x != .zero)
  #expect(y != .zero)
  #expect(z != .zero)
}

```

This is a nice shortcut… but I am wondering whether or not this is "legit" Swift. Here is another way of looking at my question:

```swift
var array: Array<(x: Int, y: Int, z: Int)> {
  var array = Array<(x: Int, y: Int, z: Int)>()
  array.append((1, 2, 3))
  array.append((4, 5, 6))
  array.append((7, 8, 9))
  return array
}

func f1(_: (x: Int, y: Int, z: Int)) {
  
}

func f2(x: Int, y: Int, z: Int) {
  
}

func main() {
  for element in array {
    f1(element)
    f2(element)
  }
}

```

This code fails to build:

```swift
11 | }
12 | 
13 | func f2(x: Int, y: Int, z: Int) {
   | `- note: 'f2(x:y:z:)' declared here
14 |   
15 | }
   :
18 | for element in array {
19 | f1(element)
20 | f2(element)
   | `- error: global function 'f2' expects 3 separate arguments
21 | }
22 | }

```

AFAIK this looks consistent with the removal of "tuple splat" behavior way back in [SE-0029](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0029-remove-implicit-tuple-splat.md).

My question then is back to this example from `swift-testing`… is this (tuple splat) pattern actually a legit way to parameterize a Swift test? Is the fact that this seems to build and run (as of `Xcode_16_beta_3`) any sign that this might be a legit (supported) pattern for `swift-testing` going forward?

Any more ideas or advice about that? Thanks!

---

<div class="post-metadata">

**Author:** ![grynspan](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/grynspan/32/15315_2.png) [@grynspan](https://forums.swift.org/u/grynspan)\
**Post date:** [July 18, 2024, 12:26am UTC](https://forums.swift.org/t/are-these-tuple-splat-parameterized-tests-legit/73250/2 "2024-07-18T00:26:44Z")

</div>

It's fully supported and is, in fact, a language feature, not just a Swift Testing feature. We use it in our own tests.

---

<div class="post-metadata">

**Author:** ![Quedlinbug](https://avatars.discourse-cdn.com/v4/letter/q/77aa72/32.png) [@Quedlinbug](https://forums.swift.org/u/Quedlinbug)\
**Post date:** [July 18, 2024, 4:14am UTC](https://forums.swift.org/t/are-these-tuple-splat-parameterized-tests-legit/73250/3 "2024-07-18T04:14:21Z")

</div>

> [@Using tuple pattern in closure parameters](https://forums.swift.org/t/using-tuple-pattern-in-closure-parameters/67917/5):
>
> It is fine to use, because it is a deliberate, special-case exception to the rules implemented in SE-0110:

* * *

This is one of the use cases of `forEach`.

```swift
let array = [
  (1, 2, 3),
  (4, 5, 6),
  (7, 8, 9)
]
func f1(_: (x: Int, y: Int, z: Int)) { }
func f2(x: Int, y: Int, z: Int) { }
array.forEach(f1)
array.forEach(f2)

```

The first form, which takes a tuple, will yield a usage warning for mismatched labels. Tests do not care about labels.

```swift
@Test(
  arguments: [
    (a: 1, b: 2, c: 3),
    (a: 4, b: 5, c: 6),
    (a: 7, b: 8, c: 9)
  ]
) func t1(x: Int, y: Int, z: Int) { }

@Test(
  arguments: [
    (1, 2, 3),
    (4, 5, 6),
    (7, 8, 9)
  ]
) func t2(x: Int, y: Int, z: Int) { }

```
