[swift-users] Parameter Validation

Dmitri Gribenko gribozavr at gmail.com
Mon Dec 7 11:21:14 CST 2015


On Mon, Dec 7, 2015 at 9:03 AM, David Hart via swift-users <
swift-users at swift.org> wrote:

> But then you can't unit-test that the function fails on those parameters.
>

Yes you can.  Maybe not with the current XCTest, but there's nothing that
prevents unit-testing traps in principle.  The standard library is already
doing that.  See test/1_stdlib/ArrayTraps.swift.gyb for some examples:

ArrayTraps.test("downcast1")
  .skip(.Custom(
    { _isFastAssertConfiguration() },
    reason: "this trap is not guaranteed to happen in -Ounchecked"))
  .code {
  let ba: [Base] = [ Derived(), Base() ]
  let da = ba as! [Derived]
  let d0 = da[0]
  expectCrashLater()
  da[1]
}

Dmitri

-- 
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20151207/f120ca8b/attachment.html>


More information about the swift-users mailing list