swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.27k stars 10.33k forks source link

I want to zip more than 3 values in parameterized testing #68896

Open uhooi opened 11 months ago

uhooi commented 11 months ago

Description

SSIA

Alternatively, I want to pass arguments as tuples.

    @Test(arguments: [
        (nil, "name", "description", UIImage()),
        (UIView(), nil, "description", UIImage()),
        (UIView(), "name", nil, UIImage()),
        (UIView(), "name", "description", nil),
    ])
    func didTapShareButton_one_nil(_ argument: (senderView: UIView?, name: String?, description: String?, icon: UIImage?)) {
        presenter.didTapShareButton(argument.senderView, name: argument.name, description: argument.description, icon: argument.icon)
        #expect(routerMock.showActivityCallCount == 0)
    }

Expected behavior

@Test("Can make large orders", arguments: zip(Food.allCases, 1 ... 100, 101 ... 200))
func makeLargeOrder(of food: Food, count: Int, count2: Int) async throws {
  let foodTruck = FoodTruck(selling: food)
  #expect(await foodTruck.cook(food, quantity: count))
}

Actual behavior

No response

Steps to reproduce

No response

swift-testing version/commit hash

70f5963

Swift & OS version (output of swift --version && uname -a)

$ swift --version && uname -a
swift-driver version: 1.87.1 Apple Swift version 5.9 (swiftlang-5.9.0.128.108 clang-1500.0.40.1)
Target: arm64-apple-macosx13.0
Darwin uhooinoMacBook-Air.local 22.6.0 Darwin Kernel Version 22.6.0: Wed Jul  5 22:22:52 PDT 2023; root:xnu-8796.141.3~6/RELEASE_ARM64_T8103 arm64
uhooi commented 11 months ago

I try to achieve this with struct, a build error will occur.

    struct DidTapShareButtonOneNilArgument {
        let senderView: UIView?
        let name: String?
        let description: String?
        let icon: UIImage?
    }
    @Test(arguments: [
        DidTapShareButtonOneNilArgument(senderView: nil, name: "name", description: "description", icon: UIImage()),
        DidTapShareButtonOneNilArgument(senderView: UIView(), name: nil, description: "description", icon: UIImage()),
        DidTapShareButtonOneNilArgument(senderView: UIView(), name: "name", description: nil, icon: UIImage()),
        DidTapShareButtonOneNilArgument(senderView: UIView(), name: "name", description: "description", icon: nil),
    ])
    func didTapShareButton_one_nil(_ argument: DidTapShareButtonOneNilArgument) {
        presenter.didTapShareButton(argument.senderView, name: argument.name, description: argument.description, icon: argument.icon)
        #expect(routerMock.showActivityCallCount == 0)
    }
/var/folders/26/0wffxqvn1s3f335cw1t7rq980000gn/T/swift-generated-sources/@__swiftmacro_14AppModuleTests022MonsterDetailPresenterC0V25didTapShareButton_one_nil4TestfMp_.swift:22:9: Expression is 'async' but is not marked with 'await'
スクリーンショット 2023-10-01 14 00 16
grynspan commented 11 months ago

zip() is part of the Swift standard library. Moving.

(Note that the error you're seeing should be resolved if you update your copy of swift-testing.)

uhooi commented 11 months ago

ref: https://developer.apple.com/documentation/swift/zip(_:_:)

uhooi commented 11 months ago

It would be easy to implement a zip() with an arbitrary number of arguments using parameter packs. ref: https://github.com/apple/swift-evolution/blob/main/proposals/0393-parameter-packs.md