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

Unit test conversion and TGD modernization (WIP) #260

Merged
merged 219 commits into from
Dec 19, 2023

Conversation

dodexahedron
Copy link
Contributor

This is a work-in-progress for conversion of unit tests for TGD to NUnit 4.0, as well as expansion, improvement, and modernization of various tests.
This also includes some preliminary incidental modernization work on TGD itself, primarily aimed at eliminating some reflection, and some redundant operations.

See https://github.com/dodexahedron/TerminalGuiDesigner for current activity

dodexahedron and others added 30 commits December 2, 2023 04:18
Pushing so I can switch computers
Conversion to Constraints for #1
Added a couple of assertions for #2
A couple of Assumptions for #3
A few Assert.Multiples for #4
Takes care of 2 inspections VS was throwing
Replaces GetArray
Using framework naming convention for methods that return boolean status and have out parameters that are non-null on success
There's another use of the old method, but I have to stare at it a bit more to see what it's really doing.
Might need to discuss that one when we chat.
…o convert-tests-to-constraint-model

Interim merge for #15
There's more to be done, but I'm going to get back to test conversion for a bit, now that several of the loudest issues are addressed
github wants this re-pushed after switch to advanced
Takes care of 2 inspections VS was throwing
Use null propagation
Private members that can or should be readonly
Reduce allocations, garbage, and enumerations with this List
Add TryGetArray<T>
Using framework naming convention for methods that return boolean status and have out parameters that are non-null on success
There's another use of the old method, but I have to stare at it a bit more to see what it's really doing.
Might need to discuss that one when we chat.
Convert ColorSchemeTests to Constraint model

Get10By10View can be static
Pushing so I can switch computers
Conversion to Constraints for #1
Added a couple of assertions for #2
A couple of Assumptions for #3
A few Assert.Multiples for #4
Also allows the list to be readonly
Unrolled a ton of test cases
Expanded scope of tests significantly
Combine both GetCode tests into a single unrolled method
Unroll some more tests
Add more cases to some tests
Most assertions removed because, if the IsAbsolute assertion passes, they are redundant to the IsAbsolute test cases.
…nto convert-tests-to-constraint-model

* 19-convert-postests-to-constraint-model:
  More coverage. Bugs revealed.
  Add test for method that wasn't covered. Revealed a bug
  That was accidentally committed a while back. Remove it.
  Convert the rest but ignore them, because they're redundant
  Remove this test, as it's solely a Terminal.Gui test
  Remove redundant test
  Convert this case
  That's not valid
  Fix nullability context in PosExtensions
  Remove redundant test
  Finish unrolling and expanding IsAnchorEnd tests
  Remove redundant tests
  More refactoring
  New tests revealed this bug
  Significant refactor
  Global usings
  Add a couple of handy helper types for tests to cut down on boilerplate
Still work in progress.
Revealed several bugs through increased test coverage.
#19
@dodexahedron
Copy link
Contributor Author

dodexahedron commented Dec 19, 2023

I just did a bunch of work on the PosTests fixture.

Coverage was increased significantly, and it revealed several bugs, most of which are noted in PosExtensions.cs or in output of tests marked Ignore (visible in test results, while allowing the fixture to "pass" for now).

The current state of that is merged to this branch.

I have not yet fixed them, as I wanted to call attention in case that raises any alarms/thoughts on your end.

Some of them are the fault of Terminal.Gui itself, but I'm pretty sure we can work around them without much work.

@tznind tznind merged commit 845076f into gui-cs:v2 Dec 19, 2023
@tznind
Copy link
Collaborator

tznind commented Dec 19, 2023

I just did a bunch of work on the PosTests fixture.

Coverage was increased significantly, and it revealed several bugs, most of which are noted in PosExtensions.cs or in output of tests marked Ignore (visible in test results, while allowing the fixture to "pass" for now).

The current state of that is merged to this branch.

I have not yet fixed them, as I wanted to call attention in case that raises any alarms/thoughts on your end.

Some of them are the fault of Terminal.Gui itself, but I'm pretty sure we can work around them without much work.

Thanks. This is awesome work. I have done a bit of manual testing and everything seems working in the editor and all the tests pass so I have merged. Feel free to continue working on this branch or create a new one. The diff was getting a bit unwieldy so I thought it was best to merge in.

I looked into the Pos issue and I have created a new bug in Terminal.Gui itself. I have had to do some of this 'unpacking' of PosCombine 0 before but really it shouldn't be a thing for so simple a method:
gui-cs/Terminal.Gui#3064

@dodexahedron dodexahedron mentioned this pull request Dec 19, 2023
@dodexahedron
Copy link
Contributor Author

Yeah, I'm cool with treating this branch as safe to merge.

I do individual work items on separate branches (one per issue, for the most part), and then merge them into this one, when done, if you ever want to look at more bite-sized chunks (or you can at least still see where they merged in, even if I've deleted the branch spec by the time you see it.

Those of course show up in the history here, basically looking like a squashed copy of all the commits on each branch into this one.

I'll keep noting in the commits and annotating in code, when I find bugs and such, unless they're simple and non-impacting, in which case I'm likely to just go ahead and take care of it in the moment, like how I went ahead and put the nullable context ?s on those Pos Extension methods.

However, there were a couple of changes over the past few merges that are a bit bigger than nullability context:

  • KeyMap loading now uses the standard Microsoft.Extensions.Configuration API. It still uses YAMLDotNet under the hood, but now we have the ability to support any kind of configuration input supported by that, for almost no effort, in the future.
  • KeyMap and ColorSchemeBlueprint got turned into records, for a bunch of reasons, mostly centered around simpler testing and that configuration settings classes are quite well-suited for being records.
  • I have been making some internal changes mostly to private methods, largely centered around just some cleanup activities like turning big sets of if-return if-return if-return blocks into switches (preference toward expressions, for brevity, when possible) with guard clauses to cut down like 60% of the code volume for those, while also gaining an unimportant (for this kind of application) performance boost, as a side effect. Mostly, it's for readability, since many more cases can fit on the screen, making it easier for meatbags like us to deal with visually. 😅
  • Probably a few other similar things. I always make sure everything passes on existing tests before committing changes, and ensure I've got a test covering it, before merge.
  • The ViewFactory changes, which have yet to be merged, but which I want to go over with a fine-toothed comb before I do merge them, just in case. Shouldn't be a problem, but I'm taking a slow approach since there's no rush to get there, since the current implementation does work.

I think we should do a workaround and fix for that, for a couple of reasons, regardless of if it gets fixed in Terminal.Gui. Most importantly, if it's a generic Pos, which is the only kind Terminal.Gui actually exposes publicly, any one of the IsWhateverTypeOfPos() methods will return true, if it's null. But, also, TGD has a bug in that it treats Pos types created from a literal value as absolute and zero, but then has inconsistent behavior because those methods all just return true, which breaks that assumption.

Also, I think it would be good for Terminal.Gui to actually expose the sub-classes of Pos, because they're useful to be able to identify by their type, rather than having to do what TGD already has to do, which is that string comparison of the type name. If that's "fixed" in Terminal.Gui, we wouldn't have to do that any more, which would be great. I really don't see or understand the reason for those being internal classes, over there. It creates a potential problem with inheritance, anyway, if someone were to inherit from Pos. Also, if TG exposed those types publicly, many of those extension methods would actually just plain no longer be necessary, since they're essentially a workaround for that design detail.

The only reason I didn't go ahead and do the fix to the part we have control over, on the TGD end (it would be suuuuper simple), is because that could have subtle effects in the UI, if any code paths actually do reach that stuff, at runtime, and I just wanted to make you aware of it before I touched anything, in case some report were to come in related to it. I have a pretty strong feeling it does hit them, sometimes, because I've had cases when using TGD where a position mysteriously turns into another type of position, if something didn't work out quite right. Now that I've seen where that most likely comes from, I'm pretty sure fixing the null handling will, at minimum, reduce the instance of that, or at least bubble the underlying problem up to something more obvious that can be addressed, if that's not the root of it.

Alrighty. Enough rambling for now. 😅
I'm going to go back and make a little extra coverage pass over some fixtures I've already touched, before I move on to the next fixture, just because I'm kinda in the mood for that over the somewhat more rote conversion of existing tests. In fact, I had one more test method already in the works for PosExtensions that visual studio didn't actually save til I exited, so it didn't get included in the last commit before I merged. :| It's got the same issue as several others in there do, around how null Pos instances get handled.

@tznind
Copy link
Collaborator

tznind commented Feb 10, 2024

I think this is the PR that nuked the code coverage

image

When I run the code coverage locally I still get 75%

Maybe codeql.yml is generating additional coverage output files too somehow? Cant see why it is dropping to 12%

image

@tznind
Copy link
Collaborator

tznind commented Feb 10, 2024

Any ideas @dodexahedron? I can't see anything that looks like it would change the CI except .github/workflows/codeql.yml

Well that also is not responsible because removing it did nothing (see on test branch) https://github.com/gui-cs/TerminalGuiDesigner/actions/runs/7857029886/job/21440440937

@tznind
Copy link
Collaborator

tznind commented Feb 10, 2024

image

@tznind
Copy link
Collaborator

tznind commented Feb 10, 2024

Moving this to an issue: #288

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants