Boost C++ Libraries: Ticket #12540: Provide customisation point for printing types in tests https://svn.boost.org/trac10/ticket/12540 <p> AFAIU (from doc "Logging user defined types"), the current design gives users two options for handling output for their types in tests: </p> <ul><li>Provide <code>operator&lt;&lt;</code> </li><li>Prevent printing with <code>BOOST_TEST_DONT_PRINT_LOG_VALUE()</code> </li></ul><p> ...and all types must be printed. </p> <p> I suggest that this is to rigid. For some types, users may not want to provide a global <code>operator&lt;&lt;</code>, or they may have already provided an <code>operator&lt;&lt;</code> or they may not own the type. </p> <p> For these reasons, I think it would be better if Boost Test provided an explicit customization point that defaulted to calling <code>operator&lt;&lt;</code> but that could be overridden by the user to explictly control the Test printing without affecting <code>operator&lt;&lt;</code>. </p> <p> In fact, I think <code>boost::test_tools::tt_detail::print_log_value</code> is already close to serving this purpose and perhaps it needs little more than being made part of the public interface and documented. </p> <p> Thanks for all your work. </p> <p> PS "D4381: Suggested Design for Customization Points" may be relevant here. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/12540 Trac 1.4.3 Raffi Enficiaud Sat, 04 Feb 2017 21:45:59 GMT owner, status changed https://svn.boost.org/trac10/ticket/12540#comment:1 https://svn.boost.org/trac10/ticket/12540#comment:1 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Gennadiy Rozental</span> to <span class="trac-author">Raffi Enficiaud</span> </li> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> Ticket Raffi Enficiaud Sun, 05 Feb 2017 12:03:02 GMT milestone changed https://svn.boost.org/trac10/ticket/12540#comment:2 https://svn.boost.org/trac10/ticket/12540#comment:2 <ul> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.64.0</span> </li> </ul> Ticket Raffi Enficiaud Sun, 05 Feb 2017 12:11:34 GMT <link>https://svn.boost.org/trac10/ticket/12540#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12540#comment:3</guid> <description> <p> Hi there, </p> <p> I am not very familiar with the intrinsics of ADL and qualified/unqualified calls. What seems to be working right now in the branch <code>topic/12540-printing-types-customisation-point</code> is something like this: </p> <pre class="wiki">namespace printing_test { struct user_defined_type { int value; user_defined_type(int value_) : value(value_) {} bool operator==(int right) const { return right == value; } }; std::ostream&amp; boost_test_print_type(std::ostream&amp; ostr, user_defined_type const&amp; right) { ostr &lt;&lt; "** value of my type is " &lt;&lt; right.value &lt;&lt; " **"; return ostr; } } BOOST_AUTO_TEST_CASE(test1) { printing_test::user_defined_type t(10); BOOST_CHECK_EQUAL(t, 10); BOOST_TEST(t == 11); } </pre><p> However, if I move the definition of <code>boost_test_print_type</code> to another namespace, it does not find the definition anymore. This seems to be normal, but I do not know if this is what we want from the users' perspective. </p> <p> What do you think? </p> </description> <category>Ticket</category> </item> <item> <author>Tony Lewis <TonyELewis@…></author> <pubDate>Sat, 11 Feb 2017 19:23:32 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12540#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12540#comment:4</guid> <description> <p> Thanks very much for your work on this. </p> <p> The changes on <code>topic/12540-printing-types-customisation-point</code> look like the sort of thing I was thinking of. </p> <p> Yes, I think the idea of D4381 is that users customise by putting their function in the namespace of the type so that it gets picked up by ADL. What are your hesitations about this? It may be sub-optimal when users want to specify a <code>boost_test_print_type()</code> for a types in namespaces that they don't own and hence want to avoid polluting (eg <code>std::</code> - I think I read that polluting <code>std::</code> technically induces undefined behaviour). Still, I'd say it's still much better than expecting them to put an <code>operator&lt;&lt;</code> in there. Maybe it's possible to document that users can alternatively specialise the default <code>boost_test_print_type</code> template (and rename/move the namespace to something specific)? I don't know how that would play with the ideas of D4381. </p> <p> I think I'd vote for: for now, document and release the current changes as a supported part of the interface. If the feedback is that users like the idea but want a way to avoid having to pollute namespaces that they don't own, consider extending the customisation interface. What do you think? </p> <p> I think these changes are a really helpful improvement and are well worth highlighting to users. </p> <p> Thanks again. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Raffi Enficiaud</dc:creator> <pubDate>Wed, 01 Mar 2017 11:35:31 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12540#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12540#comment:5</guid> <description> <p> Sorry I missed your reply, then it is good :) I will update the documentation. Should be fine for 1.64. </p> </description> <category>Ticket</category> </item> <item> <author>Tony Lewis <TonyELewis@…></author> <pubDate>Tue, 07 Mar 2017 12:34:19 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12540#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12540#comment:6</guid> <description> <p> Fantastic. Thanks very much for your work on this. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Raffi Enficiaud</dc:creator> <pubDate>Sun, 19 Mar 2017 22:00:39 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12540#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12540#comment:7</guid> <description> <p> Merged to master, rev <code></code><code>af78890325948bed598361966fa7f5fc9560c41d</code><code></code> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Raffi Enficiaud</dc:creator> <pubDate>Sun, 19 Mar 2017 22:00:54 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/12540#comment:8 https://svn.boost.org/trac10/ticket/12540#comment:8 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> Ticket Tony Lewis <TonyELewis@…> Tue, 21 Mar 2017 20:51:08 GMT <link>https://svn.boost.org/trac10/ticket/12540#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12540#comment:9</guid> <description> <p> Great. Thanks very much. </p> </description> <category>Ticket</category> </item> </channel> </rss>