Permalink
Browse files

LLVM fixes the C++ internal compiler error when using Objective-C blo…

…cks! A start at spec matchers with nicer syntax.
  • Loading branch information...
1 parent cf91051 commit 3e1bbaac2ce93f5feb4cd81e49bdd4b8ceaacc25 Adam Milligan committed Apr 21, 2011
@@ -25,10 +25,14 @@
/* Begin PBXBuildFile section */
66AEB6BE123C7CEE001C3DF1 /* CppSpecSpec.mm in Sources */ = {isa = PBXBuildFile; fileRef = AEEE1FEA11DC27B800029872 /* CppSpecSpec.mm */; };
66E33E53123CA82A00D326CC /* CppSpecSpec.mm in Sources */ = {isa = PBXBuildFile; fileRef = AEEE1FEA11DC27B800029872 /* CppSpecSpec.mm */; };
+ AE0B8563135F94DC001EEA23 /* ActualValue.mm in Sources */ = {isa = PBXBuildFile; fileRef = AEEE1FE511DC27B800029872 /* ActualValue.mm */; };
+ AE0B8564135F94DC001EEA23 /* ActualValue.mm in Sources */ = {isa = PBXBuildFile; fileRef = AEEE1FE511DC27B800029872 /* ActualValue.mm */; };
AE135D4011DEA6F400A922D4 /* OCMock.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AE135D3111DEA6A900A922D4 /* OCMock.framework */; };
AE135D4111DEA6F400A922D4 /* OCHamcrest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AE135D2111DEA69A00A922D4 /* OCHamcrest.framework */; };
AE135E7011DEB46F00A922D4 /* libOCMock-StaticLib.a in Frameworks */ = {isa = PBXBuildFile; fileRef = AE135D3511DEA6A900A922D4 /* libOCMock-StaticLib.a */; };
AE135E7111DEB46F00A922D4 /* libOCHamcrest-StaticLib.a in Frameworks */ = {isa = PBXBuildFile; fileRef = AE135D2311DEA69A00A922D4 /* libOCHamcrest-StaticLib.a */; };
+ AE8C867D135FAE76006C9305 /* ActualValue.h in Headers */ = {isa = PBXBuildFile; fileRef = AEEE1FE411DC27B800029872 /* ActualValue.h */; settings = {ATTRIBUTES = (Public, ); }; };
+ AE8C8680135FB4F7006C9305 /* ActualValue.h in Headers */ = {isa = PBXBuildFile; fileRef = AEEE1FE411DC27B800029872 /* ActualValue.h */; settings = {ATTRIBUTES = (Public, ); }; };
AE91CA6C11DE64A3002BA6B9 /* CDRSharedExampleGroupPool.h in Headers */ = {isa = PBXBuildFile; fileRef = AEFD17B311DD1E8200F4448A /* CDRSharedExampleGroupPool.h */; settings = {ATTRIBUTES = (Public, ); }; };
AE91CA6D11DE64B3002BA6B9 /* CDRSharedExampleGroupPool.h in Copy headers to framework */ = {isa = PBXBuildFile; fileRef = AEFD17B311DD1E8200F4448A /* CDRSharedExampleGroupPool.h */; };
AE9855AE1236E7080024094E /* CDRSharedExampleGroupPool.m in Sources */ = {isa = PBXBuildFile; fileRef = AEFD17B111DD1E7200F4448A /* CDRSharedExampleGroupPool.m */; };
@@ -60,7 +64,7 @@
AEEE21C211DC290400029872 /* SpecHelperSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = AEEE1FF011DC27B800029872 /* SpecHelperSpec.m */; };
AEEE21C311DC290400029872 /* SpecSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = AEEE1FF111DC27B800029872 /* SpecSpec.m */; };
AEEE21C411DC290400029872 /* SpecSpec2.m in Sources */ = {isa = PBXBuildFile; fileRef = AEEE1FF211DC27B800029872 /* SpecSpec2.m */; };
- AEEE220311DC29AC00029872 /* Cedar in Frameworks */ = {isa = PBXBuildFile; fileRef = AEEE1FB611DC271300029872 /* Cedar */; };
+ AEEE220311DC29AC00029872 /* Cedar.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AEEE1FB611DC271300029872 /* Cedar.framework */; };
AEEE223111DC2B6500029872 /* CDRDefaultReporter.m in Sources */ = {isa = PBXBuildFile; fileRef = AEEE1FC411DC27B800029872 /* CDRDefaultReporter.m */; };
AEEE223211DC2B6500029872 /* CDRExample.m in Sources */ = {isa = PBXBuildFile; fileRef = AEEE1FC511DC27B800029872 /* CDRExample.m */; };
AEEE223311DC2B6500029872 /* CDRExampleBase.m in Sources */ = {isa = PBXBuildFile; fileRef = AEEE1FC611DC27B800029872 /* CDRExampleBase.m */; };
@@ -214,7 +218,7 @@
AE135E8311DEB4E400A922D4 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = folder; name = Foundation.framework; sourceTree = SDKROOT; };
AEC9DEEA12C2CC7E0039512D /* CDRColorizedReporter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDRColorizedReporter.h; sourceTree = "<group>"; };
AEC9DEEB12C2CC7E0039512D /* CDRColorizedReporter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDRColorizedReporter.m; sourceTree = "<group>"; };
- AEEE1FB611DC271300029872 /* Cedar */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.framework; path = Cedar; sourceTree = BUILT_PRODUCTS_DIR; };
+ AEEE1FB611DC271300029872 /* Cedar.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Cedar.framework; sourceTree = BUILT_PRODUCTS_DIR; };
AEEE1FB811DC271300029872 /* Cedar-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Cedar-Info.plist"; sourceTree = "<group>"; };
AEEE1FC411DC27B800029872 /* CDRDefaultReporter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDRDefaultReporter.m; sourceTree = "<group>"; };
AEEE1FC511DC27B800029872 /* CDRExample.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDRExample.m; sourceTree = "<group>"; };
@@ -244,7 +248,7 @@
AEEE1FE011DC27B800029872 /* CDRSpecStatusCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDRSpecStatusCell.m; sourceTree = "<group>"; };
AEEE1FE111DC27B800029872 /* CDRSpecStatusViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDRSpecStatusViewController.m; sourceTree = "<group>"; };
AEEE1FE211DC27B800029872 /* CedarApplicationDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CedarApplicationDelegate.m; sourceTree = "<group>"; };
- AEEE1FE411DC27B800029872 /* ActualValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ActualValue.h; sourceTree = "<group>"; };
+ AEEE1FE411DC27B800029872 /* ActualValue.h */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.h; fileEncoding = 4; path = ActualValue.h; sourceTree = "<group>"; };
AEEE1FE511DC27B800029872 /* ActualValue.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ActualValue.mm; sourceTree = "<group>"; };
AEEE1FE611DC27B800029872 /* SpecHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SpecHelper.m; sourceTree = "<group>"; };
AEEE1FE811DC27B800029872 /* CDRExampleGroupSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDRExampleGroupSpec.m; sourceTree = "<group>"; };
@@ -257,7 +261,7 @@
AEEE1FF011DC27B800029872 /* SpecHelperSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SpecHelperSpec.m; sourceTree = "<group>"; };
AEEE1FF111DC27B800029872 /* SpecSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SpecSpec.m; sourceTree = "<group>"; };
AEEE1FF211DC27B800029872 /* SpecSpec2.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SpecSpec2.m; sourceTree = "<group>"; };
- AEEE218611DC28E200029872 /* Specs */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = "compiled.mach-o.executable"; path = Specs; sourceTree = BUILT_PRODUCTS_DIR; };
+ AEEE218611DC28E200029872 /* Specs */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = Specs; sourceTree = BUILT_PRODUCTS_DIR; };
AEEE222211DC2A1400029872 /* Rakefile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Rakefile; sourceTree = "<group>"; };
AEEE222311DC2A1400029872 /* README.markdown */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README.markdown; sourceTree = "<group>"; };
AEEE222911DC2B0600029872 /* libCedar-StaticLib.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libCedar-StaticLib.a"; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -281,7 +285,7 @@
files = (
AE135D4011DEA6F400A922D4 /* OCMock.framework in Frameworks */,
AE135D4111DEA6F400A922D4 /* OCHamcrest.framework in Frameworks */,
- AEEE220311DC29AC00029872 /* Cedar in Frameworks */,
+ AEEE220311DC29AC00029872 /* Cedar.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -352,7 +356,7 @@
AEEE1FB711DC271300029872 /* Products */ = {
isa = PBXGroup;
children = (
- AEEE1FB611DC271300029872 /* Cedar */,
+ AEEE1FB611DC271300029872 /* Cedar.framework */,
AEEE218611DC28E200029872 /* Specs */,
AEEE222911DC2B0600029872 /* libCedar-StaticLib.a */,
AEEE227611DC2CF900029872 /* iPhoneSpecs.app */,
@@ -474,6 +478,7 @@
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
+ AE8C867D135FAE76006C9305 /* ActualValue.h in Headers */,
AEEE1FF911DC27B800029872 /* CDRDefaultReporter.h in Headers */,
AEEE1FFA11DC27B800029872 /* CDRExample.h in Headers */,
AEEE1FFB11DC27B800029872 /* CDRExampleBase.h in Headers */,
@@ -494,6 +499,7 @@
buildActionMask = 2147483647;
files = (
AEC9DEEF12C2CC7E0039512D /* CDRColorizedReporter.h in Headers */,
+ AE8C8680135FB4F7006C9305 /* ActualValue.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -515,7 +521,7 @@
);
name = Cedar;
productName = Cedar;
- productReference = AEEE1FB611DC271300029872 /* Cedar */;
+ productReference = AEEE1FB611DC271300029872 /* Cedar.framework */;
productType = "com.apple.product-type.framework";
};
AEEE218511DC28E200029872 /* Specs */ = {
@@ -720,6 +726,7 @@
AEEE201111DC27B800029872 /* SpecHelper.m in Sources */,
AEFD17BB11DD1E9E00F4448A /* CDRSharedExampleGroupPool.m in Sources */,
AEC9DEEE12C2CC7E0039512D /* CDRColorizedReporter.m in Sources */,
+ AE0B8563135F94DC001EEA23 /* ActualValue.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -756,6 +763,7 @@
AEEE223D11DC2B6D00029872 /* CedarApplicationDelegate.m in Sources */,
AE9855AE1236E7080024094E /* CDRSharedExampleGroupPool.m in Sources */,
AEC9DEF412C2CC8F0039512D /* CDRColorizedReporter.m in Sources */,
+ AE0B8564135F94DC001EEA23 /* ActualValue.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -19,6 +19,9 @@ void it(NSString *, CDRSpecBlock);
void fail(NSString *);
#ifdef __cplusplus
}
+
+#import "ActualValue.h"
+
#endif
@interface CDRSpec : NSObject <CDRSpec> {
@@ -43,12 +46,3 @@ void fail(NSString *);
#define SPEC_END \
} \
@end
-
-#define DESCRIBE(name) \
-@interface name##Spec : CDRSpec \
-@end \
-@implementation name##Spec \
-- (void)declareBehaviors
-
-#define DESCRIBE_END \
-@end
@@ -4,56 +4,53 @@
#include <iostream>
#include <sstream>
-namespace Cedar {
-namespace Matchers {
+namespace Cedar { namespace Matchers {
-void fail(const NSString * failureMessage);
+ void fail(const NSString * failureMessage);
-template<typename T>
-class ActualValue {
-private:
- template<typename U>
- ActualValue(const ActualValue<U> &);
- template<typename U>
- ActualValue & operator=(const ActualValue<U> &);
+ template<typename T>
+ class ActualValue {
+ private:
+ template<typename U>
+ ActualValue(const ActualValue<U> &);
+ template<typename U>
+ ActualValue & operator=(const ActualValue<U> &);
-public:
- ActualValue(const T &);
+ public:
+ ActualValue(const T &);
- template<typename U>
- void toEqual(const U &) const;
+ template<typename U>
+ void toEqual(const U &) const;
- inline void foo(int i) const { std::cout << "int foo" << std::endl; }
- inline void foo(NSObject * i) const { std::cout << "NSObject foo" << std::endl; };
+ private:
+ const T value_;
+ };
- template<typename U>
- inline void bar(U i) const { std::cout << "template bar" << std::endl; }
-private:
- const T value_;
-};
-
-#pragma mark It's 2010 and linkers still can't handle templates in implementation files?
-
-template<typename T>
-const ActualValue<T> expect(const T & value) {
- return ActualValue<T>(value);
-}
+ template<typename T>
+ const ActualValue<T> expect(const T & value) {
+ return ActualValue<T>(value);
+ }
-template<typename T>
-ActualValue<T>::ActualValue(const T & value) : value_(value) {
-}
+ template<typename T>
+ ActualValue<T>::ActualValue(const T & value) : value_(value) {
+ }
#pragma mark toEqual
-template<typename T> template<typename U>
-void ActualValue<T>::toEqual(const U & expectedValue) const {
- if (expectedValue != value_) {
- std::stringstream message;
- message << "Expected <" << value_ << "> to equal <" << expectedValue << ">";
-
- [[CDRSpecFailure specFailureWithReason:[NSString stringWithCString:message.str().c_str() encoding:NSUTF8StringEncoding]] raise];
+ // Generic method must be defined here, not in the implementation file.
+ template<typename T> template<typename U>
+ void ActualValue<T>::toEqual(const U & expectedValue) const {
+ if (expectedValue != value_) {
+ std::stringstream message;
+ message << "Expected <" << value_ << "> to equal <" << expectedValue << ">";
+
+ [[CDRSpecFailure specFailureWithReason:[NSString stringWithCString:message.str().c_str() encoding:NSUTF8StringEncoding]] raise];
+ }
}
-}
-}
-}
+ // Specialized methods must be declared here, but defined in the implementation file.
+ // If not declared here, OS X build will fail to pick up the specialization. If defined
+ // here, iOS builds will fail with duplicate symbol link errors.
+ template<> template<>
+ void ActualValue<NSObject *>::toEqual(NSObject * const & expectedValue) const;
+}}
@@ -1,11 +1,20 @@
#import "ActualValue.h"
-namespace Cedar {
-namespace Matchers {
+namespace Cedar { namespace Matchers {
-void fail(const NSString *failureMessage) {
- [[CDRSpecFailure specFailureWithReason:[NSString stringWithFormat:@"Failure: %@", failureMessage]] raise];
-}
+ void fail(const NSString *failureMessage) {
+ [[CDRSpecFailure specFailureWithReason:[NSString stringWithFormat:@"Failure: %@", failureMessage]] raise];
+ }
-}
-}
+#pragma mark toEqual
+ template<> template<>
+ void ActualValue<NSObject *>::toEqual(NSObject * const & expectedValue) const {
+ if (![expectedValue isEqual:value_]) {
+ std::stringstream message;
+ message << "Expected NSObject <" << value_ << "> to equal NSObject <" << expectedValue << ">";
+
+ [[CDRSpecFailure specFailureWithReason:[NSString stringWithCString:message.str().c_str() encoding:NSUTF8StringEncoding]] raise];
+ }
+ }
+
+}}
View
@@ -9,6 +9,8 @@
#import <OCHamcrest/OCHamcrest.h>
#endif
+using namespace Cedar::Matchers;
+
SPEC_BEGIN(CppSpecSpec)
describe(@"CppSpec", ^{
@@ -17,11 +19,25 @@
__block int expectedValue;
beforeEach(^ {
-// expectedValue = 1;
+ expectedValue = 1;
+ });
+
+ it(@"should run", ^{
+ expect(1).toEqual(expectedValue);
+ });
+ });
+
+ describe(@"with NSObject-based types", ^{
+ __block NSObject *expectedValue;
+ int someInteger = 7;
+
+ beforeEach(^ {
+ expectedValue = [NSString stringWithFormat:@"Value: %d", someInteger];
});
it(@"should run", ^{
-// assertThatInt(1, equalToInt(expectedValue));
+ NSObject *actualValue = [NSString stringWithFormat:@"Value: %d", someInteger];
+ expect(actualValue).toEqual(expectedValue);
});
});
});
@@ -4,40 +4,41 @@
#import "OCHamcrest.h"
#import "CDRExampleStateMap.h"
-DESCRIBE(CDRExampleStateMap) {
- __block CDRExampleStateMap *map;
+SPEC_BEGIN(CDRExampleStateMapSpec)
- beforeEach(^{
- map = [CDRExampleStateMap stateMap];
- });
+__block CDRExampleStateMap *map;
+
+beforeEach(^{
+ map = [CDRExampleStateMap stateMap];
+});
- describe(@"descriptionForState", ^{
- describe(@"for an incomplete state", ^{
- it(@"should return RUNNING", ^{
- assertThat([map descriptionForState:CDRExampleStateIncomplete], equalTo(@"RUNNING"));
- });
+describe(@"descriptionForState", ^{
+ describe(@"for an incomplete state", ^{
+ it(@"should return RUNNING", ^{
+ assertThat([map descriptionForState:CDRExampleStateIncomplete], equalTo(@"RUNNING"));
});
- describe(@"for a passed state", ^{
- it(@"should return PASSED", ^{
- assertThat([map descriptionForState:CDRExampleStatePassed], equalTo(@"PASSED"));
- });
+ });
+ describe(@"for a passed state", ^{
+ it(@"should return PASSED", ^{
+ assertThat([map descriptionForState:CDRExampleStatePassed], equalTo(@"PASSED"));
});
- describe(@"for a pending state", ^{
- it(@"should return PENDING", ^{
- assertThat([map descriptionForState:CDRExampleStatePending], equalTo(@"PENDING"));
- });
+ });
+ describe(@"for a pending state", ^{
+ it(@"should return PENDING", ^{
+ assertThat([map descriptionForState:CDRExampleStatePending], equalTo(@"PENDING"));
});
- describe(@"for a failed state", ^{
- it(@"should return FAILED", ^{
- assertThat([map descriptionForState:CDRExampleStateFailed], equalTo(@"FAILED"));
- });
+ });
+ describe(@"for a failed state", ^{
+ it(@"should return FAILED", ^{
+ assertThat([map descriptionForState:CDRExampleStateFailed], equalTo(@"FAILED"));
});
- describe(@"for a error state", ^{
- it(@"should return ERROR", ^{
- assertThat([map descriptionForState:CDRExampleStateError], equalTo(@"ERROR"));
- });
+ });
+ describe(@"for a error state", ^{
+ it(@"should return ERROR", ^{
+ assertThat([map descriptionForState:CDRExampleStateError], equalTo(@"ERROR"));
});
});
-}
-DESCRIBE_END
+});
+
+SPEC_END

0 comments on commit 3e1bbaa

Please sign in to comment.