]> 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)
committerAmos Jeffries <yadij@users.noreply.github.com>
Thu, 23 May 2024 15:45:26 +0000 (03:45 +1200)
Do not hand-roll tests for exception-throwing code

src/tests/testCacheManager.cc

index a9f7ee188344bef4e4cbdbaed370638e4d37623d..a76f33663219ea47cef4eed14e4af734a22d8ad0 100644 (file)
@@ -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()