Skip to content

Commit

Permalink
Added definitions and tests for throw/no throw
Browse files Browse the repository at this point in the history
  • Loading branch information
ryancalhoun committed Dec 11, 2015
1 parent 7a2aff4 commit 62c287c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion include/cppunit/TestAssert.h
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,6 @@ void assertGreaterEqual(int expected, unsigned long long actual, SourceLine sour
# define CPPUNIT_ASSERT_ASSERTION_PASS_MESSAGE(message, assertion) \
CPPUNIT_ASSERT_NO_THROW_MESSAGE(message, assertion)

#define CPPUNIT_VA_SELECT(_2, _1, NAME, ...) NAME

/*
* Variadic macros for message/no-message signatures
Expand Down Expand Up @@ -455,6 +454,8 @@ void assertGreaterEqual(int expected, unsigned long long actual, SourceLine sour

#define assert_doubles_equal(expected, actual, tolerance, ...) CPPUNIT_ASSERT_BODY(__VA_ARGS__) (CPPUNIT_ASSERT_DOUBLES_EQUAL, __VA_ARGS__, expected, actual, tolerance)

#define assert_throw(expected, expression, ...) CPPUNIT_ASSERT_BODY(__VA_ARGS__) (CPPUNIT_ASSERT_THROW, __VA_ARGS__, expression, expected)
#define assert_no_throw(expression, ...) CPPUNIT_ASSERT_BODY(__VA_ARGS__) (CPPUNIT_ASSERT_NO_THROW, __VA_ARGS__, expression)

CPPUNIT_NS_END

Expand Down
10 changes: 10 additions & 0 deletions test/cppunit_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ class FooTest : public CppUnit::TestFixture
assert_doubles_equal(42.0, 42.0, 0.001);
}

void testThrow()
{
assert_no_throw(42);
assert_throw(int, throw 42);
}

void testMessage()
{
assert_true(true, "message");
Expand All @@ -72,6 +78,9 @@ class FooTest : public CppUnit::TestFixture
assert_greater_equal(4, 8, "message");

assert_doubles_equal(4.2, 4.2, 0.1, "message");

assert_no_throw(42, "message");
assert_throw(int, throw 42, "message");
}

static CppUnit::Test* suite()
Expand All @@ -83,6 +92,7 @@ class FooTest : public CppUnit::TestFixture
CPPUNIT_ADD_TEST(suite, testStrings);
CPPUNIT_ADD_TEST(suite, testIntegers);
CPPUNIT_ADD_TEST(suite, testDoubles);
CPPUNIT_ADD_TEST(suite, testThrow);

CPPUNIT_ADD_TEST(suite, testMessage);

Expand Down
2 changes: 1 addition & 1 deletion test/cppunit_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def testCppUnit
Dir.chdir(File.join(File.dirname(__FILE__), '..', 'build', 'test', ENV['CONFIGURATION'].to_s)) {
output = `./cppunit_test`
assert_equal 1, $?.exitstatus
assert_match /Run:\s+6\s+Failures:\s+1\s+Errors:\s+0/, output
assert_match /Run:\s+7\s+Failures:\s+1\s+Errors:\s+0/, output
}
end

Expand Down

0 comments on commit 62c287c

Please sign in to comment.