[swift-users] Parameter Validation

Dmitri Gribenko gribozavr at gmail.com
Mon Dec 7 11:40:07 CST 2015

On Mon, Dec 7, 2015 at 9:25 AM, Jens Alfke <jens at mooseyard.com> wrote:
> On Dec 7, 2015, at 9:21 AM, Dmitri Gribenko <gribozavr at gmail.com> wrote:
> 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:
> Nice! But completely undocumented, AFAIK. This is the first I’ve heard of
> the term “trap”

We don't call them "crashes", because the word "crash" is typically
used to describe non-reliable program termination because of an
invalid memory unsafe operation that lead to memory corruption.  Traps
are guaranteed to happen, and they *prevent* memory unsafe operations
to happen, terminating the process before they happen.

> or a way to handle them. The docs I’ve seen just say that an
> assertion failure terminates the process.

Traps do terminate the process, without any way to recover, and that
is exactly what is happening in the standard library tests.  There are
just two processes -- one is performing a trap, and another one is the
test harness that verifies that the other process terminated.

> Is there any more info about traps, other than “Read the source, Luke?” ;-)

What would you like to know?


(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/

More information about the swift-users mailing list