Skip to content

Commit 2f03ece

Browse files
committed
Removing excessive debug printing
1 parent 8cb5b34 commit 2f03ece

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

test/so_dll_test.cpp

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,21 @@
3333

3434
namespace leaf = boost::leaf;
3535

36-
int test_result(leaf::result<void> (*f)())
36+
int test_result(leaf::result<void> (*f)(), bool print)
3737
{
3838
int r = leaf::try_handle_all(
3939
[f]() -> leaf::result<int>
4040
{
4141
BOOST_LEAF_CHECK(f());
4242
return 0;
4343
},
44-
[]( my_info<1> x1, my_info<2> x2, leaf::diagnostic_details const & info, leaf::diagnostic_details const & vinfo )
44+
[&]( my_info<1> x1, my_info<2> x2, leaf::diagnostic_details const & info, leaf::diagnostic_details const & vinfo )
4545
{
4646
if( x1.value != 1 )
4747
return 1;
4848
if( x2.value != 2 )
4949
return 2;
50-
if( BOOST_LEAF_CFG_DIAGNOSTICS )
50+
if( BOOST_LEAF_CFG_DIAGNOSTICS && print )
5151
{
5252
#if BOOST_LEAF_CFG_STD_STRING
5353
std::ostringstream ss; ss << vinfo;
@@ -60,34 +60,35 @@ int test_result(leaf::result<void> (*f)())
6060
}
6161
return 0;
6262
},
63-
[](leaf::diagnostic_details const & vinfo)
63+
[&](leaf::diagnostic_details const & vinfo)
6464
{
6565
#if BOOST_LEAF_CFG_STD_STRING
66-
std::cout << "Test is failing (catch-all), diagnostics:\n" << vinfo << std::endl;
66+
if( print )
67+
std::cout << "Test is failing (catch-all), diagnostics:\n" << vinfo << std::endl;
6768
#endif
6869
return 4;
6970
} );
7071
return r;
7172
}
7273

7374
#ifndef BOOST_LEAF_NO_EXCEPTIONS
74-
int test_exception(void (*f)())
75+
int test_exception(void (*f)(), bool print)
7576
{
7677
int r = leaf::try_catch(
7778
[f]
7879
{
7980
f();
8081
return 0;
8182
},
82-
[]( my_info<1> x1, my_info<2> x2, leaf::diagnostic_details const & info, leaf::diagnostic_details const & vinfo )
83+
[&]( my_info<1> x1, my_info<2> x2, leaf::diagnostic_details const & info, leaf::diagnostic_details const & vinfo )
8384
{
8485
if( x1.value != 1 )
8586
return 1;
8687
if( x2.value != 2 )
8788
return 2;
88-
if( BOOST_LEAF_CFG_DIAGNOSTICS )
89+
if( BOOST_LEAF_CFG_DIAGNOSTICS && print )
8990
{
90-
#if 0 && BOOST_LEAF_CFG_STD_STRING
91+
#if BOOST_LEAF_CFG_STD_STRING
9192
std::ostringstream ss; ss << vinfo;
9293
std::string s = ss.str();
9394
std::cout << s << std::endl;
@@ -98,10 +99,11 @@ int test_exception(void (*f)())
9899
}
99100
return 0;
100101
},
101-
[](leaf::diagnostic_details const & vinfo)
102+
[&](leaf::diagnostic_details const & vinfo)
102103
{
103-
#if 0 && BOOST_LEAF_CFG_STD_STRING
104-
std::cout << "Test is failing\n" << vinfo;
104+
#if BOOST_LEAF_CFG_STD_STRING
105+
if( print )
106+
std::cout << "Test is failing\n" << vinfo;
105107
#endif
106108
return 4;
107109
} );
@@ -128,13 +130,13 @@ int test_catch(void (*f)())
128130

129131
void test_single_thread()
130132
{
131-
BOOST_TEST_EQ(test_result(hidden_result2), 0);
132-
BOOST_TEST_EQ(test_result(hidden_result1), 0);
133+
BOOST_TEST_EQ(test_result(hidden_result2, true), 0);
134+
BOOST_TEST_EQ(test_result(hidden_result1, true), 0);
133135

134136
#ifndef BOOST_LEAF_NO_EXCEPTIONS
135-
BOOST_TEST_EQ(test_exception(hidden_throw1), 0);
137+
BOOST_TEST_EQ(test_exception(hidden_throw1, true), 0);
136138
BOOST_TEST_EQ(test_catch(hidden_throw1), 0);
137-
BOOST_TEST_EQ(test_exception(hidden_throw2), 0);
139+
BOOST_TEST_EQ(test_exception(hidden_throw2, true), 0);
138140
BOOST_TEST_EQ(test_catch(hidden_throw2), 0);
139141
#endif
140142
}
@@ -151,8 +153,8 @@ void test_multithreaded()
151153
std::unique_lock<std::mutex> lock(mtx);
152154
cv.wait(lock, [&]{ return ready; });
153155
lock.unlock();
154-
int result1 = test_result(hidden_result1);
155-
int result2 = test_result(hidden_result2);
156+
int result1 = test_result(hidden_result1, false);
157+
int result2 = test_result(hidden_result2, false);
156158
return result1 + result2;
157159
};
158160
std::vector<std::future<int>> futures;
@@ -185,9 +187,9 @@ void test_multithreaded()
185187
std::unique_lock<std::mutex> lock(mtx);
186188
cv.wait(lock, [&]{ return ready; });
187189
lock.unlock();
188-
int result1 = test_exception(hidden_throw1);
190+
int result1 = test_exception(hidden_throw1, false);
189191
int result2 = test_catch(hidden_throw1);
190-
int result3 = test_exception(hidden_throw2);
192+
int result3 = test_exception(hidden_throw2, false);
191193
int result4 = test_catch(hidden_throw2);
192194
return result1 + result2 + result3 + result4;
193195
};

0 commit comments

Comments
 (0)