I'm seeing the same thing on MacOSX 10.9 with clang++3.4 and Linux with GCC 4.8.2. Exceptions are unhandled and the test program terminates immediately. A little more investigation shows that this is because the exceptions aren't of the correct type (possibly) and/or aren't being caught correctly. I've attempted to make a reduced testcase below. However, it's not perfect. The problematic test in my own code is:
// Invalid file
EXPECT_THROW(r2.isUsedFile("unused-nonexistent-file"), boost::filesystem::filesystem_error);
// Valid but unused file
EXPECT_THROW(r2.isUsedFile(PROJECT_SOURCE_DIR "/components/specification/samples/2012-06/18x24y5z5t2c8b-text.ome"), std::logic_error);
The lines doing the throwing in each case are, respectively:
path thisfile = boost::filesystem::canonical(path(file));
throw std::logic_error(msg);
The boost::filesystem::canonical function is documented to throw a boost::filesystem::filesystem_error when invoked in this manner. The logic_error is a plain std::logic_error. Yet ASSERT_THROW and EXPECT_THROW fail to catch *both*. However, gtest might not necessarily be at fault here. Adding in a few asserts in a try/catch block shows that the boost::filesystem::filesystem_error isn't caught, but a std::runtime_error *is*. However... if I compile a simpler example, the program terminates with the message:
#include <iostream>
#include <stdexcept>
#include <boost/filesystem/operations.hpp>
namespace
{
void test_throw()
{ throw std::logic_error("Bad logic"); }
}
int main()
{
try
{
boost::filesystem::canonical(boost::filesystem::path("/invalid/path"));
}
catch (const boost::filesystem::filesystem_error& e)
{ std::cerr << "Caught FSE" << std::endl; }
catch (const std::runtime_error& e)
{ std::cerr << "Caught RTE" << std::endl; }
catch (...)
{ std::cerr << "Caught general exception" << std::endl; }
}
==> it hits the runtime_error catch block
Caught RTE
or
terminating with uncaught exception of type boost::filesystem::filesystem_error: boost::filesystem::canonical: No such file or directory: "/invalid/path"
if the try/catch is removed. There's clearly something fundamentally wrong here. It *is* throwing the correct exception. But it's not being caught in the correct block and is falling through to be caught as a more generic type.
Minimal gtest test case below. This is basically the same tests run via google test. The observed behaviour is the same. In the minimal test is appear to catch the logic_error correctly, but not the boost::filesystem::filesystem_error. Link with "-lboost_system -lboost_filesystem". You might need to comment out the various bits to see all the different tests in action since it'll abort on the earlier tests.