Permalink
Browse files

RXAssert and RXAssertFalse can now take an optional message which rep…

…laces their own logged message.
  • Loading branch information...
1 parent c6f0744 commit f65d1939544b5b6c2ee7f608e7b643f75a0a32f8 @robrix committed Oct 15, 2009
Showing with 14 additions and 5 deletions.
  1. +7 −4 RXAssertions.h
  2. +1 −1 RXAssertions.xcodeproj/project.pbxproj
  3. +6 −0 RXAssertionsTests.m
View
@@ -6,15 +6,18 @@
// Assertion macros that don’t require you to describe the assertion. Perfect for use with intention-revealing code.
-#define RXAssert(_expression) {\
+// Don’t use this unless you’re writing your own assertions. The first argument is ignored, so the assertions can have optional messages appended to them.
+#define RXOptionalMessageFail(ignored, format, ...) STFail(format, ## __VA_ARGS__)
+
+#define RXAssert(_expression, ...) {\
__typeof__(_expression) __condition = (_expression);\
if(!__condition)\
- STFail(@"%s was unexpectedly false.", #_expression);\
+ RXOptionalMessageFail(, ## __VA_ARGS__, @"%s was unexpectedly false.", #_expression);\
}
-#define RXAssertFalse(_expression) {\
+#define RXAssertFalse(_expression, ...) {\
__typeof__(_expression) __condition = (_expression);\
if(__condition)\
- STFail(@"%s was unexpectedly true.", #_expression);\
+ RXOptionalMessageFail(, ## __VA_ARGS__, @"%s was unexpectedly true.", #_expression);\
}
// 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.
@@ -18,7 +18,7 @@
isa = PBXContainerItemProxy;
containerPortal = 0867D690FE84028FC02AAC07 /* Project object */;
proxyType = 1;
- remoteGlobalIDString = D2AAC07D0554694100DB518D /* RXAssertions */;
+ remoteGlobalIDString = D2AAC07D0554694100DB518D;
remoteInfo = RXAssertions;
};
/* End PBXContainerItemProxy section */
View
@@ -26,4 +26,10 @@ -(void)testDemonstrateFailures {
RXAssertNotNil(object);
}
+-(void)testCanAddOptionalFailureMessages {
+ BOOL condition = NO;
+ RXAssert(condition, @"This is a demonstration of an %@ failure", @"RXAssert");
+ RXAssertFalse(!condition, @"This is a demonstration of an %@ failure", @"RXAssertFalse");
+}
+
@end

0 comments on commit f65d193

Please sign in to comment.