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

Fix unit tests that don't dispose View correctly. #3368

Closed
2 tasks
tig opened this issue Apr 1, 2024 · 1 comment
Closed
2 tasks

Fix unit tests that don't dispose View correctly. #3368

tig opened this issue Apr 1, 2024 · 1 comment
Labels
testing Issues related to testing
Milestone

Comments

@tig
Copy link
Collaborator

tig commented Apr 1, 2024

Unit test infrastructure that attempts to ease authoring of tests, but encourages bad programming practices are Bad. I used to not realize this, and am as guilty as anyone of propogating bad behavior.

This was highlighted when I discovered that in v1 and early v2 Application.Run was disposing the Toplevel:

This was fixed in #3338.

Moving forward I want us to be more hard core about this, and not letting any example code (Scenarios) or unit tests act badly. For the most part, the Scenarios have already been fixed because UI Catalog verifies things via DEBUG_IDISPOSABLE.

However, there are dozens of unit tests that are still coded slopily/incorrectly and should be fixed. This issue is to track the fixing of them.

  • Step 1 - Remove the call to Application.Top?.Dispose in AutoInitShutdown.After. This will cause several dozen unit tests to fail. The fix for most of them is to simply add a top.Dispose () as the last line of the test.

  • Step 2 - Change SetupFakeDriver to inherit from TestRespondersDisposed (and ensure Before/After call base). This will cause even more existing unit tests to fail. Here, the fixes will involve just disposing View objects the tests create but don't dispose.

@tig tig added the testing Issues related to testing label Apr 1, 2024
@tig tig changed the title Fix unit tests that don't dispose Toplevels correctly. Fix unit tests that don't dispose View correctly. Apr 1, 2024
tig added a commit to tig/Terminal.Gui that referenced this issue Apr 1, 2024
tig added a commit to tig/Terminal.Gui that referenced this issue Apr 1, 2024
@dodexahedron
Copy link
Collaborator

Oh hey. There's an annotation for static analysis that can be used, when appropriate, to help out in tracking these down, as well as help consumers of TG with the same issue.

MustDisposeResourceAttribute([MustDisposeResource])

It takes an optional boolean documented thusly:

When set to false, disposing of the resource is not obligatory. The main use-case for explicit [MustDisposeResource(false)] annotation is to loosen the annotation for inheritors.

@tig tig added this to the V2 Beta milestone May 25, 2024
tig added a commit that referenced this issue May 30, 2024
Fixes #3368. Fix unit tests to dispose properly
@tig tig closed this as completed May 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
testing Issues related to testing
Projects
Status: ✅ Done
Status: No status
Development

No branches or pull requests

2 participants