• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: STAssertEquals and type-checking
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: STAssertEquals and type-checking


  • Subject: Re: STAssertEquals and type-checking
  • From: Kyle Sluder <email@hidden>
  • Date: Tue, 16 Aug 2011 12:00:30 -0700

I suppose you could write some wrapper macros that use __typeof (or whatever that compiler-specific keyword is) to automatically cast your second argument to the type of the first argument. You could even limit it to "safe" conversions.

Look at tgmath.h for inspiration.

--Kyle Sluder
(Sent from the road)

On Aug 16, 2011, at 11:50 AM, Sean McBride <email@hidden> wrote:

> On Tue, 16 Aug 2011 10:36:57 -0700, Jens Alfke said:
>
>> I’ve been using the STxxx test macros lately, as they’re the path of
>> least resistance, but I’m getting pretty frustrated with them. Worst is
>> the way that STAssertEquals is extremely picky about types (the actual
>> and expected parameters have to have exactly the same type), and worse,
>> somehow manages to defer the type checking until runtime, so you only
>> find out when you get an assertion failure.
>>
>> So I keep making ‘mistakes’ like:
>>    STAssertEquals(myArray.length, 32, nil);
>> which compiles fine, but fails at runtime because -length returns an
>> NSUInteger and 32 is an int. Changing 32 to 32u works on 32-bit but not
>> 64-bit; the only form I’ve found that always works is the awkward
>>   STAssertEquals(digest.length, (NSUInteger)32, nil);
>> Not surprisingly, I still forget to do this pretty often.
>
> We've had the same experience, and the same solution I'm afraid. :(
>
> --
> ____________________________________________________________
> Sean McBride, B. Eng                 email@hidden
> Rogue Research                        www.rogue-research.com
> Mac Software Developer              Montréal, Québec, Canada
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: STAssertEquals and type-checking
      • From: Jens Alfke <email@hidden>
References: 
 >STAssertEquals and type-checking (From: Jens Alfke <email@hidden>)
 >Re: STAssertEquals and type-checking (From: Sean McBride <email@hidden>)

  • Prev by Date: Re: STAssertEquals and type-checking
  • Next by Date: Re: How can I prevent drag-and-drop initiation in an NSTextField
  • Previous by thread: Re: STAssertEquals and type-checking
  • Next by thread: Re: STAssertEquals and type-checking
  • Index(es):
    • Date
    • Thread