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_7_0_1~118 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=eb743f8b6870e47bb77ac8bd69da9ed2e9a02ec3;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 fcbfffa1f3..554ecb7f61 100644 --- a/src/tests/testCacheManager.cc +++ b/src/tests/testCacheManager.cc @@ -50,26 +50,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); } /// customizes our test setup