Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option override support for tests #38051

Merged
merged 3 commits into from
Feb 19, 2020

Conversation

jbytheway
Copy link
Contributor

Summary

SUMMARY: Infrastructure "Added override_option class to help write tests which require a particular option to be set"

Purpose of change

Originally inspired by the fact that one of the iteminfo tests fails if the game is set to metric weight display (due to a lbs/kg mismatch).

Generalised into a tool for temporarily overriding options in tests, something that several tests need.

Describe the solution

Add override_option, a new test helper class which provides RAII-style option overriding (set in constructor, reset to old value in destructor).

Use this in the places where the tests were already messing with options, and add it also in the particular iteminfo test that was failing for me.

Describe alternatives you've considered

Leaving the old solution where tests changed options and left them changed, but that leads to test ordering dependencies, and makes test failures harder to debug.

Testing

Just unit tests.

@ifreund ifreund added [C++] Changes (can be) made in C++. Previously named `Code` Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style Code: Tests Measurement, self-control, statistics, balancing. labels Feb 16, 2020
@@ -724,25 +725,25 @@ static void merge_invlet_test( player &dummy, inventory_location from )

#define invlet_test_autoletter_off( name, dummy, from, to ) \
SECTION( std::string( name ) + " (auto letter off)" ) { \
get_options().get_option( "AUTO_INV_ASSIGN" ).setValue( "disabled" ); \
override_option _( "AUTO_INV_ASSIGN", "disabled" ); \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It took me a second to parse what was happening here due to the fact that we use _( ) for translation. Maybe calling the variable _handle or something would make what's happening a little more obvious?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, that slipped my mind. I renamed them all opt.

This temporarily changes an option value and restores it afterwards.
Replace places where the tests were directly modifying options with uses
of the new override_option.

This should help to reduce the dependency of the tests on test ordering.
One iteminfo test could fail when the options were configured to metric,
so override that option for that test.
@jbytheway jbytheway force-pushed the test_option_override branch from 823776f to a3c5415 Compare February 19, 2020 09:31
@ZhilkinSerg ZhilkinSerg merged commit 9b91fbf into CleverRaven:master Feb 19, 2020
@jbytheway jbytheway deleted the test_option_override branch February 20, 2020 02:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[C++] Changes (can be) made in C++. Previously named `Code` Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style Code: Tests Measurement, self-control, statistics, balancing.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants