[swift-users] Parameter Validation

David Hart david at wittywings.fr
Mon Dec 7 01:50:51 CST 2015


In that case, we really need a way to unit-test assertions, because unit-testing illegal parameters in a library seems critical.
David.

> On 07 Dec 2015, at 06:33, Jens Alfke <jens at mooseyard.com> wrote:
> 
> 
>> On Dec 6, 2015, at 12:49 PM, David Hart via swift-users <swift-users at swift.org <mailto:swift-users at swift.org>> wrote:
>> 
>> When writing library code, what method of parameter validation would be suggested?
> 
> Definitely assert. Assert is for illegal calls, i.e. programmer errors, while errors (throw) are for valid runtime error conditions.
> 
>> Cons
>> * Disabled in release
> 
> I believe there is a compiler flag to control this, if you want them enabled in the release.
> 
>> * Not unit-testable
> 
> 
> Well, you can’t create tests for rejection of illegal parameters. Which doesn’t seem like a huge loss to me. It would be nice to be able to do this, though. Maybe through some mechanism for catching / recovering from the otherwise-fatal exception triggered by an assert failure?
> 
> —Jens

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20151207/375648f9/attachment.html>


More information about the swift-users mailing list