@@ -81,21 +81,39 @@ TEST(std_test, variant) {
8181#endif
8282}
8383
84- TEST (std_test, exception) {
85- std::string str (" Test Exception" );
86- std::string escstr = fmt::format (" \" {}\" " , str);
87-
84+ template <typename Catch> void exception_test () {
8885 try {
89- throw std::runtime_error (str);
90- } catch (const std::exception& ex) {
91- EXPECT_EQ (fmt::format (" {}" , ex), str);
92- EXPECT_EQ (fmt::format (" {:?}" , ex), escstr);
86+ throw std::runtime_error (" Test Exception" );
87+ } catch (const Catch& ex) {
88+ EXPECT_EQ (" std::runtime_error: Test Exception" , fmt::format (" {}" , ex));
89+ EXPECT_EQ (" \" std::runtime_error: Test Exception\" " ,
90+ fmt::format (" {:?}" , ex));
9391 }
92+ }
93+
94+ namespace my_ns1 {
95+ namespace my_ns2 {
96+ struct my_exception : public std ::exception {
97+ private:
98+ std::string msg;
99+
100+ public:
101+ my_exception (const std::string& s) : msg(s) {}
102+ const char * what () const noexcept override ;
103+ };
104+ const char * my_exception::what () const noexcept { return msg.c_str (); }
105+ } // namespace my_ns2
106+ } // namespace my_ns1
107+
108+ TEST (std_test, exception) {
109+ exception_test<std::exception>();
110+ exception_test<std::runtime_error>();
94111
95112 try {
96- throw std::runtime_error (str);
97- } catch (const std::runtime_error& ex) {
98- EXPECT_EQ (fmt::format (" {}" , ex), str);
99- EXPECT_EQ (fmt::format (" {:?}" , ex), escstr);
113+ using namespace my_ns1 ::my_ns2;
114+ throw my_exception (" My Exception" );
115+ } catch (const std::exception& ex) {
116+ EXPECT_EQ (" my_ns1::my_ns2::my_exception: My Exception" ,
117+ fmt::format (" {}" , ex));
100118 }
101119}
0 commit comments