Boost logo

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-07-23 17:28:09


>> 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


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