Skip to content

Instantly share code, notes, and snippets.

@jeffremer
Created January 27, 2012 23:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffremer/1691576 to your computer and use it in GitHub Desktop.
Save jeffremer/1691576 to your computer and use it in GitHub Desktop.
Cedar macro object literal issue

I'm having trouble getting Cedar matchers to accept object literals like @"strings" or [NSNumber numberWithInt:2]. If I assign them to a variable then pass in the pointer it works fine, but if I pass in a literal to the macro it fails while building with errors like this:

	Semantic Issue
	error: no matching function for call to 'equal' [3]

For example, I've set up a blank Example project and added Cedar, then created a simple spec showing what seems to work and what doesn't:

#import <Cedar-iOS/SpecHelper.h>

using namespace Cedar::Matchers;

SPEC_BEGIN(ExampleSpec)
describe(@"Example", ^{
    it(@"should compare scalars", ^{
        expect(1+1).to(equal(2));
    });
    
    it(@"should compare objects", ^{
        // Works fine
        NSString* aString = @"something";
        expect(aString).to(equal(aString));

        // Works fine
        NSString* bString = @"something";
        expect(aString).to(equal(bString));

        // Semantic Issue
        // error: no matching function for call to 'equal' [3]
        expect(aString).to(equal(@"something"));        
        
        // Semantic Issue
        // error: no matching function for call to 'equal' [3]
        NSNumber *two = [NSNumber numberWithInt:(1+1)];
        expect([NSNumber numberWithInt:(1+1)]).to(equal([NSNumber numberWithInt:(2)]));        
    });
});
SPEC_END

I can run the iPhoneSpecs target in the Cedar project itself without an issue and it seems to pass in object literals to matcher macros just fine.

I have a feeling that I'm missing something crucial in the target - though I've followed the README and blog posts carefully. I've also compared it to the iPhoneSpecs target in the cedar project and it looks very similar. Though, I did notice in the cedar/iPhoneSpecs target the Other Linker Flags were set to:

	-lstdc++ -all_load -ObjC -framework Foundation -framework UIKit

While the README seems to indicate that only -lstdc++ -all_load is necessary. I added the missing ones but that doesn't seem to help.

Here are the detailed instructions with how I set up the example project and where things seem to go wrong.

  1. Create a new ARC iPhone project named Example with Xcode 4.2 including unit tests

  2. Clone pivotal/cedar into a peer directory

     $ git clone https://github.com/pivotal/cedar.git
    
  3. Initialize the cedar submodules

     $ cd cedar
     $ git submodule update --init
     
     Submodule 'Externals/OCMock' (git://github.com/pivotal/OCMock.git) registered for path 'Externals/OCMock'
     Submodule 'Spec/UIAutomation/jasmine-iphone' (git://github.com/pivotal/jasmine-iphone.git) registered for path 'Spec/UIAutomation/jasmine-iphone'
     Cloning into Externals/OCMock...
     remote: Counting objects: 674, done.
     remote: Compressing objects: 100% (161/161), done.
     remote: Total 674 (delta 456), reused 662 (delta 448)
     Receiving objects: 100% (674/674), 314.89 KiB | 429 KiB/s, done.
     Resolving deltas: 100% (456/456), done.
     Submodule path 'Externals/OCMock': checked out '0abfb4a37c09629cf435d372b64f98a740fd48ed'
     Cloning into Spec/UIAutomation/jasmine-iphone...
     remote: Counting objects: 15, done.
     remote: Compressing objects: 100% (11/11), done.
     remote: Total 15 (delta 4), reused 15 (delta 4)
     Receiving objects: 100% (15/15), done.
     Resolving deltas: 100% (4/4), done.
     Submodule path 'Spec/UIAutomation/jasmine-iphone': checked out '3cee16e01db1f667c11d9716f51b8e3e2fbabc75'
    
  4. Build the Cedar-iOS framework

    1. Open Cedar.xcodeproj in Xcode
    2. Select the "Cedar-iOS > My Mac 64-bit" scheme
    3. Click Run and see "Build Succeeded"

    Cedar-iOS

  5. Create a Cocoa Touch Application target for the tests

    1. Open the Example project
    2. Select the Example project in the project navigator
    3. Click Add Target from the bottom of the summary panel
    4. Choose iOS>Application>Empty Application
    5. Name it UISpecs
    6. Deselect use Core Data
    7. Select Use Automatic Reference Counting
    8. Deselect Include Unit Tests
    9. Click Finish
  6. Add the Cedar-iOS Framework to the Example project

    1. In Finder, under ~/cedar/build/Debug-iphoneuniversal select Cedar-iOS.framework

    Cedar-iOS.framework

    1. Drag that to the Frameworks group of the Example project in Xcode
    2. Select Copy items into destination group's folder (if needed)
    3. Add to targets UISpecs

    Add to targets

    1. Click Finish, the result is that Cedar-iOS.framework is linked with the UISpecs target

    Added

    1. Add the -ObjC and -all_load Other Linker Flags to UISpecs

    Other Linker Flags

    1. Update main.m under UISpecs to run the CedarAppDelegate

    main.m

    1. Build and Run UISpecs - at this point it opens the Simulator and runs fine (with no examples obviously)

    UISpecs

    1. Copying and updating the cedar/Rakefile over to the Example project then running rake uispecs works fine too.
  7. Write some examples

    1. Add a new blank ExampleSpec.mm to the UISpecs target
    2. Add some examples

    Examples

    1. Pointers inside the Cedar matcher macro calls work fine, literals and object instantiations don't. They give an error like:

       Semantic Issue
       error: no matching function for call to 'equal' [3]
      
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment