lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lmi] [PATCH] Add LMI_ASSERT_MESSAGE() macro


From: Greg Chicares
Subject: Re: [lmi] [PATCH] Add LMI_ASSERT_MESSAGE() macro
Date: Wed, 29 Apr 2020 22:42:35 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0

On 2014-10-06 17:57, Vadim Zeitlin wrote:
> 
>  There are just 2 more changes to non-test files that remain, so I'd like
> to submit them already, before the full testing patch. The first one of
> them is a pure addition and defines LMI_ASSERT_MESSAGE() macro which,
> unlike plain LMI_ASSERT(), shows the message specified as its second
> argument if the check fails. This still doesn't make the GUI test suite as
> user friendly as I'd like it to be, but it's better than nothing.
[...]
>  And here is the patch itself:
> 
> -- >8 --
> diff --git a/assert_lmi.hpp b/assert_lmi.hpp
> index a39d5b4..e65c1e3 100644
> --- a/assert_lmi.hpp
> +++ b/assert_lmi.hpp
> @@ -59,5 +59,40 @@
>          }                                                       \
>      while(0)
> 
> +
> +/// A version of LMI_ASSERT() allowing to specify additional information to 
> log
> +/// in case of assertion failure.
> +
> +#define LMI_ASSERT_MESSAGE(condition, message)                  \
> +    do                                                          \
> +        {                                                       \
> +        if(!(condition))                                        \
> +            {                                                   \
> +            std::ostringstream oss;                             \
> +            oss                                                 \
> +                << "Assertion '" << (#condition) << "' failed"  \
> +                << "\n(" << message << ")\n"                    \
> +                << "\n[file " << __FILE__                       \
> +                << ", line " << __LINE__ << "]\n"               \
> +                ;                                               \
> +            throw std::runtime_error(oss.str());                \
> +            }                                                   \
> +        }                                                       \
> +    while(0)
[...]
>  #endif // assert_lmi_hpp
> -- >8 --

That macro (with a slightly different name) was committed here:

commit 0f0a6c810fdcbea0ac611a9ae556bedab17caa20
Author: Gregory W. Chicares <address@hidden>
Date:   2014-10-10T17:13:30+00:00

    Add some new macros, with a unit test that fails to compile

Note that one macro argument, 'condition', is token-pasted,
but the other, 'message', is (deliberately) not.

Now the unit test fails with gcc-9 (log below). Can you see
any tidy way to fix it so that it works with both old and
new versions of gcc?

Here are the unit-test failures:

???? test failed: Caught exception
    'Assertion 'not_true' failed
(<0>).
[assert_lmi_test.cpp : 58]
'
  when
    'Assertion 'not_true' failed
(<0>).
[assert_lmi_test.cpp : 60]
'
  was expected.
[file /opt/lmi/src/lmi/assert_lmi_test.cpp, line 57]

???? test failed: Caught exception
    'Assertion '(not_true) == (true)' failed
(expected 1 vs observed 0).
[assert_lmi_test.cpp : 64]
'
  when
    'Assertion '(not_true) == (true)' failed
(expected 1 vs observed 0).
[assert_lmi_test.cpp : 66]
'
  was expected.
[file /opt/lmi/src/lmi/assert_lmi_test.cpp, line 63]

???? 2 test errors detected; 1 tests succeeded

???? returning with error code 201

???? 
???? errors detected; see stdout for details
make[2]: [/opt/lmi/src/lmi/workhorse.make:1322: assert_lmi_test.exe-run] Error 
201 (ignored)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]