// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
// Tests Google Test's throw-on-failure mode with exceptions enabled.
-#include "gtest/gtest.h"
-
-#include <stdlib.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
+
#include <stdexcept>
+#include "gtest/gtest.h"
+
// Prints the given failure message and exits the program with
// non-zero. We use this instead of a Google Test assertion to
// indicate a failure, as the latter is been tested and cannot be
// Tests that an assertion failure throws a subclass of
// std::runtime_error.
void TestFailureThrowsRuntimeError() {
- testing::GTEST_FLAG(throw_on_failure) = true;
+ GTEST_FLAG_SET(throw_on_failure, true);
// A successful assertion shouldn't throw.
try {
EXPECT_EQ(3, 3);
- } catch(...) {
+ } catch (...) {
Fail("A successful assertion wrongfully threw.");
}
// A failed assertion should throw a subclass of std::runtime_error.
try {
EXPECT_EQ(2, 3) << "Expected failure";
- } catch(const std::runtime_error& e) {
+ } catch (const std::runtime_error& e) {
if (strstr(e.what(), "Expected failure") != nullptr) return;
printf("%s",
"but the message is incorrect. Instead of containing \"Expected "
"failure\", it is:\n");
Fail(e.what());
- } catch(...) {
+ } catch (...) {
Fail("A failed assertion threw the wrong type of exception.");
}
Fail("A failed assertion should've thrown but didn't.");