Use CHECK_THAT() in PostgreSQL unit tests

This is simpler than manually using strncmp() or string::find().

Omit one negative test, it's not clear what was it actually testing for.
This commit is contained in:
Vadim Zeitlin
2025-04-22 17:02:01 +02:00
parent 9e308de736
commit cbb28ed046

View File

@@ -431,9 +431,7 @@ TEST_CASE("PostgreSQL literals", "[postgresql][into]")
}
catch (soci_error const & e)
{
char const * expectedPrefix = "Cannot convert data";
CAPTURE(e.what());
CHECK(strncmp(e.what(), expectedPrefix, strlen(expectedPrefix)) == 0);
CHECK_THAT( e.what(), Catch::StartsWith("Cannot convert data") );
}
}
@@ -696,12 +694,7 @@ TEST_CASE("PostgreSQL statement prepare failure", "[postgresql][prepare]")
}
catch(soci_error const& e)
{
std::string const msg(e.what());
CAPTURE(msg);
// poor-man heuristics
CHECK(msg.find("prepared statement") == std::string::npos);
CHECK(msg.find("operator does not exist") != std::string::npos);
CHECK_THAT( e.what(), Catch::Contains("operator does not exist") );
}
}