beyond-all-reason / Beyond-All-Reason

Main game repository for Beyond All Reason.
https://www.beyondallreason.info/
Other
1.8k stars 300 forks source link

Add Test.prepareWidget and Test.restoreWidget to simplify common test initializations #3951

Closed saurtron closed 4 days ago

saurtron commented 5 days ago

Work done

Explanation

While working on the safe-reordering-widgets PR noticed a few widget tests calling EnableWidget and EnableWidget, all doing the same thing, namely remembering if the widget was enabled, then disabling and re-enabling it with locals access. On cleanup they will check the previous enabled state and either disable or reenable without locals access as needed.

This PR introduces two methods and needed mechanism inside dbg_test_runner.lua to avoid all the copy paste among tests, also hiding some implementation details from them. Also makes the restoring after the test automatic for tests that did call Test.prepareWidget, although they can also call it manually in case it's needed.