diff --git a/include/cppunit/TestAssert.h b/include/cppunit/TestAssert.h index 1ab3643..ab787b5 100644 --- a/include/cppunit/TestAssert.h +++ b/include/cppunit/TestAssert.h @@ -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 @@ -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 diff --git a/test/cppunit_test.cpp b/test/cppunit_test.cpp index 16765d0..46d9385 100644 --- a/test/cppunit_test.cpp +++ b/test/cppunit_test.cpp @@ -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"); @@ -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() @@ -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); diff --git a/test/cppunit_test.rb b/test/cppunit_test.rb index dd2ae82..5f8f306 100644 --- a/test/cppunit_test.rb +++ b/test/cppunit_test.rb @@ -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