Skip to content

Commit

Permalink
DPL: add test for exception throwing in Variant
Browse files Browse the repository at this point in the history
  • Loading branch information
ktf committed Nov 25, 2024
1 parent 4f7d71b commit acbee81
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Framework/Core/include/Framework/Variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ class Variant
T get() const
{
if (mType != variant_trait_v<T>) {
throw runtime_error("Mismatch between types");
throw runtime_error_f("Variant::get: Mismatch between types %d %d.", mType, variant_trait_v<T>);
}
return variant_helper<T>::get(&mStore);
}
Expand Down
12 changes: 12 additions & 0 deletions Framework/Core/test/test_Variants.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -338,3 +338,15 @@ TEST_CASE("VariantJSONConversionsTest")
REQUIRE(vstrings[i] == vvstra.get<std::string*>()[i]);
}
}

TEST_CASE("VariantThrowing")
{
Variant a("true");
REQUIRE_THROWS_AS(a.get<int>(), o2::framework::RuntimeErrorRef);
try {
a.get<int>();
} catch (RuntimeErrorRef& ref) {
RuntimeError& error = error_from_ref(ref);
REQUIRE(error.what == std::string("Variant::get: Mismatch between types 4 0."));
}
}

0 comments on commit acbee81

Please sign in to comment.