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 tests that check Bounds or Frame before IsInitialzied == true are bogus #2450

Closed
tig opened this issue Mar 26, 2023 · 0 comments
Closed
Labels
v2 For discussions, issues, etc... relavant for v2

Comments

@tig
Copy link
Collaborator

tig commented Mar 26, 2023

e.g.

[Fact, AutoInitShutdown]
		public void AutoSize_False_SetWidthHeight_With_Dim_Fill_And_Dim_Absolute_After_IsAdded_And_IsInitialized ()
		{
			var win = new Window (new Rect (0, 0, 30, 80), "win");
			var label = new Label () { Width = Dim.Fill () };
			win.Add (label);
			Application.Top.Add (win);

			Assert.True (label.IsAdded);

			// Text is empty so height=0
			Assert.True (label.AutoSize);
			// BUGBUG: LayoutSubviews has not been called, so this test is not really valid (pos/dim are indeterminate, not 0)
			Assert.Equal ("{X=0,Y=0,Width=0,Height=0}", label.Bounds.ToString ());

			label.Text = "First line\nSecond line";
			Application.Top.LayoutSubviews ();

			Assert.True (label.AutoSize);
			// BUGBUG: This test is bogus: label has not been initialized. pos/dim is indeterminate!
			Assert.Equal ("{X=0,Y=0,Width=28,Height=2}", label.Bounds.ToString ());
			Assert.False (label.IsInitialized);

			Application.Begin (Application.Top);

			Assert.True (label.AutoSize);
			Assert.Equal ("{X=0,Y=0,Width=28,Height=2}", label.Bounds.ToString ());
			Assert.True (label.IsInitialized);

			label.AutoSize = false;
			Application.Refresh ();

			Assert.False (label.AutoSize);
			Assert.Equal ("{X=0,Y=0,Width=28,Height=1}", label.Bounds.ToString ());
		}

See the 2nd BUGBUG above.

In v1 we thought it was ok to "read" Bounds, Frame, X, Y, Height, and Width for a ComputedLayout view before Begin/EndInit were called. It's not; the state of the view is indeterminate until it's been initialized.

In #2360 I will be refactoring unit tests that do this. I will also be adding diagnostics to output debug spew when detected.

image

This is related to #2449.

@tig tig added the v2 For discussions, issues, etc... relavant for v2 label Mar 26, 2023
@tig tig moved this to 📋 Backlog in Terminal.Gui V2 Beta Mar 27, 2023
@tig tig moved this from 📋 Backlog to 🏗 In progress in Terminal.Gui V2 Beta Mar 27, 2023
@tig tig closed this as completed Apr 16, 2023
@github-project-automation github-project-automation bot moved this from 🏗 In progress to ✅ Done in Terminal.Gui V2 Beta Apr 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v2 For discussions, issues, etc... relavant for v2
Projects
No open projects
Status: ✅ Done
Development

No branches or pull requests

1 participant