← Back to Pull requests

Added lwt_context to lightweight test #195

Open
anarthal opened this pull request with 417 lines diff across 5 files
View on GitHub
anarthal anarthal commented on May 25, 2025 10:59 UTC
Author

lwt_context makes the framework print the passed values on test failure

Diff: 417 lines (+345 / -72) across 5 files Reviewer: Lastique Review duration: 764781m
All Vouch review confidence checks passed
Residual risk 0.06 = Change Risk (0.52) × (1 − Review Confidence (0.89)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 417 lines diff across 5 files
0.52
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.90 · 5 substantive comment(s)
0.90
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
88%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.361
Real PR Conversation Timeline
10 items
anarthal anarthal commented on May 25, 2025 11:00 UTC
Author

This still lacks tests and docs. Before I go ahead and write them, can you please confirm that this is (more or less) what you expected? Feedback is welcome.

Lastique Lastique commented on code on May 25, 2025 12:16 UTC
Code Review
include/boost/core/lightweight_test.hpp:1
@@ -527,6 +596,48 @@ inline void lwt_init()
     boost::detail::test_results();
 }
 
+class lwt_context
+{
+    boost::detail::lwt_context_frame frame_;
+    
+    // Disallow copy and movement
+    lwt_context(const lwt_context&) {};
+    lwt_context& operator=(const lwt_context&) { return *this; }
+
+public:
+    template <class T>
+    explicit lwt_context(const T* value)
+    {
+        frame_.values[0].set_value(value);
+        frame_.values[1].set_null();
+        frame_.values[2].set_null();
+        boost::detail::test_results().push_context(frame_);
+    }
+
+    template <class T0, class T1>
+    lwt_context(const T0* value0, const T1* value1)
+    {
+        frame_.values[0].set_value(value0);
+        frame_.values[1].set_value(value1);
+        frame_.values[2].set_null();
+        boost::detail::test_results().push_context(frame_);
+    }
+
+    template <class T0, class T1, class T2>
+    lwt_context(const T0* value0, const T1* value1, const T2* value2)
+    {
+        frame_.values[0].set_value(value0);
+        frame_.values[0].set_value(value1);
+        frame_.values[0].set_value(value2);

[0], [1], [2]?

Lastique Lastique commented on code on May 25, 2025 12:19 UTC
Code Review
include/boost/core/lightweight_test.hpp:1
@@ -45,11 +45,92 @@ namespace boost
 namespace detail
 {
 
+// specialize test output for char pointers to avoid printing as cstring
+template <class T> inline const T& test_output_impl(const T& v) { return v; }
+inline const void* test_output_impl(const char* v) { return v; }
+inline const void* test_output_impl(const unsigned char* v) { return v; }
+inline const void* test_output_impl(const signed char* v) { return v; }
+inline const void* test_output_impl(char* v) { return v; }
+inline const void* test_output_impl(unsigned char* v) { return v; }
+inline const void* test_output_impl(signed char* v) { return v; }
+template<class T> inline const void* test_output_impl(T volatile* v) { return const_cast<T*>(v); }
+
+#if !defined( BOOST_NO_CXX11_NULLPTR )
+inline const void* test_output_impl(std::nullptr_t) { return nullptr; }
+#endif
+
+// print chars as numeric
+
+inline int test_output_impl( signed char const& v ) { return v; }
+inline unsigned test_output_impl( unsigned char const& v ) { return v; }
+
+// Whether wchar_t is signed is implementation-defined
+
+template<bool Signed> struct lwt_long_type {};
+template<> struct lwt_long_type<true> { typedef long type; };
+template<> struct lwt_long_type<false> { typedef unsigned long type; };
+
+inline lwt_long_type<(static_cast<wchar_t>(-1) < static_cast<wchar_t>(0))>::type test_output_impl( wchar_t const& v ) { return v; }
+
+#if !defined( BOOST_NO_CXX11_CHAR16_T )
+inline unsigned long test_output_impl( char16_t const& v ) { return v; }
+#endif
+
+#if !defined( BOOST_NO_CXX11_CHAR32_T )
+inline unsigned long test_output_impl( char32_t const& v ) { return v; }
+#endif
+
+inline std::string test_output_impl( char const& v )
+{
+    if( std::isprint( static_cast<unsigned char>( v ) ) )
+    {
+        return std::string( 1, v );
+    }
+    else
+    {
+        static const char char_table[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
+        char buffer[ 4 ];
+        buffer[ 0 ] = '\\';
+        buffer[ 1 ] = 'x';
+        buffer[ 2 ] = char_table[ (static_cast<unsigned char>( v ) >> 4u) & 0x0f ];
+        buffer[ 3 ] = char_table[ static_cast<unsigned char>( v ) & 0x0f ];
+
+        return std::string( buffer, 4u );
+    }
+}
+
+// Allow associating arbitrary context values to tests that get printed on error
+struct lwt_context_frame
+{
+    static const int max_values = 3;

Is there a reason for the particular value of 3? Why have multiple values anyway, since you already maintain a list of frames?

pdimov pdimov commented on May 25, 2025 12:25 UTC
Contributor

That is what I had in mind, yes. Please enclose the printed context values in ' for consistency with TEST_EQ.

pdimov pdimov commented on code on May 25, 2025 12:27 UTC
Code Review
include/boost/core/lightweight_test.hpp:1
@@ -45,11 +45,92 @@ namespace boost
 namespace detail
 {
 
+// specialize test output for char pointers to avoid printing as cstring
+template <class T> inline const T& test_output_impl(const T& v) { return v; }
+inline const void* test_output_impl(const char* v) { return v; }
+inline const void* test_output_impl(const unsigned char* v) { return v; }
+inline const void* test_output_impl(const signed char* v) { return v; }
+inline const void* test_output_impl(char* v) { return v; }
+inline const void* test_output_impl(unsigned char* v) { return v; }
+inline const void* test_output_impl(signed char* v) { return v; }
+template<class T> inline const void* test_output_impl(T volatile* v) { return const_cast<T*>(v); }
+
+#if !defined( BOOST_NO_CXX11_NULLPTR )
+inline const void* test_output_impl(std::nullptr_t) { return nullptr; }
+#endif
+
+// print chars as numeric
+
+inline int test_output_impl( signed char const& v ) { return v; }
+inline unsigned test_output_impl( unsigned char const& v ) { return v; }
+
+// Whether wchar_t is signed is implementation-defined
+
+template<bool Signed> struct lwt_long_type {};
+template<> struct lwt_long_type<true> { typedef long type; };
+template<> struct lwt_long_type<false> { typedef unsigned long type; };
+
+inline lwt_long_type<(static_cast<wchar_t>(-1) < static_cast<wchar_t>(0))>::type test_output_impl( wchar_t const& v ) { return v; }
+
+#if !defined( BOOST_NO_CXX11_CHAR16_T )
+inline unsigned long test_output_impl( char16_t const& v ) { return v; }
+#endif
+
+#if !defined( BOOST_NO_CXX11_CHAR32_T )
+inline unsigned long test_output_impl( char32_t const& v ) { return v; }
+#endif
+
+inline std::string test_output_impl( char const& v )
+{
+    if( std::isprint( static_cast<unsigned char>( v ) ) )
+    {
+        return std::string( 1, v );
+    }
+    else
+    {
+        static const char char_table[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
+        char buffer[ 4 ];
+        buffer[ 0 ] = '\\';
+        buffer[ 1 ] = 'x';
+        buffer[ 2 ] = char_table[ (static_cast<unsigned char>( v ) >> 4u) & 0x0f ];
+        buffer[ 3 ] = char_table[ static_cast<unsigned char>( v ) & 0x0f ];
+
+        return std::string( buffer, 4u );
+    }
+}
+
+// Allow associating arbitrary context values to tests that get printed on error
+struct lwt_context_frame
+{
+    static const int max_values = 3;

You'd use multiple nested contexts when the test is reached via several nested functions, whereas multiple values per single context is when your current iteration has more that one value, e.g. &p.x, &p.y in case p itself doesn't have op<<.

anarthal anarthal commented on code on May 25, 2025 12:32 UTC
Code Review
include/boost/core/lightweight_test.hpp:1
@@ -527,6 +596,48 @@ inline void lwt_init()
     boost::detail::test_results();
 }
 
+class lwt_context
+{
+    boost::detail::lwt_context_frame frame_;
+    
+    // Disallow copy and movement
+    lwt_context(const lwt_context&) {};
+    lwt_context& operator=(const lwt_context&) { return *this; }
+
+public:
+    template <class T>
+    explicit lwt_context(const T* value)
+    {
+        frame_.values[0].set_value(value);
+        frame_.values[1].set_null();
+        frame_.values[2].set_null();
+        boost::detail::test_results().push_context(frame_);
+    }
+
+    template <class T0, class T1>
+    lwt_context(const T0* value0, const T1* value1)
+    {
+        frame_.values[0].set_value(value0);
+        frame_.values[1].set_value(value1);
+        frame_.values[2].set_null();
+        boost::detail::test_results().push_context(frame_);
+    }
+
+    template <class T0, class T1, class T2>
+    lwt_context(const T0* value0, const T1* value1, const T2* value2)
+    {
+        frame_.values[0].set_value(value0);
+        frame_.values[0].set_value(value1);
+        frame_.values[0].set_value(value2);

Completely. Will add unit tests to detect these.

Does defining BOOST_LIGHTWEIGHT_TEST_OSTREAM to a global std::stringstream value sound a good approach for tests?

pdimov pdimov commented on code on May 25, 2025 14:14 UTC
Code Review
include/boost/core/lightweight_test.hpp:1
@@ -527,6 +596,48 @@ inline void lwt_init()
     boost::detail::test_results();
 }
 
+class lwt_context
+{
+    boost::detail::lwt_context_frame frame_;
+    
+    // Disallow copy and movement
+    lwt_context(const lwt_context&) {};
+    lwt_context& operator=(const lwt_context&) { return *this; }

Please remove the bodies here; the C++03 idiomatic way to disable copy and assign is to declare the members as private and not define them.

pdimov pdimov commented on code on May 25, 2025 14:15 UTC
Code Review
include/boost/core/lightweight_test.hpp:1
@@ -527,6 +596,48 @@ inline void lwt_init()
     boost::detail::test_results();
 }
 
+class lwt_context
+{
+    boost::detail::lwt_context_frame frame_;
+    
+    // Disallow copy and movement
+    lwt_context(const lwt_context&) {};
+    lwt_context& operator=(const lwt_context&) { return *this; }
+
+public:
+    template <class T>
+    explicit lwt_context(const T* value)
+    {
+        frame_.values[0].set_value(value);
+        frame_.values[1].set_null();
+        frame_.values[2].set_null();
+        boost::detail::test_results().push_context(frame_);
+    }
+
+    template <class T0, class T1>
+    lwt_context(const T0* value0, const T1* value1)
+    {
+        frame_.values[0].set_value(value0);
+        frame_.values[1].set_value(value1);
+        frame_.values[2].set_null();
+        boost::detail::test_results().push_context(frame_);
+    }
+
+    template <class T0, class T1, class T2>
+    lwt_context(const T0* value0, const T1* value1, const T2* value2)
+    {
+        frame_.values[0].set_value(value0);
+        frame_.values[0].set_value(value1);
+        frame_.values[0].set_value(value2);

Sounds fine to me.

Lastique Lastique commented on code on May 25, 2025 15:15 UTC
Code Review
include/boost/core/lightweight_test.hpp:1
@@ -527,6 +596,48 @@ inline void lwt_init()
     boost::detail::test_results();
 }
 
+class lwt_context
+{
+    boost::detail::lwt_context_frame frame_;
+    
+    // Disallow copy and movement
+    lwt_context(const lwt_context&) {};
+    lwt_context& operator=(const lwt_context&) { return *this; }

Better use BOOST_DELETED_FUNCTION, if we intend to keep C++03 compatibility.

Reviewers
Assignees
anarthal anarthal
Labels
risk: low confidence: 88.9% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 52.0% (MEDIUM) · Higher = larger blast radius
52.0%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 88.9% · Lower = rushed or shallow review
88.9%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 5.8% · Safe to merge
5.8%
Repository