From b03bec327abd523111812263cd8077fd5c3daa65 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Wed, 8 Jul 2026 15:16:22 +0200 Subject: [PATCH] Use CHECK_THROWS_AS_WITH for std::optional test assertions Update the regression tests to use CHECK_THROWS_AS_WITH instead of CHECK_THROWS_AS to verify both the exception type and the error message. Signed-off-by: Niels Lohmann --- tests/src/unit-conversions.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/src/unit-conversions.cpp b/tests/src/unit-conversions.cpp index 5a7353eae..298dcdc55 100644 --- a/tests/src/unit-conversions.cpp +++ b/tests/src/unit-conversions.cpp @@ -1779,8 +1779,10 @@ TEST_CASE("std::optional") // operator); there is no SFINAE path that distinguishes "call from inside // std::optional's constructor" from "direct call". Use get>() // or get_to() instead for correct null handling. See #4864 and #5246. - CHECK_THROWS_AS(std::optional(j_null), json::type_error); - CHECK_THROWS_AS(std::optional(j_null), json::type_error); + CHECK_THROWS_AS_WITH(std::optional(j_null), json::type_error, + "type must be string, but is null"); + CHECK_THROWS_AS_WITH(std::optional(j_null), json::type_error, + "type must be number, but is null"); } SECTION("string")