kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #40330
Re: Why is the advanced config object read-only?
Hi John,
That makes sense! Thanks for the detailed explanation.
-Jon
On Mon, Apr 29, 2019 at 8:28 AM John Beard <john.j.beard@xxxxxxxxx> wrote:
> On 29/04/2019 12:41, John Beard wrote:
>
> > Then you might start running into consistency issues with multiple
> > users of A_C getting different answers.
>
> Notably, there is a specific case that illustrates where global state
> can cause Bad Things (TM) right now: unit tests.
>
> Say you had a mutable ADVANCED_CFG, and you have a test suite like this:
>
> BOOST_AUTO_TEST_CASE( Test1 )
> {
> CONNECTIVITY_FOO thing;
> ADVANCED_CFG::GetCfg().m_whatever = true; // default false
>
> thing.Frobnicate(); // cares about m_whatever
> }
>
> BOOST_AUTO_TEST_CASE( Test2 )
> {
> // what is ADVANCED_CFG::GetCfg().m_whatever?
> // It depends on the test case ordering.
> // Test2 does not *have* to come second, and might even be
> concurrent
> // so AC::m_whatever could even change *during* this test
>
> CONNECTIVITY_FOO thing;
> thing.Frobnicate(); // what will this do?
> }
>
> Also, if core functions depend on A_C, it's very hard to test them with
> good coverage. It's better to pass the A_C as a higher level parameter,
> so you can do this:
>
> BOOST_AUTO_TEST_CASE( TestWithFeatureOn )
> {
> bool enable_feature = true;
> CONNECTIVITY_FOO thing( enable_feature );
> thing.Frobnicate(); // test with feature
> }
>
> BOOST_AUTO_TEST_CASE( TestWithFeatureOff )
> {
> bool enable_feature = false;
> CONNECTIVITY_FOO thing( enable_feature );
> thing.Frobnicate(); // test without feature
> }
>
> If CONNECTIVITY_FOO only used A_C internally, you cannot test the
> feature reliably as it depends on the config the user has set.
>
> Cheers,
>
> John
>
References