From: Francesco Chemolli <5175948+kinkie@users.noreply.github.com> Date: Wed, 22 May 2024 22:35:22 +0000 (+0000) Subject: testCacheManager: use cppunit exception tests (#1811) X-Git-Tag: SQUID_6_10~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0e0a59a7ccb9bdd476adc097d4c944f220646933;p=thirdparty%2Fsquid.git testCacheManager: use cppunit exception tests (#1811) Do not hand-roll tests for exception-throwing code --- diff --git a/src/tests/testCacheManager.cc b/src/tests/testCacheManager.cc index a9f7ee1883..a76f336632 100644 --- a/src/tests/testCacheManager.cc +++ b/src/tests/testCacheManager.cc @@ -33,26 +33,13 @@ public: void CacheManagerInternals::testValidUrl(const AnyP::Uri &url) { - try { - (void)ParseUrl(url); - } catch (...) { - std::cerr << "\nFAIL: " << url << - Debug::Extra << "error: " << CurrentException << "\n"; - CPPUNIT_FAIL("rejected a valid URL"); - } + CPPUNIT_ASSERT_NO_THROW(ParseUrl(url)); } void CacheManagerInternals::testInvalidUrl(const AnyP::Uri &url, const char *const problem) { - try { - (void)ParseUrl(url); - std::cerr << "\nFAIL: " << url << - Debug::Extra << "error: should be rejected due to '" << problem << "'\n"; - } catch (const TextException &) { - return; // success -- the parser signaled bad input - } - CPPUNIT_FAIL("failed to reject an invalid URL"); + CPPUNIT_ASSERT_THROW_MESSAGE(problem, ParseUrl(url), TextException); } void testCacheManager::setUp()