From 48034e05485eb2357e23eec5f7d84d567566389c Mon Sep 17 00:00:00 2001 From: Jacob Date: Sat, 18 May 2024 22:53:21 +0200 Subject: [PATCH] Add test.NewTempApp() to tear down app at the end of the test --- canvas/text_test.go | 6 +-- container/apptabs_desktop_flakey_test.go | 6 +-- container/apptabs_desktop_test.go | 21 ++++------- container/apptabs_mobile_flakey_test.go | 6 +-- container/apptabs_mobile_test.go | 21 ++++------- container/doctabs_desktop_test.go | 27 +++++--------- container/doctabs_mobile_test.go | 27 +++++--------- container/tabs_test.go | 3 +- dialog/color_button_test.go | 3 +- dialog/color_channel_test.go | 3 +- dialog/color_picker_test.go | 12 ++---- dialog/color_preview_test.go | 3 +- dialog/color_test.go | 28 +++++--------- dialog/color_wheel_test.go | 3 +- dialog/confirm_test.go | 3 +- dialog/custom_test.go | 18 +++------ dialog/form_test.go | 3 +- internal/driver/common/canvas_test.go | 3 +- internal/driver/glfw/menu_bar_test.go | 6 +-- internal/painter/image_test.go | 3 +- internal/widget/shadow_test.go | 15 +++----- test/testapp.go | 10 +++++ widget/accordion_test.go | 3 +- widget/activity_internal_test.go | 3 +- widget/activity_test.go | 6 +-- widget/button_internal_test.go | 3 +- widget/button_test.go | 18 +++------ widget/check_test.go | 3 +- widget/entry_password_extend_test.go | 3 +- widget/entry_test.go | 3 +- widget/entry_validation_test.go | 3 +- widget/fileicon_test.go | 3 +- widget/form_test.go | 30 +++++---------- widget/gridwrap_test.go | 2 +- widget/hyperlink_test.go | 6 +-- widget/icon_test.go | 3 +- widget/label_test.go | 6 +-- widget/list_test.go | 29 ++++++--------- widget/menu_desktop_test.go | 9 ++--- widget/menu_mobile_test.go | 6 +-- widget/menu_test.go | 6 +-- widget/popup_test.go | 24 ++++-------- widget/select_entry_internal_test.go | 18 +++------ widget/select_internal_test.go | 3 +- widget/select_test.go | 30 +++++---------- widget/slider_test.go | 6 +-- widget/table_desktop_test.go | 3 +- widget/table_test.go | 47 ++++++++---------------- widget/tree_internal_test.go | 9 ++--- widget/tree_test.go | 9 ++--- widget/widget_test.go | 3 +- 51 files changed, 184 insertions(+), 343 deletions(-) diff --git a/canvas/text_test.go b/canvas/text_test.go index 00fe12aab9..bc3ec9c197 100644 --- a/canvas/text_test.go +++ b/canvas/text_test.go @@ -35,8 +35,7 @@ func TestText_MinSize_NoMultiLine(t *testing.T) { } func TestText_Layout(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) for name, tt := range map[string]struct { text string @@ -115,8 +114,7 @@ func TestText_Layout(t *testing.T) { } func TestText_CarriageReturn(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) for name, tt := range map[string]struct { text string diff --git a/container/apptabs_desktop_flakey_test.go b/container/apptabs_desktop_flakey_test.go index d888a18636..774d68ac61 100644 --- a/container/apptabs_desktop_flakey_test.go +++ b/container/apptabs_desktop_flakey_test.go @@ -12,8 +12,7 @@ import ( ) func TestAppTabs_ApplyTheme(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) w := test.NewWindow( container.NewAppTabs(&container.TabItem{Text: "Test", Content: widget.NewLabel("Text")}), @@ -30,8 +29,7 @@ func TestAppTabs_ApplyTheme(t *testing.T) { } func TestAppTabs_ChangeItemContent(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) item1 := &container.TabItem{Text: "Test1", Content: widget.NewLabel("Text1")} item2 := &container.TabItem{Text: "Test2", Content: widget.NewLabel("Text2")} diff --git a/container/apptabs_desktop_test.go b/container/apptabs_desktop_test.go index a327a2a7d0..2b8c494173 100644 --- a/container/apptabs_desktop_test.go +++ b/container/apptabs_desktop_test.go @@ -17,8 +17,7 @@ import ( ) func TestAppTabs_ChangeItemIcon(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) item1 := &container.TabItem{Icon: theme.CancelIcon(), Content: widget.NewLabel("Text1")} item2 := &container.TabItem{Icon: theme.ConfirmIcon(), Content: widget.NewLabel("Text2")} @@ -41,8 +40,7 @@ func TestAppTabs_ChangeItemIcon(t *testing.T) { } func TestAppTabs_ChangeItemText(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) item1 := &container.TabItem{Text: "Test1", Content: widget.NewLabel("Text1")} item2 := &container.TabItem{Text: "Test2", Content: widget.NewLabel("Text2")} @@ -65,8 +63,7 @@ func TestAppTabs_ChangeItemText(t *testing.T) { } func TestAppTabs_DynamicTabs(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) item1 := &container.TabItem{Text: "Test1", Content: widget.NewLabel("Text 1")} tabs := container.NewAppTabs(item1) @@ -117,8 +114,7 @@ func TestAppTabs_DynamicTabs(t *testing.T) { } func TestAppTabs_HoverButtons(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) item1 := &container.TabItem{Text: "Test1", Content: widget.NewLabel("Text1")} item2 := &container.TabItem{Text: "Test2", Content: widget.NewLabel("Text2")} @@ -148,8 +144,7 @@ func TestAppTabs_HoverButtons(t *testing.T) { } func TestAppTabs_Layout(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) w := test.NewWindow(nil) defer w.Close() @@ -248,8 +243,7 @@ func TestAppTabs_Layout(t *testing.T) { } func TestAppTabs_SetTabLocation(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) item1 := &container.TabItem{Text: "Test1", Content: widget.NewLabel("Text 1")} item2 := &container.TabItem{Text: "Test2", Content: widget.NewLabel("Text 2")} @@ -281,8 +275,7 @@ func TestAppTabs_SetTabLocation(t *testing.T) { } func TestAppTabs_Tapped(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) item1 := &container.TabItem{Text: "Test1", Content: widget.NewLabel("Text 1")} item2 := &container.TabItem{Text: "Test2", Content: widget.NewLabel("Text 2")} diff --git a/container/apptabs_mobile_flakey_test.go b/container/apptabs_mobile_flakey_test.go index 8de37b101f..6134913e61 100644 --- a/container/apptabs_mobile_flakey_test.go +++ b/container/apptabs_mobile_flakey_test.go @@ -12,8 +12,7 @@ import ( ) func TestAppTabs_ApplyTheme(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) w := test.NewWindow( container.NewAppTabs(&container.TabItem{Text: "Test", Content: widget.NewLabel("Text")}), @@ -30,8 +29,7 @@ func TestAppTabs_ApplyTheme(t *testing.T) { } func TestAppTabs_ChangeItemContent(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) item1 := &container.TabItem{Text: "Test1", Content: widget.NewLabel("Text1")} item2 := &container.TabItem{Text: "Test2", Content: widget.NewLabel("Text2")} diff --git a/container/apptabs_mobile_test.go b/container/apptabs_mobile_test.go index 1d1ff8f90d..8c8672dee7 100644 --- a/container/apptabs_mobile_test.go +++ b/container/apptabs_mobile_test.go @@ -18,8 +18,7 @@ import ( ) func TestAppTabs_ChangeItemIcon(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) item1 := &container.TabItem{Icon: theme.CancelIcon(), Content: widget.NewLabel("Text1")} item2 := &container.TabItem{Icon: theme.ConfirmIcon(), Content: widget.NewLabel("Text2")} @@ -42,8 +41,7 @@ func TestAppTabs_ChangeItemIcon(t *testing.T) { } func TestAppTabs_ChangeItemText(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) item1 := &container.TabItem{Text: "Test1", Content: widget.NewLabel("Text1")} item2 := &container.TabItem{Text: "Test2", Content: widget.NewLabel("Text2")} @@ -66,8 +64,7 @@ func TestAppTabs_ChangeItemText(t *testing.T) { } func TestAppTabs_DynamicTabs(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) item1 := &container.TabItem{Text: "Test1", Content: widget.NewLabel("Text 1")} tabs := container.NewAppTabs(item1) @@ -118,8 +115,7 @@ func TestAppTabs_DynamicTabs(t *testing.T) { } func TestAppTabs_HoverButtons(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) test.ApplyTheme(t, internalTest.LightTheme(theme.DefaultTheme())) item1 := &container.TabItem{Text: "Test1", Content: widget.NewLabel("Text1")} @@ -144,8 +140,7 @@ func TestAppTabs_HoverButtons(t *testing.T) { } func TestAppTabs_Layout(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) w := test.NewWindow(nil) defer w.Close() @@ -244,8 +239,7 @@ func TestAppTabs_Layout(t *testing.T) { } func TestAppTabs_SetTabLocation(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) item1 := &container.TabItem{Text: "Test1", Content: widget.NewLabel("Text 1")} item2 := &container.TabItem{Text: "Test2", Content: widget.NewLabel("Text 2")} @@ -277,8 +271,7 @@ func TestAppTabs_SetTabLocation(t *testing.T) { } func TestAppTabs_Tapped(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) item1 := &container.TabItem{Text: "Test1", Content: widget.NewLabel("Text 1")} item2 := &container.TabItem{Text: "Test2", Content: widget.NewLabel("Text 2")} diff --git a/container/doctabs_desktop_test.go b/container/doctabs_desktop_test.go index dc2949de02..b81786cebe 100644 --- a/container/doctabs_desktop_test.go +++ b/container/doctabs_desktop_test.go @@ -17,8 +17,7 @@ import ( ) func TestDocTabs_ApplyTheme(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) w := test.NewWindow( container.NewDocTabs(&container.TabItem{Text: "Test", Content: widget.NewLabel("Text")}), @@ -35,8 +34,7 @@ func TestDocTabs_ApplyTheme(t *testing.T) { } func TestDocTabs_ChangeItemContent(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) item1 := &container.TabItem{Text: "Test1", Content: widget.NewLabel("Text1")} item2 := &container.TabItem{Text: "Test2", Content: widget.NewLabel("Text2")} @@ -59,8 +57,7 @@ func TestDocTabs_ChangeItemContent(t *testing.T) { } func TestDocTabs_ChangeItemIcon(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) item1 := &container.TabItem{Icon: theme.CancelIcon(), Content: widget.NewLabel("Text1")} item2 := &container.TabItem{Icon: theme.ConfirmIcon(), Content: widget.NewLabel("Text2")} @@ -83,8 +80,7 @@ func TestDocTabs_ChangeItemIcon(t *testing.T) { } func TestDocTabs_ChangeItemText(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) item1 := &container.TabItem{Text: "Test1", Content: widget.NewLabel("Text1")} item2 := &container.TabItem{Text: "Test2", Content: widget.NewLabel("Text2")} @@ -113,8 +109,7 @@ func TestDocTabs_ChangeItemText(t *testing.T) { } func TestDocTabs_DynamicTabs(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) item1 := &container.TabItem{Text: "Test1", Content: widget.NewLabel("Text 1")} tabs := container.NewDocTabs(item1) @@ -165,8 +160,7 @@ func TestDocTabs_DynamicTabs(t *testing.T) { } func TestDocTabs_HoverButtons(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) item1 := &container.TabItem{Text: "Test1", Content: widget.NewLabel("Text1")} item2 := &container.TabItem{Text: "Test2", Content: widget.NewLabel("Text2")} @@ -202,8 +196,7 @@ func TestDocTabs_HoverButtons(t *testing.T) { } func TestDocTabs_Layout(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) w := test.NewWindow(nil) defer w.Close() @@ -302,8 +295,7 @@ func TestDocTabs_Layout(t *testing.T) { } func TestDocTabs_SetTabLocation(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) item1 := &container.TabItem{Text: "Test1", Content: widget.NewLabel("Text 1")} item2 := &container.TabItem{Text: "Test2", Content: widget.NewLabel("Text 2")} @@ -335,8 +327,7 @@ func TestDocTabs_SetTabLocation(t *testing.T) { } func TestDocTabs_Tapped(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) item1 := &container.TabItem{Text: "Test1", Content: widget.NewLabel("Text 1")} item2 := &container.TabItem{Text: "Test2", Content: widget.NewLabel("Text 2")} diff --git a/container/doctabs_mobile_test.go b/container/doctabs_mobile_test.go index 6dd788404c..2679c510fd 100644 --- a/container/doctabs_mobile_test.go +++ b/container/doctabs_mobile_test.go @@ -18,8 +18,7 @@ import ( ) func TestDocTabs_ApplyTheme(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) w := test.NewWindow( container.NewDocTabs(&container.TabItem{Text: "Test", Content: widget.NewLabel("Text")}), @@ -36,8 +35,7 @@ func TestDocTabs_ApplyTheme(t *testing.T) { } func TestDocTabs_ChangeItemContent(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) item1 := &container.TabItem{Text: "Test1", Content: widget.NewLabel("Text1")} item2 := &container.TabItem{Text: "Test2", Content: widget.NewLabel("Text2")} @@ -60,8 +58,7 @@ func TestDocTabs_ChangeItemContent(t *testing.T) { } func TestDocTabs_ChangeItemIcon(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) item1 := &container.TabItem{Icon: theme.CancelIcon(), Content: widget.NewLabel("Text1")} item2 := &container.TabItem{Icon: theme.ConfirmIcon(), Content: widget.NewLabel("Text2")} @@ -84,8 +81,7 @@ func TestDocTabs_ChangeItemIcon(t *testing.T) { } func TestDocTabs_ChangeItemText(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) item1 := &container.TabItem{Text: "Test1", Content: widget.NewLabel("Text1")} item2 := &container.TabItem{Text: "Test2", Content: widget.NewLabel("Text2")} @@ -108,8 +104,7 @@ func TestDocTabs_ChangeItemText(t *testing.T) { } func TestDocTabs_DynamicTabs(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) item1 := &container.TabItem{Text: "Test1", Content: widget.NewLabel("Text 1")} tabs := container.NewDocTabs(item1) @@ -160,8 +155,7 @@ func TestDocTabs_DynamicTabs(t *testing.T) { } func TestDocTabs_HoverButtons(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) test.ApplyTheme(t, internalTest.LightTheme(theme.DefaultTheme())) item1 := &container.TabItem{Text: "Test1", Content: widget.NewLabel("Text1")} @@ -195,8 +189,7 @@ func TestDocTabs_HoverButtons(t *testing.T) { } func TestDocTabs_Layout(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) w := test.NewWindow(nil) defer w.Close() @@ -296,8 +289,7 @@ func TestDocTabs_Layout(t *testing.T) { } func TestDocTabs_SetTabLocation(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) item1 := &container.TabItem{Text: "Test1", Content: widget.NewLabel("Text 1")} item2 := &container.TabItem{Text: "Test2", Content: widget.NewLabel("Text 2")} @@ -329,8 +321,7 @@ func TestDocTabs_SetTabLocation(t *testing.T) { } func TestDocTabs_Tapped(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) item1 := &container.TabItem{Text: "Test1", Content: widget.NewLabel("Text 1")} item2 := &container.TabItem{Text: "Test2", Content: widget.NewLabel("Text 2")} diff --git a/container/tabs_test.go b/container/tabs_test.go index f50e78336a..87647193c8 100644 --- a/container/tabs_test.go +++ b/container/tabs_test.go @@ -26,8 +26,7 @@ func TestTabButton_Icon_Change(t *testing.T) { } func TestTab_ThemeChange(t *testing.T) { - a := test.NewApp() - defer test.NewApp() + a := test.NewTempApp(t) a.Settings().SetTheme(internalTest.LightTheme(theme.DefaultTheme())) tabs := NewAppTabs( diff --git a/dialog/color_button_test.go b/dialog/color_button_test.go index 741d9124f8..bb7e240922 100644 --- a/dialog/color_button_test.go +++ b/dialog/color_button_test.go @@ -11,8 +11,7 @@ import ( ) func Test_colorButton_Layout(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) for name, tt := range map[string]struct { color color.Color diff --git a/dialog/color_channel_test.go b/dialog/color_channel_test.go index 9bca175afd..053d871e48 100644 --- a/dialog/color_channel_test.go +++ b/dialog/color_channel_test.go @@ -8,8 +8,7 @@ import ( ) func Test_colorChannel_Layout(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) min := 0 max := 100 diff --git a/dialog/color_picker_test.go b/dialog/color_picker_test.go index c146c900dc..f475f1ad15 100644 --- a/dialog/color_picker_test.go +++ b/dialog/color_picker_test.go @@ -10,8 +10,7 @@ import ( ) func Test_colorGreyscalePicker_Layout(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) color := newColorGreyscalePicker(nil) @@ -24,8 +23,7 @@ func Test_colorGreyscalePicker_Layout(t *testing.T) { } func Test_colorBasicPicker_Layout(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) color := newColorBasicPicker(nil) @@ -38,8 +36,7 @@ func Test_colorBasicPicker_Layout(t *testing.T) { } func Test_colorRecentPicker_Layout(t *testing.T) { - a := test.NewApp() - defer test.NewApp() + a := test.NewTempApp(t) // Inject recent preferences a.Preferences().SetString("color_recents", "#0000FF,#008000,#FF0000") @@ -55,8 +52,7 @@ func Test_colorRecentPicker_Layout(t *testing.T) { } func Test_colorAdvancedPicker_Layout(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) color := newColorAdvancedPicker(theme.PrimaryColor(), nil) diff --git a/dialog/color_preview_test.go b/dialog/color_preview_test.go index 538679ff1f..a9bb5a13d4 100644 --- a/dialog/color_preview_test.go +++ b/dialog/color_preview_test.go @@ -10,8 +10,7 @@ import ( ) func Test_colorPreview_Color(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) preview := newColorPreview(color.RGBA{53, 113, 233, 255}) preview.SetColor(color.RGBA{90, 206, 80, 180}) diff --git a/dialog/color_test.go b/dialog/color_test.go index 311132f2de..820aba89a0 100644 --- a/dialog/color_test.go +++ b/dialog/color_test.go @@ -13,8 +13,7 @@ import ( ) func TestColorDialog_Theme(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) w := test.NewWindow(canvas.NewRectangle(color.Transparent)) w.Resize(fyne.NewSize(1000, 800)) @@ -41,9 +40,7 @@ func TestColorDialog_Theme(t *testing.T) { } func TestColorDialog_Recents(t *testing.T) { - a := test.NewApp() - defer test.NewApp() - + a := test.NewTempApp(t) // Inject recent preferences a.Preferences().SetString("color_recents", "#2196f3,#4caf50,#f44336") @@ -102,8 +99,7 @@ func TestColorDialog_SetColor(t *testing.T) { } func TestColorDialogSimple_Theme(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) w := test.NewWindow(canvas.NewRectangle(color.Transparent)) w.Resize(fyne.NewSize(600, 400)) @@ -120,8 +116,7 @@ func TestColorDialogSimple_Theme(t *testing.T) { } func TestColorDialogSimple_Recents(t *testing.T) { - a := test.NewApp() - defer test.NewApp() + a := test.NewTempApp(t) // Inject recent preferences a.Preferences().SetString("color_recents", "#2196f3,#4caf50,#f44336") @@ -142,22 +137,19 @@ func TestColorDialogSimple_Recents(t *testing.T) { func Test_recent_color(t *testing.T) { t.Run("Empty", func(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) colors := readRecentColors() assert.Equal(t, 0, len(colors)) }) t.Run("Single", func(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) writeRecentColor("#ff0000") // Red colors := readRecentColors() assert.Equal(t, 1, len(colors)) assert.Equal(t, "#ff0000", colors[0]) }) t.Run("Order", func(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) // Recents are last in, first out writeRecentColor("#ff0000") // Red writeRecentColor("#00ff00") // Green @@ -169,8 +161,7 @@ func Test_recent_color(t *testing.T) { assert.Equal(t, "#ff0000", colors[2]) }) t.Run("Deduplicate", func(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) // Ensure no duplicates writeRecentColor("#ff0000") // Red writeRecentColor("#00ff00") // Green @@ -183,8 +174,7 @@ func Test_recent_color(t *testing.T) { assert.Equal(t, "#00ff00", colors[2]) // Green }) t.Run("Limit", func(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) // Max recents is 7 writeRecentColor("#000000") // Black writeRecentColor("#bbbbbb") // Dark Grey diff --git a/dialog/color_wheel_test.go b/dialog/color_wheel_test.go index 39d85036b5..481c096d1c 100644 --- a/dialog/color_wheel_test.go +++ b/dialog/color_wheel_test.go @@ -8,8 +8,7 @@ import ( ) func Test_colorWheel_Layout(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) wheel := newColorWheel(nil) wheel.SetHSLA(180, 100, 50, 255) diff --git a/dialog/confirm_test.go b/dialog/confirm_test.go index fba7ab22c6..45a32fb745 100644 --- a/dialog/confirm_test.go +++ b/dialog/confirm_test.go @@ -107,8 +107,7 @@ func TestConfirmDialog_Resize(t *testing.T) { } func TestConfirm_Importance(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) w := test.NewWindow(canvas.NewRectangle(color.Transparent)) size := fyne.NewSize(200, 300) w.Resize(size) diff --git a/dialog/custom_test.go b/dialog/custom_test.go index d94b016a63..51069e0890 100644 --- a/dialog/custom_test.go +++ b/dialog/custom_test.go @@ -14,8 +14,7 @@ import ( ) func TestShowCustom_ApplyTheme(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) w := test.NewWindow(canvas.NewRectangle(color.Transparent)) @@ -50,8 +49,7 @@ func TestShowCustom_Resize(t *testing.T) { } func TestCustom_ApplyThemeOnShow(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) w := test.NewWindow(canvas.NewRectangle(color.Transparent)) w.Resize(fyne.NewSize(200, 300)) @@ -76,8 +74,7 @@ func TestCustom_ApplyThemeOnShow(t *testing.T) { } func TestCustom_ResizeOnShow(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) w := test.NewWindow(canvas.NewRectangle(color.Transparent)) size := fyne.NewSize(200, 300) w.Resize(size) @@ -98,8 +95,7 @@ func TestCustom_ResizeOnShow(t *testing.T) { } func TestConfirm_SetButtons(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) w := test.NewWindow(canvas.NewRectangle(color.Transparent)) size := fyne.NewSize(200, 300) w.Resize(size) @@ -121,8 +117,7 @@ func TestConfirm_SetButtons(t *testing.T) { } func TestConfirmWithoutButtons(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) w := test.NewWindow(canvas.NewRectangle(color.Transparent)) size := fyne.NewSize(200, 300) w.Resize(size) @@ -134,8 +129,7 @@ func TestConfirmWithoutButtons(t *testing.T) { } func TestCustomConfirm_Importance(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) w := test.NewWindow(canvas.NewRectangle(color.Transparent)) size := fyne.NewSize(200, 300) w.Resize(size) diff --git a/dialog/form_test.go b/dialog/form_test.go index 5c7074319f..69f17f37f2 100644 --- a/dialog/form_test.go +++ b/dialog/form_test.go @@ -87,8 +87,7 @@ func TestFormDialog_CanCancelNoValidation(t *testing.T) { func TestFormDialog_Hints(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) test.ApplyTheme(t, internalTest.LightTheme(theme.DefaultTheme())) w := test.NewWindow(nil) w.SetFullScreen(true) diff --git a/internal/driver/common/canvas_test.go b/internal/driver/common/canvas_test.go index b43fbd0e5e..e9398c56fb 100644 --- a/internal/driver/common/canvas_test.go +++ b/internal/driver/common/canvas_test.go @@ -15,8 +15,7 @@ import ( ) func TestCanvas_walkTree(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) leftObj1 := canvas.NewRectangle(color.Gray16{Y: 1}) leftObj2 := canvas.NewRectangle(color.Gray16{Y: 2}) diff --git a/internal/driver/glfw/menu_bar_test.go b/internal/driver/glfw/menu_bar_test.go index 64b3729fa0..e897369d42 100644 --- a/internal/driver/glfw/menu_bar_test.go +++ b/internal/driver/glfw/menu_bar_test.go @@ -17,8 +17,7 @@ import ( ) func TestMenuBar(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) var lastAction string @@ -450,8 +449,7 @@ func TestMenuBar(t *testing.T) { } func TestMenuBar_Toggle(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) m1i1 := fyne.NewMenuItem("New", nil) m1i2 := fyne.NewMenuItem("Open", nil) diff --git a/internal/painter/image_test.go b/internal/painter/image_test.go index 14c1efb2ba..2272e090ec 100644 --- a/internal/painter/image_test.go +++ b/internal/painter/image_test.go @@ -39,8 +39,7 @@ func TestPaintImageWithBadSVGElement(t *testing.T) { } func TestPaintImage_SVG(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) for name, tt := range map[string]struct { width float32 diff --git a/internal/widget/shadow_test.go b/internal/widget/shadow_test.go index e27e7cbafc..0b1abdbc0c 100644 --- a/internal/widget/shadow_test.go +++ b/internal/widget/shadow_test.go @@ -13,8 +13,7 @@ import ( var shadowLevel = widget.ElevationLevel(5) func TestShadow_ApplyTheme(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) s := widget.NewShadow(widget.ShadowAround, shadowLevel) w := test.NewWindow(s) @@ -30,8 +29,7 @@ func TestShadow_ApplyTheme(t *testing.T) { } func TestShadow_AroundShadow(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) s := widget.NewShadow(widget.ShadowAround, shadowLevel) w := test.NewWindow(s) @@ -44,8 +42,7 @@ func TestShadow_AroundShadow(t *testing.T) { } func TestShadow_Transparency(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) s := widget.NewShadow(widget.ShadowAround, shadowLevel) w := test.NewWindow(s) @@ -62,8 +59,7 @@ func TestShadow_Transparency(t *testing.T) { } func TestShadow_BottomShadow(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) s := widget.NewShadow(widget.ShadowBottom, shadowLevel) w := test.NewWindow(s) @@ -80,8 +76,7 @@ func TestShadow_MinSize(t *testing.T) { } func TestShadow_TopShadow(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) s := widget.NewShadow(widget.ShadowTop, shadowLevel) w := test.NewWindow(s) diff --git a/test/testapp.go b/test/testapp.go index 6c54eee35d..bd89e0dd8b 100644 --- a/test/testapp.go +++ b/test/testapp.go @@ -4,6 +4,7 @@ package test // import "fyne.io/fyne/v2/test" import ( "net/url" "sync" + "testing" "fyne.io/fyne/v2" "fyne.io/fyne/v2/internal" @@ -146,6 +147,15 @@ func (a *testApp) transitionCloud(p fyne.CloudProvider) { a.settings.apply() } +// NewTempApp returns a new dummy app and tears it down at the end of the test. +// +// Since: 2.5 +func NewTempApp(t testing.TB) fyne.App { + app := NewApp() + t.Cleanup(func() { NewApp() }) + return app +} + // NewApp returns a new dummy app used for testing. // It loads a test driver which creates a virtual window in memory for testing. func NewApp() fyne.App { diff --git a/widget/accordion_test.go b/widget/accordion_test.go index 68704071c3..fee7cec1aa 100644 --- a/widget/accordion_test.go +++ b/widget/accordion_test.go @@ -32,8 +32,7 @@ func TestAccordion_Append(t *testing.T) { } func TestAccordion_ChangeTheme(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) ac := widget.NewAccordion() ac.Append(widget.NewAccordionItem("foo0", widget.NewLabel("foobar0"))) diff --git a/widget/activity_internal_test.go b/widget/activity_internal_test.go index 13372186da..1d5a90195a 100644 --- a/widget/activity_internal_test.go +++ b/widget/activity_internal_test.go @@ -7,8 +7,7 @@ import ( ) func TestActivity_Animation(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) test.ApplyTheme(t, test.NewTheme()) a := NewActivity() diff --git a/widget/activity_test.go b/widget/activity_test.go index a758af384f..a0d94bf254 100644 --- a/widget/activity_test.go +++ b/widget/activity_test.go @@ -10,8 +10,7 @@ import ( ) func TestActivity_Start(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) test.ApplyTheme(t, test.NewTheme()) a := NewActivity() @@ -29,8 +28,7 @@ func TestActivity_Start(t *testing.T) { } func TestActivity_Stop(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) test.ApplyTheme(t, test.NewTheme()) a := NewActivity() diff --git a/widget/button_internal_test.go b/widget/button_internal_test.go index 72c401aa81..b70a9de3d6 100644 --- a/widget/button_internal_test.go +++ b/widget/button_internal_test.go @@ -210,8 +210,7 @@ func TestButtonRenderer_ApplyTheme(t *testing.T) { } func TestButtonRenderer_TapAnimation(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) test.ApplyTheme(t, test.NewTheme()) button := NewButton("Hi", func() {}) diff --git a/widget/button_test.go b/widget/button_test.go index c13b2a841f..7f2765466e 100644 --- a/widget/button_test.go +++ b/widget/button_test.go @@ -66,8 +66,7 @@ func TestButton_Tapped(t *testing.T) { } func TestButton_Disable(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) test.ApplyTheme(t, internalTest.LightTheme(theme.DefaultTheme())) tapped := false @@ -123,8 +122,7 @@ func TestButton_Disabled(t *testing.T) { } func TestButton_LowImportance(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) b := &widget.Button{Text: "Text", Icon: theme.HomeIcon(), Importance: widget.LowImportance} w := test.NewWindow(b) @@ -137,8 +135,7 @@ func TestButton_LowImportance(t *testing.T) { } func TestButton_Hover(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) test.ApplyTheme(t, internalTest.LightTheme(theme.DefaultTheme())) b := widget.NewButtonWithIcon("Test", theme.HomeIcon(), func() {}) @@ -166,8 +163,7 @@ func TestButton_Hover(t *testing.T) { } func TestButton_Layout(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) for name, tt := range map[string]struct { text string @@ -294,8 +290,7 @@ func TestButton_Layout(t *testing.T) { } func TestButton_ChangeTheme(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) b := widget.NewButton("Test", func() {}) w := test.NewWindow(b) @@ -323,8 +318,7 @@ func TestButtonCompatImportance(t *testing.T) { } func TestButtonSuccess(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) test.ApplyTheme(t, internalTest.LightTheme(theme.DefaultTheme())) b := widget.NewButtonWithIcon("Test", theme.HomeIcon(), func() {}) diff --git a/widget/check_test.go b/widget/check_test.go index 6b4210e926..38351fb688 100644 --- a/widget/check_test.go +++ b/widget/check_test.go @@ -38,8 +38,7 @@ func TestCheck_Binding(t *testing.T) { } func TestCheck_Layout(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) for name, tt := range map[string]struct { text string diff --git a/widget/entry_password_extend_test.go b/widget/entry_password_extend_test.go index 71f4011413..9173e5c382 100644 --- a/widget/entry_password_extend_test.go +++ b/widget/entry_password_extend_test.go @@ -15,8 +15,7 @@ type extendEntry struct { } func TestEntry_Password_Extended_CreateRenderer(t *testing.T) { - a := test.NewApp() - defer test.NewApp() + a := test.NewTempApp(t) w := a.NewWindow("") entry := &extendEntry{} entry.ExtendBaseWidget(entry) diff --git a/widget/entry_test.go b/widget/entry_test.go index 588ee00bfe..00072e52db 100644 --- a/widget/entry_test.go +++ b/widget/entry_test.go @@ -1869,8 +1869,7 @@ func TestPasswordEntry_Placeholder(t *testing.T) { } func TestPasswordEntry_Reveal(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) t.Run("NewPasswordEntry constructor", func(t *testing.T) { entry := widget.NewPasswordEntry() diff --git a/widget/entry_validation_test.go b/widget/entry_validation_test.go index b8f4aa1509..2d0642e221 100644 --- a/widget/entry_validation_test.go +++ b/widget/entry_validation_test.go @@ -64,8 +64,7 @@ func TestEntry_Validate(t *testing.T) { } func TestEntry_NotEmptyValidator(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) entry := widget.NewEntry() entry.Validator = func(s string) error { if s == "" { diff --git a/widget/fileicon_test.go b/widget/fileicon_test.go index a655e39e41..5397398e67 100644 --- a/widget/fileicon_test.go +++ b/widget/fileicon_test.go @@ -16,8 +16,7 @@ import ( ) func TestFileIcon_NewFileIcon_Rendered(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) workingDir, err := os.Getwd() if err != nil { diff --git a/widget/form_test.go b/widget/form_test.go index efa32a0e07..d8aaac88ee 100644 --- a/widget/form_test.go +++ b/widget/form_test.go @@ -98,8 +98,7 @@ func TestForm_AddRemoveButton(t *testing.T) { } func TestForm_Renderer(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) form := &Form{ Items: []*FormItem{ @@ -127,8 +126,7 @@ func TestForm_ChangeText(t *testing.T) { } func TestForm_ChangeTheme(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) form := &Form{ Items: []*FormItem{ @@ -149,8 +147,7 @@ func TestForm_ChangeTheme(t *testing.T) { } func TestForm_Disabled(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) test.ApplyTheme(t, internalTest.LightTheme(theme.DefaultTheme())) disabled := NewEntry() @@ -166,8 +163,7 @@ func TestForm_Disabled(t *testing.T) { } func TestForm_Hints(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) test.ApplyTheme(t, internalTest.LightTheme(theme.DefaultTheme())) entry1 := &Entry{} @@ -191,8 +187,7 @@ func TestForm_Hints(t *testing.T) { } func TestForm_Validation(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) test.ApplyTheme(t, internalTest.LightTheme(theme.DefaultTheme())) entry1 := &Entry{Validator: validation.NewRegexp(`^\d{2}-\w{4}$`, "Input is not valid"), Text: "15-true"} @@ -223,8 +218,7 @@ func TestForm_Validation(t *testing.T) { } func TestForm_EntryValidation_FirstTypeValid(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) test.ApplyTheme(t, internalTest.LightTheme(theme.DefaultTheme())) notEmptyValidator := func(s string) error { @@ -263,8 +257,7 @@ func TestForm_EntryValidation_FirstTypeValid(t *testing.T) { } func TestForm_DisableEnable(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) test.ApplyTheme(t, internalTest.LightTheme(theme.DefaultTheme())) form := &Form{ @@ -299,8 +292,7 @@ func TestForm_DisableEnable(t *testing.T) { } func TestForm_Disable_Validation(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) test.ApplyTheme(t, internalTest.LightTheme(theme.DefaultTheme())) entry := &Entry{Validator: validation.NewRegexp(`^\d{2}-\w{4}$`, "Input is not valid"), Text: "wrong"} @@ -331,8 +323,7 @@ func TestForm_Disable_Validation(t *testing.T) { } func TestForm_HintsRendered(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) test.ApplyTheme(t, internalTest.LightTheme(theme.DefaultTheme())) f := NewForm() @@ -421,8 +412,7 @@ func TestForm_SetOnValidationChanged(t *testing.T) { func TestForm_ExtendedEntry(t *testing.T) { extendedEntry := NewSelectEntry([]string{""}) - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) form := &Form{ Items: []*FormItem{ diff --git a/widget/gridwrap_test.go b/widget/gridwrap_test.go index 29dd28f060..91da46ccef 100644 --- a/widget/gridwrap_test.go +++ b/widget/gridwrap_test.go @@ -10,7 +10,7 @@ import ( ) func TestGridWrap_Focus(t *testing.T) { - defer test.NewApp() + test.NewTempApp(t) list := createGridWrap(100) window := test.NewWindow(list) defer window.Close() diff --git a/widget/hyperlink_test.go b/widget/hyperlink_test.go index 03bbe7048d..9fd083ad4a 100644 --- a/widget/hyperlink_test.go +++ b/widget/hyperlink_test.go @@ -73,8 +73,7 @@ func TestHyperlink_Hide(t *testing.T) { } func TestHyperlink_Focus(t *testing.T) { - app := test.NewApp() - defer test.NewApp() + app := test.NewTempApp(t) app.Settings().SetTheme(internalTest.LightTheme(theme.DefaultTheme())) hyperlink := &Hyperlink{Text: "Test"} @@ -167,8 +166,7 @@ func TestHyperlink_SetUrl(t *testing.T) { } func TestHyperlink_ThemeOverride(t *testing.T) { - _ = test.NewApp() - defer test.NewApp() + test.NewTempApp(t) test.ApplyTheme(t, internalTest.LightTheme(theme.DefaultTheme())) hyperlink := &Hyperlink{Text: "Test"} diff --git a/widget/icon_test.go b/widget/icon_test.go index b4c369326d..5d12ce3f14 100644 --- a/widget/icon_test.go +++ b/widget/icon_test.go @@ -11,8 +11,7 @@ import ( ) func TestIcon_Layout(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) for name, tt := range map[string]struct { resource fyne.Resource diff --git a/widget/label_test.go b/widget/label_test.go index d359683d96..e09e110605 100644 --- a/widget/label_test.go +++ b/widget/label_test.go @@ -183,8 +183,7 @@ func TestLabel_CreateRendererDoesNotAffectSize(t *testing.T) { } func TestLabel_ChangeTruncate(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) c := test.NewCanvasWithPainter(software.NewPainter()) c.SetPadded(false) @@ -210,8 +209,7 @@ func TestNewLabelWithData(t *testing.T) { } func TestLabelImportance(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) test.ApplyTheme(t, internalTest.LightTheme(theme.DefaultTheme())) lbl := NewLabel("hello, fyne") diff --git a/widget/list_test.go b/widget/list_test.go index 74f2019ece..2d339dbf09 100644 --- a/widget/list_test.go +++ b/widget/list_test.go @@ -84,7 +84,7 @@ func TestList_MinSize(t *testing.T) { } func TestList_Resize(t *testing.T) { - defer test.NewApp() + test.NewTempApp(t) list, w := setupList(t) assert.Equal(t, float32(0), list.offsetY) @@ -157,8 +157,7 @@ func TestList_SetItemHeight_InUpdate(t *testing.T) { } func TestList_OffsetChange(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) list := createList(1000) w := test.NewWindow(list) @@ -345,8 +344,7 @@ func TestList_Unselect(t *testing.T) { } func TestList_DataChange(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) list, w := setupList(t) children := list.scroller.Content.(*fyne.Container).Layout.(*listLayout).children @@ -360,8 +358,7 @@ func TestList_DataChange(t *testing.T) { } func TestList_ItemDataChange(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) list, _ := setupList(t) children := list.scroller.Content.(*fyne.Container).Layout.(*listLayout).children @@ -373,7 +370,7 @@ func TestList_ItemDataChange(t *testing.T) { } func TestList_ThemeChange(t *testing.T) { - defer test.NewApp() + test.NewTempApp(t) list, w := setupList(t) test.AssertImageMatches(t, "list/list_initial.png", w.Canvas().Capture()) @@ -386,8 +383,7 @@ func TestList_ThemeChange(t *testing.T) { } func TestList_SmallList(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) var data []string data = append(data, "Test Item 0") @@ -422,7 +418,7 @@ func TestList_SmallList(t *testing.T) { } func TestList_ClearList(t *testing.T) { - defer test.NewApp() + test.NewTempApp(t) list, w := setupList(t) assert.Equal(t, 1000, list.Length()) @@ -438,8 +434,7 @@ func TestList_ClearList(t *testing.T) { } func TestList_RemoveItem(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) data := []string{"Test Item 0", "Test Item 1", "Test Item 2"} @@ -472,8 +467,7 @@ func TestList_RemoveItem(t *testing.T) { } func TestList_ScrollThenShrink(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) data := make([]string, 0, 20) for i := 0; i < 20; i++ { @@ -512,8 +506,7 @@ func TestList_ScrollThenShrink(t *testing.T) { } func TestList_ScrollThenResizeWindow(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) data := make([]string, 0, 20) for i := 0; i < 20; i++ { @@ -553,7 +546,7 @@ func TestList_NoFunctionsSet(t *testing.T) { } func TestList_Focus(t *testing.T) { - defer test.NewApp() + test.NewTempApp(t) list := createList(10) window := test.NewWindow(list) defer window.Close() diff --git a/widget/menu_desktop_test.go b/widget/menu_desktop_test.go index 4d4f5743a2..abecb879fc 100644 --- a/widget/menu_desktop_test.go +++ b/widget/menu_desktop_test.go @@ -20,8 +20,7 @@ import ( ) func TestMenu_Layout(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) w := test.NewWindow(canvas.NewRectangle(color.Transparent)) defer w.Close() @@ -198,8 +197,7 @@ func TestMenu_Layout(t *testing.T) { } func TestMenu_Scrolling(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) w := test.NewWindow(canvas.NewRectangle(color.Transparent)) defer w.Close() @@ -239,8 +237,7 @@ func TestMenu_Scrolling(t *testing.T) { } func TestMenu_TraverseMenu(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) w := fyne.CurrentApp().NewWindow("") defer w.Close() diff --git a/widget/menu_mobile_test.go b/widget/menu_mobile_test.go index 9c81ed0381..cbaa8f91c6 100644 --- a/widget/menu_mobile_test.go +++ b/widget/menu_mobile_test.go @@ -15,8 +15,7 @@ import ( ) func TestMenu_Layout(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) w := test.NewWindow(canvas.NewRectangle(color.Transparent)) defer w.Close() @@ -135,8 +134,7 @@ func TestMenu_Layout(t *testing.T) { } func TestMenu_Dragging(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) w := test.NewWindow(canvas.NewRectangle(color.Transparent)) defer w.Close() diff --git a/widget/menu_test.go b/widget/menu_test.go index ab8be3979d..13bf6bcab7 100644 --- a/widget/menu_test.go +++ b/widget/menu_test.go @@ -13,8 +13,7 @@ import ( ) func TestMenu_RefreshOptions(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) w := fyne.CurrentApp().NewWindow("") defer w.Close() @@ -65,8 +64,7 @@ func TestMenu_RefreshOptions(t *testing.T) { } func TestMenu_TappedPaddingOrSeparator(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) w := fyne.CurrentApp().NewWindow("") defer w.Close() diff --git a/widget/popup_test.go b/widget/popup_test.go index 8a955ec236..a7277c28c5 100644 --- a/widget/popup_test.go +++ b/widget/popup_test.go @@ -30,8 +30,7 @@ func TestNewPopUp(t *testing.T) { } func TestShowPopUp(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) w := test.NewWindow(canvas.NewRectangle(color.Transparent)) w.Resize(fyne.NewSize(200, 200)) @@ -83,8 +82,7 @@ func TestShowPopUpAtRelativePosition(t *testing.T) { } func TestShowModalPopUp(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) w := test.NewWindow(canvas.NewRectangle(color.Transparent)) w.Resize(fyne.NewSize(200, 199)) @@ -326,8 +324,7 @@ func TestPopUp_Layout(t *testing.T) { } func TestPopUp_ApplyThemeOnShow(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) w := test.NewWindow(canvas.NewRectangle(color.Transparent)) w.Resize(fyne.NewSize(200, 300)) @@ -350,8 +347,7 @@ func TestPopUp_ApplyThemeOnShow(t *testing.T) { } func TestPopUp_ResizeOnShow(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) w := test.NewWindow(canvas.NewRectangle(color.Transparent)) size := fyne.NewSize(200, 300) w.Resize(size) @@ -370,8 +366,7 @@ func TestPopUp_ResizeOnShow(t *testing.T) { } func TestPopUp_ResizeBeforeShow_CanvasSizeZero(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) // Simulate canvas size {0,0} rect := canvas.NewRectangle(color.Black) @@ -455,8 +450,7 @@ func TestModalPopUp_Resize_Constrained(t *testing.T) { } func TestModalPopUp_ApplyThemeOnShow(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) w := test.NewWindow(canvas.NewRectangle(color.Transparent)) w.Resize(fyne.NewSize(200, 300)) @@ -479,8 +473,7 @@ func TestModalPopUp_ApplyThemeOnShow(t *testing.T) { } func TestModalPopUp_ResizeOnShow(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) w := test.NewWindow(canvas.NewRectangle(color.Transparent)) size := fyne.NewSize(200, 300) w.Resize(size) @@ -499,8 +492,7 @@ func TestModalPopUp_ResizeOnShow(t *testing.T) { } func TestModelPopUp_ResizeBeforeShow_CanvasSizeZero(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) // Simulate canvas size {0,0} rect := canvas.NewRectangle(color.Black) diff --git a/widget/select_entry_internal_test.go b/widget/select_entry_internal_test.go index 0a14466d41..fac8c3e3db 100644 --- a/widget/select_entry_internal_test.go +++ b/widget/select_entry_internal_test.go @@ -11,8 +11,7 @@ import ( ) func TestSelectEntry_Disableable(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) options := []string{"A", "B", "C"} e := NewSelectEntry(options) @@ -49,8 +48,7 @@ func TestSelectEntry_Disableable(t *testing.T) { } func TestSelectEntry_DropDown(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) options := []string{"A", "B", "C"} e := NewSelectEntry(options) @@ -81,8 +79,7 @@ func TestSelectEntry_DropDown(t *testing.T) { } func TestSelectEntry_DropDownMove(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) e := NewSelectEntry([]string{"one"}) w := test.NewWindow(e) @@ -112,8 +109,7 @@ func TestSelectEntry_DropDownMove(t *testing.T) { } func TestSelectEntry_DropDownResize(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) options := []string{"A", "B", "C"} e := NewSelectEntry(options) @@ -181,8 +177,7 @@ func TestSelectEntry_MinSize(t *testing.T) { } func TestSelectEntry_SetOptions(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) e := NewSelectEntry([]string{"A", "B", "C"}) w := test.NewWindow(e) @@ -203,8 +198,7 @@ func TestSelectEntry_SetOptions(t *testing.T) { } func TestSelectEntry_SetOptions_Empty(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) e := NewSelectEntry([]string{}) w := test.NewWindow(e) diff --git a/widget/select_internal_test.go b/widget/select_internal_test.go index 218352b284..1a63fb687a 100644 --- a/widget/select_internal_test.go +++ b/widget/select_internal_test.go @@ -36,8 +36,7 @@ func TestSelect_SetOptions(t *testing.T) { } func TestSelectRenderer_TapAnimation(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) test.ApplyTheme(t, test.NewTheme()) sel := NewSelect([]string{"one"}, func(s string) {}) diff --git a/widget/select_test.go b/widget/select_test.go index 3bf972628f..2410cc717a 100644 --- a/widget/select_test.go +++ b/widget/select_test.go @@ -26,8 +26,7 @@ func TestNewSelect(t *testing.T) { } func TestSelect_Align(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) sel := widget.NewSelect([]string{"Hi"}, func(string) {}) sel.Alignment = fyne.TextAlignCenter @@ -45,8 +44,7 @@ func TestSelect_Align(t *testing.T) { } func TestSelect_ChangeTheme(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) combo := widget.NewSelect([]string{"1", "2"}, func(s string) {}) w := test.NewWindow(combo) @@ -106,8 +104,7 @@ func TestSelect_ClipValue(t *testing.T) { } func TestSelect_Disable(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) sel := widget.NewSelect([]string{"Hi"}, func(string) {}) w := test.NewWindow(&fyne.Container{Layout: layout.NewCenterLayout(), Objects: []fyne.CanvasObject{sel}}) @@ -150,8 +147,7 @@ func TestSelect_Enable(t *testing.T) { } func TestSelect_FocusRendering(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) t.Run("gain/lose focus", func(t *testing.T) { sel := widget.NewSelect([]string{"Option A", "Option B", "Option C"}, nil) @@ -191,8 +187,7 @@ func TestSelect_FocusRendering(t *testing.T) { } func TestSelect_KeyboardControl(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) t.Run("activate pop-up", func(t *testing.T) { sel := widget.NewSelect([]string{"Option A", "Option B"}, nil) @@ -284,8 +279,7 @@ func TestSelect_KeyboardControl(t *testing.T) { } func TestSelect_Move(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) combo := widget.NewSelect([]string{"1", "2"}, nil) w := test.NewWindow(combo) @@ -324,8 +318,7 @@ func TestSelect_SelectedIndex(t *testing.T) { } func TestSelect_SetSelected(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) var triggered bool var triggeredValue string @@ -417,8 +410,7 @@ func TestSelect_SetSelectedIndex_Invalid(t *testing.T) { } func TestSelect_Tapped(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) combo := widget.NewSelect([]string{"1", "2"}, func(s string) {}) w := test.NewWindow(combo) @@ -433,8 +425,7 @@ func TestSelect_Tapped(t *testing.T) { } func TestSelect_Tapped_Constrained(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) combo := widget.NewSelect([]string{"1", "2"}, func(s string) {}) w := test.NewWindow(combo) @@ -450,8 +441,7 @@ func TestSelect_Tapped_Constrained(t *testing.T) { } func TestSelect_Layout(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) for name, tt := range map[string]struct { placeholder string diff --git a/widget/slider_test.go b/widget/slider_test.go index 8521ebed30..9f504d577f 100644 --- a/widget/slider_test.go +++ b/widget/slider_test.go @@ -68,8 +68,7 @@ func TestSlider_Clamp(t *testing.T) { } func TestSlider_HorizontalLayout(t *testing.T) { - app := test.NewApp() - defer test.NewApp() + app := test.NewTempApp(t) app.Settings().SetTheme(internalTest.LightTheme(theme.DefaultTheme())) slider := NewSlider(0, 1) @@ -110,8 +109,7 @@ func TestSlider_OutOfRange(t *testing.T) { } func TestSlider_VerticalLayout(t *testing.T) { - app := test.NewApp() - defer test.NewApp() + app := test.NewTempApp(t) app.Settings().SetTheme(internalTest.LightTheme(theme.DefaultTheme())) slider := NewSlider(0, 1) diff --git a/widget/table_desktop_test.go b/widget/table_desktop_test.go index e06990b227..77ca292c61 100644 --- a/widget/table_desktop_test.go +++ b/widget/table_desktop_test.go @@ -13,8 +13,7 @@ import ( ) func TestTable_Hovered(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) table := NewTable( func() (int, int) { return 2, 2 }, diff --git a/widget/table_test.go b/widget/table_test.go index b634f532a8..07066067e5 100644 --- a/widget/table_test.go +++ b/widget/table_test.go @@ -54,8 +54,7 @@ func TestTable_Cache(t *testing.T) { } func TestTable_ChangeTheme(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) table := NewTable( func() (int, int) { return 3, 5 }, @@ -85,8 +84,7 @@ func TestTable_ChangeTheme(t *testing.T) { } func TestTable_Filled(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) test.ApplyTheme(t, internalTest.LightTheme(theme.DefaultTheme())) table := NewTable( @@ -107,7 +105,7 @@ func TestTable_Filled(t *testing.T) { } func TestTable_Focus(t *testing.T) { - defer test.NewApp() + test.NewTempApp(t) table := NewTable( func() (int, int) { return 5, 5 }, @@ -168,8 +166,7 @@ func TestTable_Headers(t *testing.T) { func TestTable_JustHeaders(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) table := NewTableWithHeaders( func() (int, int) { return 0, 9 }, @@ -321,8 +318,7 @@ func TestTable_Resize(t *testing.T) { } func TestTable_Unselect(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) table := NewTable( func() (int, int) { return 3, 5 }, @@ -385,8 +381,7 @@ func TestTable_Refresh(t *testing.T) { } func TestTable_ScrollTo(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) // for this test the separator thickness is 0 test.ApplyTheme(t, &paddingZeroTheme{test.Theme()}) @@ -482,8 +477,7 @@ func TestTable_ScrollTo(t *testing.T) { } func TestTable_ScrollToBottom(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) test.ApplyTheme(t, test.NewTheme()) const ( @@ -517,8 +511,7 @@ func TestTable_ScrollToBottom(t *testing.T) { } func TestTable_ScrollToLeading(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) table := NewTable( func() (int, int) { return 3, 5 }, @@ -543,8 +536,7 @@ func TestTable_ScrollToLeading(t *testing.T) { } func TestTable_ScrollToTop(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) const ( maxRows int = 6 @@ -575,8 +567,7 @@ func TestTable_ScrollToTop(t *testing.T) { } func TestTable_ScrollToTrailing(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) table := NewTable( func() (int, int) { return 24, 24 }, @@ -604,8 +595,7 @@ func TestTable_ScrollToTrailing(t *testing.T) { } func TestTable_Selection(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) table := NewTable( func() (int, int) { return 5, 5 }, @@ -648,8 +638,7 @@ func TestTable_Selection(t *testing.T) { } func TestTable_Selection_OnHeader(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) table := NewTableWithHeaders( func() (int, int) { return 5, 5 }, @@ -678,8 +667,7 @@ func TestTable_Selection_OnHeader(t *testing.T) { } func TestTable_Select(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) table := NewTable( func() (int, int) { return 5, 5 }, @@ -716,8 +704,7 @@ func TestTable_Select(t *testing.T) { } func TestTable_SetColumnWidth(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) test.ApplyTheme(t, internalTest.LightTheme(theme.DefaultTheme())) table := NewTable( @@ -796,8 +783,7 @@ func TestTable_SetColumnWidth_Dragged(t *testing.T) { } func TestTable_SetRowHeight(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) test.ApplyTheme(t, internalTest.LightTheme(theme.DefaultTheme())) table := NewTable( @@ -890,8 +876,7 @@ func TestTable_ShowVisible(t *testing.T) { } func TestTable_SeparatorThicknessZero_NotPanics(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) test.ApplyTheme(t, &paddingZeroTheme{test.Theme()}) diff --git a/widget/tree_internal_test.go b/widget/tree_internal_test.go index 2107b4c982..5d7124b216 100644 --- a/widget/tree_internal_test.go +++ b/widget/tree_internal_test.go @@ -558,8 +558,7 @@ func TestTree_Select_Unselects(t *testing.T) { } func TestTree_ScrollTo(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) test.ApplyTheme(t, test.NewTheme()) data := make(map[string][]string) @@ -593,8 +592,7 @@ func TestTree_ScrollTo(t *testing.T) { } func TestTree_ScrollToBottom(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) test.ApplyTheme(t, test.NewTheme()) data := make(map[string][]string) @@ -663,8 +661,7 @@ func TestTree_ScrollToSelection(t *testing.T) { } func TestTree_ScrollToTop(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) test.ApplyTheme(t, test.NewTheme()) data := make(map[string][]string) diff --git a/widget/tree_test.go b/widget/tree_test.go index d53b3fc5cf..cf9260adf6 100644 --- a/widget/tree_test.go +++ b/widget/tree_test.go @@ -287,8 +287,7 @@ func TestTree_Layout(t *testing.T) { } func TestTree_ChangeTheme(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) tree := widget.NewTreeWithStrings(treeData) tree.OpenBranch("foo") @@ -309,8 +308,7 @@ func TestTree_ChangeTheme(t *testing.T) { } func TestTree_Move(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) tree := widget.NewTreeWithStrings(treeData) tree.OpenBranch("foo") @@ -328,8 +326,7 @@ func TestTree_Move(t *testing.T) { } func TestTree_Refresh(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) test.ApplyTheme(t, internalTest.LightTheme(theme.DefaultTheme())) value := "Foo Leaf" diff --git a/widget/widget_test.go b/widget/widget_test.go index 780ff2ec8e..8a34b7cfe1 100644 --- a/widget/widget_test.go +++ b/widget/widget_test.go @@ -66,8 +66,7 @@ func TestApplyThemeCalledChild(t *testing.T) { } func TestSimpleRenderer(t *testing.T) { - test.NewApp() - defer test.NewApp() + test.NewTempApp(t) c := &fyne.Container{Layout: layout.NewStackLayout(), Objects: []fyne.CanvasObject{ newTestWidget(canvas.NewRectangle(color.Gray{Y: 0x79})),