dodexahedron / TerminalGuiDesigner

Forms Designer for Terminal.Gui (aka gui.cs)
MIT License
1 stars 0 forks source link

Create test fixture for ViewToCode class #31

Open dodexahedron opened 10 months ago

dodexahedron commented 10 months ago

Fun.

I let ReSharper generate a test fixture using AI, and it created....tests.... 😅

They weren't terribly meaningful, but at least provide a starting point. I committed them plus enough modifications to make them at least work in 421985d1b69aa6e7eb4f6d723c2d94b04c068fbb.

They will of course need a lot more work than this, which I'll be getting to shortly. The ones already written have brought up a potential problem, either with the test cases themselves or with the code it is testing.

The test that checks that no exceptions are thrown gets an exception when operating on the TextValidateField class. The Activator in ViewToCode.GenerateNewView dies with a nullreferenceexception because the constructor that is generated assigns null to Provider, which will cause a NRE in the second line of the setter of Terminal.Gui.TextValidateField.Provider.

While this is arguably a defect in Terminal.Gui itself, it does cause problems here, revealed by the new unit tests. It seems to me that ViewToCode.GenerateNewView should be using the ViewFactory, instead (I imagine it was probably added before ViewFactory existed, but I am not sure).

Sure enough, if I change it to use ViewFactory.Create, these succeed. But it breaks a ton of other tests, from something that happens in Tests.RoundTrip.

I'm continuing to investigate, and am sorta working on both this and #30 at the same time, since that's all pretty tightly coupled at the moment.