1

I have the following stupidly simple test case (defined in a .mm file with correspong .h file). It uses boost to try to read in a ptree from a stringstream to simulate the text that would be in a file.

-(void)setUp {
  printf("setup\n");

  ::std::stringstream ss;
  ss << "bad format text";

  _configuration = new ptree();
  ::boost::property_tree::read_json(ss, *_configuration);
}

The tearDown function does nothing, and there is one test case, which also does nothing. If I comment out the read_json line, everything works fine. But if I run it as is, I get:

Test Case '-[TestPlanner testPlanner]' started.
libc++abi.dylib: terminate called throwing an exception
/Applications/Xcode.app/Contents/Developer/Tools/RunPlatformUnitTests.include: line 415:  3320 Abort trap: 6           "${THIN_TEST_RIG}" "${OTHER_TEST_FLAGS}" "${TEST_BUNDLE_PATH}"
/Applications/Xcode.app/Contents/Developer/Tools/RunPlatformUnitTests.include:451: error: Test rig '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.0.sdk/Developer/usr/bin/otest' exited abnormally with code 134 (it may have crashed).

The really crazy thing is that if I set a breakpoint in the SetUp function, it doesn't even run! And this is the only test enabled, so without even running a single line of a single test, something crashes. I know the test is set up correctly, because if I comment out the read_json line and set a breakpoint, it does get reached, and I can include some asserts in the test case and they work as expected.

It's not just a boost problem either. I originally encountered this when calling a different library from my own project, but to simplify everything I went down to just this boost call. This exact same call is happening in other parts of the code, so I'm pretty sure I have boost linked in correctly. I was super verbose with namespaces, so I don't think I'm linking the wrong version of a function or something.

I'm running XCode 4.5 (but have the same problem on 4.4.1) and trying to write Unit tests using OCUnit. The project I am working on already has a few unit tests written in this framework and everything with those tests seems to work fine.

I'm new to Objective C and XCode but the guy who set this project up definitely isn't and he couldn't see any problem with what I was doing and we were both totally stumped.

Thanks for reading! Let me know if you need any more info.

stokastic
  • 986
  • 2
  • 7
  • 19

1 Answers1

0

It turns out OCUnit barfs if it gets a C++ exception, and for some reason, XCode (or maybe lldb) doesn't properly trigger the breakpoint. The SetUp code is running, the debugger just isn't working. Adding a try/catch block or changing the code to:

-(void)setUp {
  printf("setup\n");

  ::std::stringstream ss;
  ss << "{}";

  _configuration = new ptree();
  ::boost::property_tree::read_json(ss, *_configuration);
}

Doesn't cause an exception and makes everything work.

So the workaround if you are seeing this problem is to make sure you try/catch everything in your test cases. Hopefully someone will come up with a better answer because this seems like a pretty big bug in OCunit.

stokastic
  • 986
  • 2
  • 7
  • 19