0

I've inherited a project which contains a lot of Objective-C++ code, and no unit tests. I'm attempting to set up testing, using Xcode 6.1.1 and XCTest. I've started by creating a new Cocoa Touch unit testing bundle with default settings.

When I create a standard XCTest subclass, everything works fine. When I then include an Obj-C++ file, the build stage breaks with various C++-related errors. That's understandable, because the test subclass needs to be compiled as an Obj-C++ class.

When I switch the XCTest subclass from myTests.m to myTests.mm, the build stage breaks again, but this time with

Unexpected '@' in program

There are two additional errors being shown :

Expanded from macro 'XCTAssert'

Expanded from macro '_XCTPrimitiveAssertTrue'

The errors are being caused by the NSString parameter of the XCAssert call - replacing this with a standard C string in the test case doesn't fix the problem.

If I switch the C++ standard library for the test target from libstdc++ to libc++ the @ errors disappear, but then the compilation of the Obj-C++ code in the rest of the project fails.

I don't know enough about Obj-C++ to figure this one out - are there some additional compiler flags I need to set in order to use XCTest successfully?

1
  • What version of Xcode are you using? I just created a new project in Xcode 6.1.1 and changed an XCTest subclass to use .mm as the file extension. It’s compiling as Objective-C++ just fine. Dec 19, 2014 at 15:28

1 Answer 1

0

Are you quite sure the error is being caused by the NSString you're passing? You can test that assumption by passing nil, or by putting the string into a variable and passing the variable. The reason I ask is that _XCTPrimitiveAssertTrue contains several @-prefixed keywords, and it seems conceivable that one of those could be tripping things up (though I don't know why).

Also it might be enlightening to see the verbatim compiler invocation and output (or not. I'm not making any promises here).

1
  • Thanks - I've tried various combinations of passing nil and strings into the XCTAssert call, and they're all failing - the detail in the log is: Unexpected @ in program Expanded from macro XCTAssert Expanded from macro _XCTPrimitiveAssertTrue
    – TimD
    Dec 19, 2014 at 11:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.