Page MenuHomePhabricator

Avoid custom main for passing arguments to the unit tests
ClosedPublic

Authored by Fabien on Jan 6 2020, 16:00.

Details

Summary

Since D4474 the unit tests rely on BOOST_TEST_NO_MAIN to override the
default Boost unit tests framework main function.
This doesn't work by default when Boost is built as a static library,
which is the case when the software builds against the depends
libraries.
This diff replaces the custom main with a global fixture, that forwards
custom arguments before any test begins.

This is an alternative to D4837.

Test Plan
ninja check
ninja check-bitcoin-upgrade-activated

Edit src/tests/activation_tests.cpp: add the line

BOOST_TEST_MESSAGE("Phonon activation time : " << activation);

after the const auto activation = [...] in the isphononenabled test
case.

./src/test/test_bitcoin -t activation_tests --log_level=all

Look at the log, it should contain the line:

Phonon activation time : 1589544000

./src/test/test_bitcoin -t activation_tests --log_level=all \
  -- -phononactivationtime=1575158400

Look at the log, it should contain the line:

Phonon activation time : 1575158400

/src/test/test_bitcoin -t activation_tests --log_level=all -- -foo

Look at the log, it should contain the line (it may be prefixed with
more info):

Test setup error: std::invalid_argument: Invalid parameter -foo

Cross build `test_bitcoin` for any platform and check the build is

successful.

Diff Detail

Repository
rABC Bitcoin ABC
Branch
boost_global_fixture
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 8752
Build 15488: Default Diff Build & Tests
Build 15487: arc lint + arc unit

Event Timeline

This revision is now accepted and ready to land.Jan 6 2020, 16:22
jasonbcox added a subscriber: jasonbcox.
jasonbcox added inline comments.
src/test/test_bitcoin_main.cpp
57