Permalink
Browse files

Reduced warning spam from the assert macros when a parameter causes a…

… warning.

The extra warnings were coming from the __typeof__ expressions, so now we take the type of the parameter itself only once (and the type of its evaluated value thereafter).
As an example, `RXAssertEquals([foo bar], 0)` would warn when -bar can’t be found, as expected… but it would warn six times. Now it’s down to twice. Unfortunately, I don’t believe it can be reduced any further since the initial __typeof__ expression is needed to store the value of the parameter (avoiding re-evaluating and potentially duplicating side-effects).
  • Loading branch information...
1 parent 6bc64fb commit e778dc4b8d0fdc3dcf3a2900157f97e3b10c3d4b @robrix committed May 18, 2010
Showing with 6 additions and 6 deletions.
  1. +6 −6 RXAssertions.h
View
@@ -22,15 +22,15 @@
// casts the expected value to the type of the actual value. will fail (and rightly so) if you try crazy casts like struct to pointer.
#define RXAssertEquals(_actual, _expected, ...) {\
- __typeof__(_actual) __actual = (_actual), __expected = (__typeof__(_actual))(_expected);\
- if(![RXAssertionHelper compareValue: &__actual withValue: &__expected ofObjCType: @encode(__typeof__(_actual))]) {\
- STFail(@"%s has value %@, not expected value %@. %@", #_actual, [RXAssertionHelper descriptionForValue: &__actual ofObjCType: @encode(__typeof__(_actual))], [RXAssertionHelper descriptionForValue: &__expected ofObjCType: @encode(__typeof__(_actual))], RXOptionalMessageString(, ## __VA_ARGS__, @""));\
+ __typeof__(_actual) __actual = (_actual), __expected = (__typeof__(__actual))(_expected);\
+ if(![RXAssertionHelper compareValue: &__actual withValue: &__expected ofObjCType: @encode(__typeof__(__actual))]) {\
+ STFail(@"%s has value %@, not expected value %@. %@", #_actual, [RXAssertionHelper descriptionForValue: &__actual ofObjCType: @encode(__typeof__(__actual))], [RXAssertionHelper descriptionForValue: &__expected ofObjCType: @encode(__typeof__(__actual))], RXOptionalMessageString(, ## __VA_ARGS__, @""));\
}\
}
#define RXAssertNotEquals(_actual, _expected, ...) {\
- __typeof__(_actual) __actual = (_actual), __expected = (__typeof__(_actual))(_expected);\
- if([RXAssertionHelper compareValue: &__actual withValue: &__expected ofObjCType: @encode(__typeof__(_actual))]) {\
- STFail(@"%s has unexpected value %@. %@", #_actual, [RXAssertionHelper descriptionForValue: &__actual ofObjCType: @encode(__typeof__(_actual))], RXOptionalMessageString(, ## __VA_ARGS__, @""));\
+ __typeof__(_actual) __actual = (_actual), __expected = (__typeof__(__actual))(_expected);\
+ if([RXAssertionHelper compareValue: &__actual withValue: &__expected ofObjCType: @encode(__typeof__(__actual))]) {\
+ STFail(@"%s has unexpected value %@. %@", #_actual, [RXAssertionHelper descriptionForValue: &__actual ofObjCType: @encode(__typeof__(__actual))], RXOptionalMessageString(, ## __VA_ARGS__, @""));\
}\
}

0 comments on commit e778dc4

Please sign in to comment.