From 6601a925c7b9dae76505fe2244a12806535dbdfe Mon Sep 17 00:00:00 2001 From: Joaquim Casals <jcasals@iri.upc.edu> Date: Wed, 12 Jun 2019 13:06:50 +0200 Subject: [PATCH] Changed asserts for std::runtime_error in converter.h --- include/core/utils/converter.h | 5 ++--- test/gtest_converter.cpp | 6 +++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/include/core/utils/converter.h b/include/core/utils/converter.h index 49f003633..ffb955d45 100644 --- a/include/core/utils/converter.h +++ b/include/core/utils/converter.h @@ -97,7 +97,7 @@ namespace wolf{ template<typename T> struct converter{ static T convert(std::string val){ - assert(1 == 0 && "There is no general convert for arbitrary T !!!"); + throw std::runtime_error("There is no general convert for arbitrary T !!! String provided: "+ val); } }; template<typename A> @@ -160,8 +160,7 @@ struct converter<std::string>{ } template<typename T> static std::string convert(T val){ - assert(1 == 0 && "There is no general convert to string for arbitrary T !!!"); - return ""; + throw std::runtime_error("There is no general convert to string for arbitrary T !!! String provided: " + val); } static std::string convert(int val){ return std::to_string(val); diff --git a/test/gtest_converter.cpp b/test/gtest_converter.cpp index 6a263e55e..d8378df46 100644 --- a/test/gtest_converter.cpp +++ b/test/gtest_converter.cpp @@ -49,7 +49,11 @@ TEST(Converter, ParseToMap) map<string, vector<int>> m = {{"x",vector<int>{1,2}}, {"y",vector<int>{}}, {"z",vector<int>{3}}}; ASSERT_EQ(converter<string>::convert(m), "[{x:[1,2]},{y:[]},{z:[3]}]"); } - +TEST(Converter, noGeneralConvert) +{ + class DUMMY{}; + EXPECT_THROW(([=]{converter<DUMMY>::convert("Should fail");}()), std::runtime_error); +} int main(int argc, char **argv) { testing::InitGoogleTest(&argc, argv); -- GitLab