Boost logo

Boost :

Subject: Re: [boost] [test] unit test command-line handling
From: Raffi Enficiaud (raffi.enficiaud_at_[hidden])
Date: 2018-09-12 18:28:00


On 12.09.18 00:21, Stefan Seefeld via Boost wrote:
> Hello,
>
> this is a question concerning the Boost.Test framework.
>
> I'd like to pass command-line arguments to my tests, and I'm unsure of
> how to proceed. I have found
> https://www.boost.org/doc/libs/1_68_0/libs/test/doc/html/boost_test/adv_scenarios/obsolete_init_func.html,
> which shows how to access the command-line programmatically, but that's
> declared obsolete, and it's also lacking some important info, such as
> how I should handle the argv vector. Are there any examples that
> demonstrate this use case ? Specifically:
>
> * What (non-deprecated) API can I use to access command-line arguments
> during test initialization ?

By "test initialization", do you mean before the first test starts?
The argc/argv are available to the master test suite:

https://www.boost.org/doc/libs/1_68_0/libs/test/doc/html/boost_test/tests_organization/test_suite/master_test_suite.html#boost_test.tests_organization.test_suite.master_test_suite.command_line_arguments_access_in

In 1.68, it is also possible to use this for data driven test cases,
using the make_delayed (if you need a test generator that is dependent
on your argc/argv).

https://www.boost.org/doc/libs/1_68_0/libs/test/doc/html/boost_test/change_log.html#boost_test.change_log.new_features

> * How does my own handling of command-line arguments interact with
> Boost.Test's own command-line argument handling ?

I am surprised I did not create a doc entry about this. The way it works
is indicated in the change logs of boost.test:

https://www.boost.org/doc/libs/1_68_0/libs/test/doc/html/boost_test/change_log.html#boost_test.change_log.boost_test_v3_1_boost_1_60

Anything after -- is passed to the master test suite argc/argv and is
available to your test module.

I will update the doc on the two points above to make it clearer.

Raffi

>
> Thanks,
>
>
> Stefan
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk