|
Boost Users : |
Subject: Re: [Boost-users] Boost.Test BOOST_TEST/BOOST_REQUIRE_MESSAGE message arg problems
From: Olaf Peter (ope-devel_at_[hidden])
Date: 2018-08-12 18:19:33
Am 08.08.2018 um 13:22 schrieb Raffi Enficiaud via Boost-users:
> On 23.07.18 19:28, Olaf Peter via Boost-users wrote:
>>
>>>> How to get this?
>>>
>>> What about :
>>>
>>> 1- using test-case fixtures for writing things at the end of the test
>>> 2- registering an observer for getting the failure signal?
>>>
>>> The observer is (kind of) described here:
>>> https://www.boost.org/doc/libs/master/libs/test/doc/html/boost/unit_test/framework/register_observer.html
>>>
>>>
>>> You may install and remove it globally by using a global fixture:
>>>
>>> https://www.boost.org/doc/libs/master/libs/test/doc/html/boost_test/utf_reference/test_org_reference/test_org_boost_test_global_fixture.html
>>>
>>>
>>> Once registered, it will capture the events that you want,
>>> especially the failure cases.
>>>
>>> From the observer, you can get the current test cases with this
>>>
>>> https://www.boost.org/doc/libs/master/libs/test/doc/html/boost/unit_test/framework/current_test_case.html
>>>
>>
>> OK, my test_observer_fixture with overloads is ready:
>>
>> class test_observer_fixture
>> {
>> Â Â Â Â struct test_observer : public utf::test_observer
>> Â Â Â Â {
>> Â Â Â Â Â Â Â virtual void test_unit_aborted(utf::test_unit const& tu)
>> override;
>> Â Â Â Â Â Â Â virtual void assertion_result(utf::assertion_result result)
>> override;
>> Â Â Â Â Â Â Â // are the others required for my use case?
>> Â Â Â Â };
>>
>>     test_observer                           observer;
>>
>> public:
>> Â Â Â Â test_observer_fixture();
>> Â Â Â Â ~test_observer_fixture();
>>
>> public:
>> Â Â Â Â void setup();
>> Â Â Â Â void teardown();
>> };
>>
>> and get called by my BOOST_DATA_TEST_CASE. What is the prefered way
>> to use this Fixture to save the test result in case of failure/abort?
>>
>>
>> BOOST_DATA_TEST_CASE( wave,
>> Â Â Â Â utf_data::make_delayed<testsuite::dataset_loader>(
>> "test_case/wave" ),
>> Â Â Â Â input, expected, orig_file_name)
>> {
>> Â Â Â ...
>> Â Â Â Â auto [parse_ok, parse_result] = parse(input, parser,
>> test_case_name);
>>
>> Â Â Â Â BOOST_REQUIRE(parse_ok);
>>
>> Â Â Â Â BOOST_TEST(parse_result == expected, btt::per_element());
>>
>> Â Â Â Â Â Â Â ??? my_diagnostic_saving .... (orig_file_name, input,
>> parse_result);
>> Â Â Â Â );
>> }
>>
>> Thanks,
>> Olaf
>
> Sorry for the late answer,
>
> In the teardown, you may check if the current test had failures. You
> can do so by accessing the global singleton "results_collector". If
> "tc" is the current test case (that you can get with
> "current_test_case"):
>
> test_results const& tr = results_collector.results( tc.p_id );
>
> will give you the result.
>
> If the fixture should be applied to each of the test case inside your
> suite, you can install it like this:
>
> https://www.boost.org/doc/libs/1_67_0/libs/test/doc/html/boost_test/tests_organization/fixtures/case.html#boost_test.tests_organization.fixtures.case.fixture_for_a_complete_subtree
>
>
> Accessing via the test result will let you check if this is a failure
> or an abort: the BOOST_TEST_REQUIRE (BOOST_REQUIRE is deprecated) will
> fire an abort if I remember well. Using this way to install the
> fixture will also let you access the instance of the fixture directly
> (see examples in the documentation).
>
> Since you solved your issue with the double messages, I would just use
> the appropriate fixture and forget about the observer.
>
> Raffi
>
> PS: I am not sure that the teardown is called for data test case
> (something I forgot to check). You may do that in the dtor of your
> fixture.
thanks for your answer - I will implement and check it next.
Regards,
Olaf
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net