]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
testCacheManager: use cppunit exception tests (#1811)
authorFrancesco Chemolli <5175948+kinkie@users.noreply.github.com>
Wed, 22 May 2024 22:35:22 +0000 (22:35 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Wed, 22 May 2024 22:35:34 +0000 (22:35 +0000)
Do not hand-roll tests for exception-throwing code

src/tests/testCacheManager.cc

index fcbfffa1f37f4449f2c3f3c79e6bd5a6b050aa14..554ecb7f61fe1ca814c817ddb8a365f31b00f277 100644 (file)
@@ -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