diff --git a/app/icon_cache_file_test.go b/app/icon_cache_file_test.go index 165cf82294..512c16456c 100644 --- a/app/icon_cache_file_test.go +++ b/app/icon_cache_file_test.go @@ -7,6 +7,7 @@ import ( "fyne.io/fyne/v2" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) //go:embed testdata/fyne.png @@ -27,8 +28,8 @@ func TestCachedIcon_PATH(t *testing.T) { } info, err := os.Stat(path) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "icon.png", info.Name()) - assert.NoError(t, err) + require.NoError(t, err) } diff --git a/app/preferences_test.go b/app/preferences_test.go index 63f6ce5e02..a09ef06882 100644 --- a/app/preferences_test.go +++ b/app/preferences_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func loadPreferences(id string) *preferences { @@ -24,7 +25,7 @@ func TestPreferences_Remove(t *testing.T) { p.RemoveValue("keyString") err := p.saveToFile(p.storagePath()) - assert.NoError(t, err) + require.NoError(t, err) // check it doesn't write values that were removed p = loadPreferences("dummy") @@ -49,7 +50,7 @@ func TestPreferences_Save(t *testing.T) { path := p.storagePath() defer os.Remove(path) err := p.saveToFile(path) - assert.NoError(t, err) + require.NoError(t, err) expected, err := os.ReadFile(filepath.Join("testdata", "preferences.json")) if err != nil { diff --git a/app/storage_test.go b/app/storage_test.go index 33eafab4a8..f9858bdedc 100644 --- a/app/storage_test.go +++ b/app/storage_test.go @@ -3,7 +3,7 @@ package app import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestStore_RootURI(t *testing.T) { @@ -12,9 +12,9 @@ func TestStore_RootURI(t *testing.T) { d := makeStoreDocs(id, &store{a: a}) w, err := d.Create("test") - assert.NoError(t, err) + require.NoError(t, err) err = w.Close() - assert.NoError(t, err) + require.NoError(t, err) err = d.Remove("test") - assert.NoError(t, err) + require.NoError(t, err) } diff --git a/canvas/image_test.go b/canvas/image_test.go index 9b6d5c7b75..4a43889df2 100644 --- a/canvas/image_test.go +++ b/canvas/image_test.go @@ -14,6 +14,7 @@ import ( _ "fyne.io/fyne/v2/test" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestImage_AlphaDefault(t *testing.T) { @@ -41,7 +42,7 @@ func TestNewImageFromReader(t *testing.T) { pwd, _ := os.Getwd() path := filepath.Join(filepath.Dir(pwd), "theme", "icons", "fyne.png") read, err := os.Open(path) - assert.NoError(t, err) + require.NoError(t, err) defer read.Close() img := canvas.NewImageFromReader(read, "fyne.png") diff --git a/canvas/text_test.go b/canvas/text_test.go index 4bee9182e9..51f32ea147 100644 --- a/canvas/text_test.go +++ b/canvas/text_test.go @@ -48,7 +48,7 @@ func TestText_MinSize_NoMultiLine(t *testing.T) { text = canvas.NewText("Bre\nak", color.NRGBA{0, 0, 0, 0xff}) min2 := text.MinSize() assert.Greater(t, min2.Width, min.Width) - assert.True(t, min2.Height == min.Height) + assert.Equal(t, min2.Height, min.Height) } func TestText_Layout(t *testing.T) { diff --git a/cmd/fyne/internal/commands/build_test.go b/cmd/fyne/internal/commands/build_test.go index 47d8a54ac6..a25abb0d26 100644 --- a/cmd/fyne/internal/commands/build_test.go +++ b/cmd/fyne/internal/commands/build_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func Test_BuildWasmVersion(t *testing.T) { @@ -30,7 +31,7 @@ func Test_BuildWasmVersion(t *testing.T) { wasmBuildTest := &testCommandRuns{runs: expected, t: t} b := &Builder{appData: &appData{}, os: "wasm", srcdir: "myTest", runner: wasmBuildTest} err := b.build() - assert.Nil(t, err) + require.NoError(t, err) wasmBuildTest.verifyExpectation() } @@ -58,7 +59,7 @@ func Test_BuildWasmReleaseVersion(t *testing.T) { wasmBuildTest := &testCommandRuns{runs: expected, t: t} b := &Builder{appData: &appData{}, os: "wasm", srcdir: "myTest", release: true, runner: wasmBuildTest} err := b.build() - assert.Nil(t, err) + require.NoError(t, err) wasmBuildTest.verifyExpectation() } @@ -88,7 +89,7 @@ func Test_BuildLinuxReleaseVersion(t *testing.T) { linuxBuildTest := &testCommandRuns{runs: expected, t: t} b := &Builder{appData: &appData{}, os: "linux", srcdir: "myTest", release: true, runner: linuxBuildTest, goPackage: relativePath} err := b.build() - assert.Nil(t, err) + require.NoError(t, err) linuxBuildTest.verifyExpectation() } diff --git a/cmd/fyne/internal/commands/mock_runner_test.go b/cmd/fyne/internal/commands/mock_runner_test.go index c22f0e75fe..17d5bc470f 100644 --- a/cmd/fyne/internal/commands/mock_runner_test.go +++ b/cmd/fyne/internal/commands/mock_runner_test.go @@ -80,10 +80,10 @@ func (t *testCommandRuns) verifyExpectation() { for _, value := range t.runs { if value.dir != nil { - assert.Equal(t.t, true, value.dirSet) + assert.True(t.t, value.dirSet) } if len(value.env) > 0 { - assert.Equal(t.t, true, value.envSet) + assert.True(t.t, value.envSet) } } } diff --git a/cmd/fyne/internal/commands/package-darwin_test.go b/cmd/fyne/internal/commands/package-darwin_test.go index 97896ae053..e86a6f75b1 100644 --- a/cmd/fyne/internal/commands/package-darwin_test.go +++ b/cmd/fyne/internal/commands/package-darwin_test.go @@ -9,7 +9,7 @@ import ( func TestDarwinLangs(t *testing.T) { langs := darwinLangs([]string{"en-GB", "de-CH"}) - assert.Equal(t, 2, len(langs)) + assert.Len(t, langs, 2) assert.Equal(t, "en_GB", langs[0]) assert.Equal(t, "de_CH", langs[1]) } diff --git a/cmd/fyne/internal/commands/package-unix_test.go b/cmd/fyne/internal/commands/package-unix_test.go index 67800dd54d..1d986e3ec9 100644 --- a/cmd/fyne/internal/commands/package-unix_test.go +++ b/cmd/fyne/internal/commands/package-unix_test.go @@ -2,11 +2,11 @@ package commands import ( "bytes" - "strings" "testing" "fyne.io/fyne/v2/cmd/fyne/internal/templates" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestFormatDesktopFileList(t *testing.T) { @@ -22,15 +22,15 @@ func TestDesktopFileSource(t *testing.T) { buf := &bytes.Buffer{} err := templates.DesktopFileUNIX.Execute(buf, tplData) - assert.Nil(t, err) - assert.False(t, strings.Contains(buf.String(), "[X-Fyne")) + require.NoError(t, err) + assert.NotContains(t, buf.String(), "[X-Fyne") tplData.SourceRepo = "https://example.com" tplData.SourceDir = "cmd/name" err = templates.DesktopFileUNIX.Execute(buf, tplData) - assert.Nil(t, err) - assert.True(t, strings.Contains(buf.String(), "[X-Fyne")) - assert.True(t, strings.Contains(buf.String(), "Repo=https://example.com")) - assert.True(t, strings.Contains(buf.String(), "Dir=cmd/name")) + require.NoError(t, err) + assert.Contains(t, buf.String(), "[X-Fyne") + assert.Contains(t, buf.String(), "Repo=https://example.com") + assert.Contains(t, buf.String(), "Dir=cmd/name") } diff --git a/cmd/fyne/internal/commands/package_test.go b/cmd/fyne/internal/commands/package_test.go index a3bc944552..8549b0ad0a 100644 --- a/cmd/fyne/internal/commands/package_test.go +++ b/cmd/fyne/internal/commands/package_test.go @@ -9,6 +9,7 @@ import ( "github.com/josephspurrier/goversioninfo" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "fyne.io/fyne/v2/internal/metadata" ) @@ -116,44 +117,44 @@ func Test_MergeMetata(t *testing.T) { func Test_validateAppID(t *testing.T) { id, err := validateAppID("myApp", "windows", "myApp", false) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "myApp", id) id, err = validateAppID("", "darwin", "myApp", true) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "com.example.myApp", id) // this was in for compatibility id, err = validateAppID("com.myApp", "darwin", "myApp", true) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "com.myApp", id) _, err = validateAppID("", "ios", "myApp", false) - assert.NotNil(t, err) + require.Error(t, err) _, err = validateAppID("myApp", "ios", "myApp", false) - assert.NotNil(t, err) + require.Error(t, err) id, err = validateAppID("com.myApp", "android", "myApp", true) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "com.myApp", id) _, err = validateAppID("myApp", "android", "myApp", true) - assert.NotNil(t, err) + require.Error(t, err) _, err = validateAppID("com._server.myApp", "android", "myApp", true) - assert.NotNil(t, err) + require.Error(t, err) _, err = validateAppID("com.5server.myApp", "android", "myApp", true) - assert.NotNil(t, err) + require.Error(t, err) _, err = validateAppID("0com.server.myApp", "android", "myApp", true) - assert.NotNil(t, err) + require.Error(t, err) _, err = validateAppID("......", "android", "myApp", true) - assert.Nil(t, err) + require.NoError(t, err) _, err = validateAppID(".....myApp", "android", "myApp", true) - assert.Nil(t, err) + require.NoError(t, err) } func Test_buildPackageWasm(t *testing.T) { @@ -185,9 +186,9 @@ func Test_buildPackageWasm(t *testing.T) { } wasmBuildTest := &testCommandRuns{runs: expected, t: t} files, err := p.buildPackage(wasmBuildTest, []string{}) - assert.Nil(t, err) + require.NoError(t, err) assert.NotNil(t, files) - assert.Equal(t, 1, len(files)) + assert.Len(t, files, 1) } func Test_PackageWasm(t *testing.T) { @@ -274,7 +275,7 @@ func Test_PackageWasm(t *testing.T) { } err := p.doPackage(wasmBuildTest) - assert.Nil(t, err) + require.NoError(t, err) wasmBuildTest.verifyExpectation() expectedTotalCount(t, len(expectedEnsureSubDirRuns.expected), expectedEnsureSubDirRuns.current) expectedTotalCount(t, len(expectedExistRuns.expected), expectedExistRuns.current) diff --git a/cmd/fyne/internal/commands/serve_test.go b/cmd/fyne/internal/commands/serve_test.go index cc382532ab..83af1404ae 100644 --- a/cmd/fyne/internal/commands/serve_test.go +++ b/cmd/fyne/internal/commands/serve_test.go @@ -4,20 +4,21 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func Test_validatePort(t *testing.T) { valid := &Server{port: 80} - assert.Nil(t, valid.validate()) + require.NoError(t, valid.validate()) assert.Equal(t, 80, valid.port) def := &Server{} - assert.Nil(t, def.validate()) + require.NoError(t, def.validate()) assert.Equal(t, 8080, def.port) invalidLow := &Server{port: -1} - assert.NotNil(t, invalidLow.validate()) + require.Error(t, invalidLow.validate()) invalidHigh := &Server{port: 65536} - assert.NotNil(t, invalidHigh.validate()) + require.Error(t, invalidHigh.validate()) } diff --git a/cmd/fyne/internal/util/mobile_test.go b/cmd/fyne/internal/util/mobile_test.go index afc3c57e06..ba5d1616b5 100644 --- a/cmd/fyne/internal/util/mobile_test.go +++ b/cmd/fyne/internal/util/mobile_test.go @@ -10,24 +10,24 @@ func Test_IsMobile(t *testing.T) { osList := []string{"darwin", "linux", "windows", "android/arm", "android/arm64", "android/amd64", "android/386", "android", "ios"} osIsMobile := []bool{false, false, false, true, true, true, true, true, true} - assert.Equal(t, IsMobile(""), false) + assert.False(t, IsMobile("")) for i, os := range osList { assert.Equal(t, IsMobile(os), osIsMobile[i]) } - assert.Equal(t, IsMobile("amiga"), false) + assert.False(t, IsMobile("amiga")) } func Test_IsAndroid(t *testing.T) { osList := []string{"darwin", "linux", "windows", "android/arm", "android/arm64", "android/amd64", "android/386", "android", "ios"} osIsMobile := []bool{false, false, false, true, true, true, true, true, false} - assert.Equal(t, IsAndroid(""), false) + assert.False(t, IsAndroid("")) for i, os := range osList { assert.Equal(t, IsAndroid(os), osIsMobile[i]) } - assert.Equal(t, IsAndroid("amiga"), false) + assert.False(t, IsAndroid("amiga")) } diff --git a/cmd/fyne_settings/settings/scale_test.go b/cmd/fyne_settings/settings/scale_test.go index 8368979fea..c234bffa27 100644 --- a/cmd/fyne_settings/settings/scale_test.go +++ b/cmd/fyne_settings/settings/scale_test.go @@ -26,7 +26,7 @@ func TestMakeScaleButtons(t *testing.T) { s.fyneSettings.Scale = 1.0 buttons := s.makeScaleButtons() - assert.Equal(t, 5, len(buttons)) + assert.Len(t, buttons, 5) assert.Equal(t, widget.MediumImportance, buttons[0].(*widget.Button).Importance) assert.Equal(t, widget.HighImportance, buttons[2].(*widget.Button).Importance) } @@ -36,7 +36,7 @@ func TestMakeScalePreviews(t *testing.T) { s.fyneSettings.Scale = 1.0 previews := s.makeScalePreviews(1.0) - assert.Equal(t, 5, len(previews)) + assert.Len(t, previews, 5) assert.Equal(t, theme.TextSize(), previews[2].(*canvas.Text).TextSize) s.appliedScale(1.5) diff --git a/container/apptabs_desktop_test.go b/container/apptabs_desktop_test.go index 2d57c0dec8..bfe02e5394 100644 --- a/container/apptabs_desktop_test.go +++ b/container/apptabs_desktop_test.go @@ -77,25 +77,25 @@ func TestAppTabs_DynamicTabs(t *testing.T) { appendedItem := container.NewTabItem("Test2", widget.NewLabel("Text 2")) tabs.Append(appendedItem) - assert.Equal(t, 2, len(tabs.Items)) + assert.Len(t, tabs.Items, 2) assert.Equal(t, "Test2", tabs.Items[1].Text) test.AssertRendersToMarkup(t, "apptabs/desktop/dynamic_appended.xml", c) tabs.RemoveIndex(1) - assert.Equal(t, len(tabs.Items), 1) + assert.Len(t, tabs.Items, 1) assert.Equal(t, "Test1", tabs.Items[0].Text) test.AssertRendersToMarkup(t, "apptabs/desktop/dynamic_initial.xml", c) tabs.Append(appendedItem) tabs.Remove(tabs.Items[0]) - assert.Equal(t, len(tabs.Items), 1) + assert.Len(t, tabs.Items, 1) assert.Equal(t, "Test2", tabs.Items[0].Text) test.AssertRendersToMarkup(t, "apptabs/desktop/dynamic_appended_and_removed.xml", c) tabs.Append(container.NewTabItem("Test3", canvas.NewCircle(theme.Color(theme.ColorNameBackground)))) tabs.Append(container.NewTabItem("Test4", canvas.NewCircle(theme.Color(theme.ColorNameBackground)))) tabs.Append(container.NewTabItem("Test5", canvas.NewCircle(theme.Color(theme.ColorNameBackground)))) - assert.Equal(t, 4, len(tabs.Items)) + assert.Len(t, tabs.Items, 4) assert.Equal(t, "Test3", tabs.Items[1].Text) assert.Equal(t, "Test4", tabs.Items[2].Text) assert.Equal(t, "Test5", tabs.Items[3].Text) @@ -106,7 +106,7 @@ func TestAppTabs_DynamicTabs(t *testing.T) { container.NewTabItem("Test7", widget.NewLabel("Text 7")), container.NewTabItem("Test8", widget.NewLabel("Text 8")), }) - assert.Equal(t, 3, len(tabs.Items)) + assert.Len(t, tabs.Items, 3) assert.Equal(t, "Test6", tabs.Items[0].Text) assert.Equal(t, "Test7", tabs.Items[1].Text) assert.Equal(t, "Test8", tabs.Items[2].Text) diff --git a/container/apptabs_internal_test.go b/container/apptabs_internal_test.go index 777cfdbf46..90ab030435 100644 --- a/container/apptabs_internal_test.go +++ b/container/apptabs_internal_test.go @@ -56,11 +56,11 @@ func Test_tabButtonRenderer_EmptyDeleteAdd(t *testing.T) { tabs.Resize(fyne.NewSize(300, 200)) tabRenderer := cache.Renderer(tabs).(*appTabsRenderer) - assert.Equal(t, 0, len(tabRenderer.bar.Objects[0].(*fyne.Container).Objects)) + assert.Empty(t, tabRenderer.bar.Objects[0].(*fyne.Container).Objects) tabs.Append(item1) - assert.Equal(t, 1, len(tabRenderer.bar.Objects[0].(*fyne.Container).Objects)) + assert.Len(t, tabRenderer.bar.Objects[0].(*fyne.Container).Objects, 1) tabs.Remove(item1) - assert.Equal(t, 0, len(tabRenderer.bar.Objects[0].(*fyne.Container).Objects)) + assert.Empty(t, tabRenderer.bar.Objects[0].(*fyne.Container).Objects) } diff --git a/container/apptabs_test.go b/container/apptabs_test.go index 7958e48412..1a8cde57d8 100644 --- a/container/apptabs_test.go +++ b/container/apptabs_test.go @@ -16,20 +16,20 @@ func TestAppTabs_Selected(t *testing.T) { tab2 := &TabItem{Text: "Test2", Content: widget.NewLabel("Test2")} tabs := NewAppTabs(tab1, tab2) - assert.Equal(t, 2, len(tabs.Items)) + assert.Len(t, tabs.Items, 2) assert.Equal(t, tab1, tabs.Selected()) } func TestAppTabs_SelectedIndex(t *testing.T) { tabs := NewAppTabs(&TabItem{Text: "Test", Content: widget.NewLabel("Test")}) - assert.Equal(t, 1, len(tabs.Items)) + assert.Len(t, tabs.Items, 1) assert.Equal(t, 0, tabs.SelectedIndex()) } func TestAppTabs_Empty(t *testing.T) { tabs := NewAppTabs() - assert.Equal(t, 0, len(tabs.Items)) + assert.Empty(t, tabs.Items) assert.Equal(t, -1, tabs.SelectedIndex()) assert.Nil(t, tabs.Selected()) min := tabs.MinSize() @@ -37,7 +37,7 @@ func TestAppTabs_Empty(t *testing.T) { assert.Equal(t, theme.Padding(), min.Height) tabs = &AppTabs{} - assert.Equal(t, 0, len(tabs.Items)) + assert.Empty(t, tabs.Items) assert.Nil(t, tabs.Selected()) assert.NotNil(t, test.TempWidgetRenderer(t, tabs)) // doesn't crash } @@ -71,7 +71,7 @@ func TestAppTabs_Select(t *testing.T) { tab2 := &TabItem{Text: "Test2", Content: widget.NewLabel("Test2")} tabs := NewAppTabs(tab1, tab2) - assert.Equal(t, 2, len(tabs.Items)) + assert.Len(t, tabs.Items, 2) assert.Equal(t, tab1, tabs.Selected()) var selectedTab *TabItem @@ -101,7 +101,7 @@ func TestAppTabs_SelectIndex(t *testing.T) { tabs := NewAppTabs(&TabItem{Text: "Test1", Content: widget.NewLabel("Test1")}, &TabItem{Text: "Test2", Content: widget.NewLabel("Test2")}) - assert.Equal(t, 2, len(tabs.Items)) + assert.Len(t, tabs.Items, 2) assert.Equal(t, 0, tabs.SelectedIndex()) var selectedTab *TabItem diff --git a/container/doctabs_desktop_test.go b/container/doctabs_desktop_test.go index 88e6c6ee12..f3b22468bd 100644 --- a/container/doctabs_desktop_test.go +++ b/container/doctabs_desktop_test.go @@ -123,25 +123,25 @@ func TestDocTabs_DynamicTabs(t *testing.T) { appendedItem := container.NewTabItem("Test2", widget.NewLabel("Text 2")) tabs.Append(appendedItem) - assert.Equal(t, 2, len(tabs.Items)) + assert.Len(t, tabs.Items, 2) assert.Equal(t, "Test2", tabs.Items[1].Text) test.AssertRendersToMarkup(t, "doctabs/desktop/dynamic_appended.xml", c) tabs.RemoveIndex(1) - assert.Equal(t, len(tabs.Items), 1) + assert.Len(t, tabs.Items, 1) assert.Equal(t, "Test1", tabs.Items[0].Text) test.AssertRendersToMarkup(t, "doctabs/desktop/dynamic_initial.xml", c) tabs.Append(appendedItem) tabs.Remove(tabs.Items[0]) - assert.Equal(t, len(tabs.Items), 1) + assert.Len(t, tabs.Items, 1) assert.Equal(t, "Test2", tabs.Items[0].Text) test.AssertRendersToMarkup(t, "doctabs/desktop/dynamic_appended_and_removed.xml", c) tabs.Append(container.NewTabItem("Test3", canvas.NewCircle(theme.Color(theme.ColorNameBackground)))) tabs.Append(container.NewTabItem("Test4", canvas.NewCircle(theme.Color(theme.ColorNameBackground)))) tabs.Append(container.NewTabItem("Test5", canvas.NewCircle(theme.Color(theme.ColorNameBackground)))) - assert.Equal(t, 4, len(tabs.Items)) + assert.Len(t, tabs.Items, 4) assert.Equal(t, "Test3", tabs.Items[1].Text) assert.Equal(t, "Test4", tabs.Items[2].Text) assert.Equal(t, "Test5", tabs.Items[3].Text) @@ -152,7 +152,7 @@ func TestDocTabs_DynamicTabs(t *testing.T) { container.NewTabItem("Test7", widget.NewLabel("Text 7")), container.NewTabItem("Test8", widget.NewLabel("Text 8")), }) - assert.Equal(t, 3, len(tabs.Items)) + assert.Len(t, tabs.Items, 3) assert.Equal(t, "Test6", tabs.Items[0].Text) assert.Equal(t, "Test7", tabs.Items[1].Text) assert.Equal(t, "Test8", tabs.Items[2].Text) diff --git a/container/doctabs_test.go b/container/doctabs_test.go index e0c24dff14..bea0b607e0 100644 --- a/container/doctabs_test.go +++ b/container/doctabs_test.go @@ -17,20 +17,20 @@ func TestDocTabs_Selected(t *testing.T) { tab2 := &container.TabItem{Text: "Test2", Content: widget.NewLabel("Test2")} tabs := container.NewDocTabs(tab1, tab2) - assert.Equal(t, 2, len(tabs.Items)) + assert.Len(t, tabs.Items, 2) assert.Equal(t, tab1, tabs.Selected()) } func TestDocTabs_SelectedIndex(t *testing.T) { tabs := container.NewDocTabs(&container.TabItem{Text: "Test", Content: widget.NewLabel("Test")}) - assert.Equal(t, 1, len(tabs.Items)) + assert.Len(t, tabs.Items, 1) assert.Equal(t, 0, tabs.SelectedIndex()) } func TestDocTabs_Empty(t *testing.T) { tabs := container.NewDocTabs() - assert.Equal(t, 0, len(tabs.Items)) + assert.Empty(t, tabs.Items) assert.Equal(t, -1, tabs.SelectedIndex()) assert.Nil(t, tabs.Selected()) min := tabs.MinSize() @@ -38,7 +38,7 @@ func TestDocTabs_Empty(t *testing.T) { assert.Equal(t, 4*theme.Padding()+theme.IconInlineSize(), min.Height) tabs = &container.DocTabs{} - assert.Equal(t, 0, len(tabs.Items)) + assert.Empty(t, tabs.Items) assert.Nil(t, tabs.Selected()) assert.NotNil(t, test.TempWidgetRenderer(t, tabs)) // doesn't crash } @@ -72,7 +72,7 @@ func TestDocTabs_Select(t *testing.T) { tab2 := &container.TabItem{Text: "Test2", Content: widget.NewLabel("Test2")} tabs := container.NewDocTabs(tab1, tab2) - assert.Equal(t, 2, len(tabs.Items)) + assert.Len(t, tabs.Items, 2) assert.Equal(t, tab1, tabs.Selected()) var selectedTab *container.TabItem @@ -102,7 +102,7 @@ func TestDocTabs_SelectIndex(t *testing.T) { tabs := container.NewDocTabs(&container.TabItem{Text: "Test1", Content: widget.NewLabel("Test1")}, &container.TabItem{Text: "Test2", Content: widget.NewLabel("Test2")}) - assert.Equal(t, 2, len(tabs.Items)) + assert.Len(t, tabs.Items, 2) assert.Equal(t, 0, tabs.SelectedIndex()) var selectedTab *container.TabItem diff --git a/container/layouts_test.go b/container/layouts_test.go index 39c2997ad2..678f648a48 100644 --- a/container/layouts_test.go +++ b/container/layouts_test.go @@ -11,12 +11,12 @@ import ( func TestNewBorder_Nil(t *testing.T) { b := NewBorder(nil, nil, nil, nil) - assert.Equal(t, 0, len(b.Objects)) + assert.Empty(t, b.Objects) b = NewBorder(canvas.NewRectangle(color.Black), canvas.NewRectangle(color.Black), canvas.NewRectangle(color.Black), canvas.NewRectangle(color.Black)) - assert.Equal(t, 4, len(b.Objects)) + assert.Len(t, b.Objects, 4) b = NewBorder(canvas.NewRectangle(color.Black), nil, nil, nil, nil) // a common error - adding nil to component list - assert.Equal(t, 1, len(b.Objects)) + assert.Len(t, b.Objects, 1) b = NewBorder(canvas.NewRectangle(color.Black), canvas.NewRectangle(color.Black), canvas.NewRectangle(color.Black), canvas.NewRectangle(color.Black), nil) - assert.Equal(t, 4, len(b.Objects)) + assert.Len(t, b.Objects, 4) } diff --git a/container/multiplewindows_test.go b/container/multiplewindows_test.go index c8901abb3a..e73d6a14ab 100644 --- a/container/multiplewindows_test.go +++ b/container/multiplewindows_test.go @@ -11,17 +11,17 @@ import ( func TestMultipleWindows_Add(t *testing.T) { m := NewMultipleWindows() - assert.Zero(t, len(m.Windows)) + assert.Empty(t, m.Windows) m.Add(NewInnerWindow("1", widget.NewLabel("Inside"))) - assert.Equal(t, 1, len(m.Windows)) + assert.Len(t, m.Windows, 1) } func TestMultipleWindows_Drag(t *testing.T) { w := NewInnerWindow("1", widget.NewLabel("Inside")) m := NewMultipleWindows(w) _ = test.TempWidgetRenderer(t, m) // initialise display - assert.Equal(t, 1, len(m.Windows)) + assert.Len(t, m.Windows, 1) assert.True(t, w.Position().IsZero()) w.OnDragged(&fyne.DragEvent{Dragged: fyne.Delta{DX: 10, DY: 5}}) diff --git a/data/binding/binding_exted_test.go b/data/binding/binding_exted_test.go index f06e46da3d..ea2ed9bad9 100644 --- a/data/binding/binding_exted_test.go +++ b/data/binding/binding_exted_test.go @@ -4,13 +4,14 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestBindUserType(t *testing.T) { val := user{name: "Unnamed"} u := bindUserType(&val) v, err := u.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "User: Unnamed", v.String()) called := false @@ -22,7 +23,7 @@ func TestBindUserType(t *testing.T) { called = false err = u.Set(user{name: "Replace"}) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "User: Replace", val.String()) assert.True(t, called) @@ -31,7 +32,7 @@ func TestBindUserType(t *testing.T) { _ = u.Reload() assert.True(t, called) v, err = u.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "User: Direct", v.String()) called = false @@ -39,20 +40,20 @@ func TestBindUserType(t *testing.T) { _ = u.Reload() assert.True(t, called) v, err = u.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "User: FieldSet", v.String()) } func TestNewUserType(t *testing.T) { u := newUserType() v, err := u.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "User: ", v.String()) err = u.Set(user{name: "Dave"}) - assert.Nil(t, err) + require.NoError(t, err) v, err = u.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "User: Dave", v.String()) } diff --git a/data/binding/binditems_extend_test.go b/data/binding/binditems_extend_test.go index 0f2962d6ee..5aca834ab2 100644 --- a/data/binding/binditems_extend_test.go +++ b/data/binding/binditems_extend_test.go @@ -5,13 +5,14 @@ import ( "time" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestBindTime(t *testing.T) { val := time.Now() f := bindTime(&val) v, err := f.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, val.Unix(), v.Unix()) called := false @@ -24,7 +25,7 @@ func TestBindTime(t *testing.T) { newTime := val.Add(time.Hour) called = false err = f.Set(newTime) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, newTime.Unix(), val.Unix()) assert.True(t, called) @@ -34,21 +35,21 @@ func TestBindTime(t *testing.T) { _ = f.Reload() assert.True(t, called) v, err = f.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, newTime.Unix(), v.Unix()) } func TestNewTime(t *testing.T) { f := newTime() v, err := f.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, time.Unix(0, 0), v) now := time.Now() err = f.Set(now) - assert.Nil(t, err) + require.NoError(t, err) v, err = f.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, now.Unix(), v.Unix()) } diff --git a/data/binding/binditems_test.go b/data/binding/binditems_test.go index 2f8ff95bd7..1eb3c39fb5 100644 --- a/data/binding/binditems_test.go +++ b/data/binding/binditems_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "fyne.io/fyne/v2/storage" ) @@ -17,7 +18,7 @@ func TestBindFloat(t *testing.T) { val := 0.5 f := BindFloat(&val) v, err := f.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 0.5, v) called := false @@ -29,7 +30,7 @@ func TestBindFloat(t *testing.T) { called = false err = f.Set(0.3) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 0.3, val) assert.True(t, called) @@ -38,7 +39,7 @@ func TestBindFloat(t *testing.T) { f.Reload() assert.True(t, called) v, err = f.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 1.2, v) } @@ -47,7 +48,7 @@ func TestBindUntyped(t *testing.T) { val = 0.5 f := BindUntyped(&val) v, err := f.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 0.5, v) called := false @@ -59,7 +60,7 @@ func TestBindUntyped(t *testing.T) { called = false err = f.Set(0.3) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 0.3, val) assert.True(t, called) @@ -68,20 +69,20 @@ func TestBindUntyped(t *testing.T) { f.Reload() assert.True(t, called) v, err = f.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 1.2, v) } func TestNewFloat(t *testing.T) { f := NewFloat() v, err := f.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 0.0, v) err = f.Set(0.3) - assert.Nil(t, err) + require.NoError(t, err) v, err = f.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 0.3, v) } @@ -97,30 +98,30 @@ func TestBindFloat_TriggerOnlyWhenChange(t *testing.T) { triggered = 0 for i := 0; i < 5; i++ { err := f.Set(9.0) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 1, triggered) } triggered = 0 err := f.Set(9.1) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 1, triggered) triggered = 0 err = f.Set(8.0) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 1, triggered) triggered = 0 v = 8.0 err = f.Reload() - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, 0, triggered) triggered = 0 v = 9.2 err = f.Reload() - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, 1, triggered) } @@ -135,18 +136,18 @@ func TestNewFloat_TriggerOnlyWhenChange(t *testing.T) { triggered = 0 for i := 0; i < 5; i++ { err := f.Set(9.0) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 1, triggered) } triggered = 0 err := f.Set(9.1) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 1, triggered) triggered = 0 err = f.Set(8.0) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 1, triggered) } @@ -154,7 +155,7 @@ func TestBindURI(t *testing.T) { val := storage.NewFileURI("/tmp") f := BindURI(&val) v, err := f.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "file:///tmp", v.String()) called := false @@ -166,7 +167,7 @@ func TestBindURI(t *testing.T) { called = false err = f.Set(storage.NewFileURI("/tmp/test.txt")) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "file:///tmp/test.txt", val.String()) assert.True(t, called) @@ -175,7 +176,7 @@ func TestBindURI(t *testing.T) { _ = f.Reload() assert.True(t, called) v, err = f.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "file:///hello", v.String()) } @@ -191,43 +192,43 @@ func TestBindURI_TriggerOnlyWhenChange(t *testing.T) { triggered = 0 for i := 0; i < 5; i++ { err := b.Set(storage.NewFileURI("second")) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 1, triggered) } triggered = 0 err := b.Set(storage.NewFileURI("third")) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 1, triggered) triggered = 0 err = b.Set(storage.NewFileURI("fourth")) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 1, triggered) triggered = 0 v = storage.NewFileURI("fourth") err = b.Reload() - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, 0, triggered) triggered = 0 v = storage.NewFileURI("fifth") err = b.Reload() - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, 1, triggered) } func TestNewURI(t *testing.T) { f := NewURI() v, err := f.Get() - assert.Nil(t, err) - assert.Equal(t, nil, v) + require.NoError(t, err) + assert.Nil(t, v) err = f.Set(storage.NewFileURI("/var")) - assert.Nil(t, err) + require.NoError(t, err) v, err = f.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "file:///var", v.String()) } @@ -242,17 +243,17 @@ func TestNewURI_TriggerOnlyWhenChange(t *testing.T) { triggered = 0 for i := 0; i < 5; i++ { err := b.Set(storage.NewFileURI("first")) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 1, triggered) } triggered = 0 err := b.Set(storage.NewFileURI("second")) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 1, triggered) triggered = 0 err = b.Set(storage.NewFileURI("third")) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 1, triggered) } diff --git a/data/binding/bindlists_test.go b/data/binding/bindlists_test.go index cc2b49a94a..68eaecedc0 100644 --- a/data/binding/bindlists_test.go +++ b/data/binding/bindlists_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestBindFloatList(t *testing.T) { @@ -12,14 +13,14 @@ func TestBindFloatList(t *testing.T) { assert.Equal(t, 3, f.Length()) v, err := f.GetValue(1) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 5.0, v) assert.NotNil(t, f.(*boundFloatList).val) - assert.Equal(t, 3, len(*(f.(*boundFloatList).val))) + assert.Len(t, *(f.(*boundFloatList).val), 3) _, err = f.GetValue(-1) - assert.NotNil(t, err) + assert.Error(t, err) } func TestExternalFloatList_Reload(t *testing.T) { @@ -28,7 +29,7 @@ func TestExternalFloatList_Reload(t *testing.T) { assert.Equal(t, 3, f.Length()) v, err := f.GetValue(1) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 5.0, v) calledList, calledChild := false, false @@ -38,23 +39,23 @@ func TestExternalFloatList_Reload(t *testing.T) { assert.True(t, calledList) child, err := f.GetItem(1) - assert.Nil(t, err) + require.NoError(t, err) child.AddListener(NewDataListener(func() { calledChild = true })) assert.True(t, calledChild) assert.NotNil(t, f.(*boundFloatList).val) - assert.Equal(t, 3, len(*(f.(*boundFloatList).val))) + assert.Len(t, *(f.(*boundFloatList).val), 3) _, err = f.GetValue(-1) - assert.NotNil(t, err) + require.Error(t, err) calledList, calledChild = false, false l[1] = 4.8 f.Reload() v, err = f.GetValue(1) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 4.8, v) assert.False(t, calledList) assert.True(t, calledChild) @@ -63,7 +64,7 @@ func TestExternalFloatList_Reload(t *testing.T) { l = []float64{1.0, 4.2} f.Reload() v, err = f.GetValue(1) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 4.2, v) assert.True(t, calledList) assert.True(t, calledChild) @@ -72,7 +73,7 @@ func TestExternalFloatList_Reload(t *testing.T) { l = []float64{1.0, 4.2, 5.3} f.Reload() v, err = f.GetValue(1) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 4.2, v) assert.True(t, calledList) assert.False(t, calledChild) @@ -83,7 +84,7 @@ func TestNewFloatList(t *testing.T) { assert.Equal(t, 0, f.Length()) _, err := f.GetValue(-1) - assert.NotNil(t, err) + assert.Error(t, err) } func TestFloatList_Append(t *testing.T) { @@ -98,21 +99,21 @@ func TestFloatList_GetValue(t *testing.T) { f := NewFloatList() err := f.Append(1.3) - assert.Nil(t, err) + require.NoError(t, err) v, err := f.GetValue(0) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 1.3, v) err = f.Append(0.2) - assert.Nil(t, err) + require.NoError(t, err) v, err = f.GetValue(1) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 0.2, v) err = f.SetValue(1, 0.5) - assert.Nil(t, err) + require.NoError(t, err) v, err = f.GetValue(1) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 0.5, v) } @@ -133,39 +134,39 @@ func TestFloatList_Set(t *testing.T) { l := []float64{1.0, 5.0, 2.3} f := BindFloatList(&l) i, err := f.GetItem(1) - assert.Nil(t, err) + require.NoError(t, err) data := i.(Float) assert.Equal(t, 3, f.Length()) v, err := f.GetValue(1) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 5.0, v) v, err = data.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 5.0, v) l = []float64{1.2, 5.2, 2.2, 4.2} err = f.Set(l) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 4, f.Length()) v, err = f.GetValue(1) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 5.2, v) v, err = data.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 5.2, v) l = []float64{1.3, 5.3} err = f.Set(l) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 2, f.Length()) v, err = f.GetValue(0) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 1.3, v) v, err = data.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 5.3, v) } diff --git a/data/binding/bindtrees_test.go b/data/binding/bindtrees_test.go index 26f774f548..d21a9d0ba4 100644 --- a/data/binding/bindtrees_test.go +++ b/data/binding/bindtrees_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestBindStringTree(t *testing.T) { @@ -11,16 +12,16 @@ func TestBindStringTree(t *testing.T) { l := map[string]string{"1": "one", "5": "five", "2": "two and a half"} f := BindStringTree(&ids, &l) - assert.Equal(t, 3, len(f.ChildIDs(DataTreeRootID))) + assert.Len(t, f.ChildIDs(DataTreeRootID), 3) v, err := f.GetValue("5") - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "five", v) assert.NotNil(t, f.(*boundStringTree).val) - assert.Equal(t, 3, len(*(f.(*boundStringTree).val))) + assert.Len(t, *(f.(*boundStringTree).val), 3) _, err = f.GetValue("nan") - assert.NotNil(t, err) + require.Error(t, err) } func TestExternalFloatTree_Reload(t *testing.T) { @@ -28,9 +29,9 @@ func TestExternalFloatTree_Reload(t *testing.T) { m := map[string]float64{"1": 1.0, "2": 5.0, "3": 2.3} f := BindFloatTree(&i, &m) - assert.Equal(t, 2, len(f.ChildIDs(""))) + assert.Len(t, f.ChildIDs(""), 2) v, err := f.GetValue("2") - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 5.0, v) calledTree, calledChild := false, false @@ -40,23 +41,23 @@ func TestExternalFloatTree_Reload(t *testing.T) { assert.True(t, calledTree) child, err := f.GetItem("2") - assert.Nil(t, err) + require.NoError(t, err) child.AddListener(NewDataListener(func() { calledChild = true })) assert.True(t, calledChild) assert.NotNil(t, f.(*boundFloatTree).val) - assert.Equal(t, 3, len(*(f.(*boundFloatTree).val))) + assert.Len(t, *(f.(*boundFloatTree).val), 3) _, err = f.GetValue("-1") - assert.NotNil(t, err) + require.Error(t, err) calledTree, calledChild = false, false m["2"] = 4.8 f.Reload() v, err = f.GetValue("2") - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 4.8, v) assert.False(t, calledTree) assert.True(t, calledChild) @@ -65,7 +66,7 @@ func TestExternalFloatTree_Reload(t *testing.T) { m = map[string]float64{"1": 1.0, "2": 4.2} f.Reload() v, err = f.GetValue("2") - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 4.2, v) assert.True(t, calledTree) assert.True(t, calledChild) @@ -74,7 +75,7 @@ func TestExternalFloatTree_Reload(t *testing.T) { m = map[string]float64{"1": 1.0, "2": 4.2, "3": 5.3} f.Reload() v, err = f.GetValue("2") - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 4.2, v) assert.True(t, calledTree) assert.False(t, calledChild) @@ -82,39 +83,39 @@ func TestExternalFloatTree_Reload(t *testing.T) { func TestNewStringTree(t *testing.T) { f := NewStringTree() - assert.Equal(t, 0, len(f.ChildIDs(DataTreeRootID))) + assert.Empty(t, f.ChildIDs(DataTreeRootID)) _, err := f.GetValue("NaN") - assert.NotNil(t, err) + require.Error(t, err) } func TestStringTree_Append(t *testing.T) { f := NewStringTree() - assert.Equal(t, 0, len(f.ChildIDs(DataTreeRootID))) + assert.Empty(t, f.ChildIDs(DataTreeRootID)) f.Append(DataTreeRootID, "5", "five") - assert.Equal(t, 1, len(f.ChildIDs(DataTreeRootID))) + assert.Len(t, f.ChildIDs(DataTreeRootID), 1) } func TestStringTree_GetValue(t *testing.T) { f := NewStringTree() err := f.Append(DataTreeRootID, "1", "1.3") - assert.Nil(t, err) + require.NoError(t, err) v, err := f.GetValue("1") - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "1.3", v) err = f.Append(DataTreeRootID, "fraction", "0.2") - assert.Nil(t, err) + require.NoError(t, err) v, err = f.GetValue("fraction") - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "0.2", v) err = f.SetValue("1", "0.5") - assert.Nil(t, err) + require.NoError(t, err) v, err = f.GetValue("1") - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "0.5", v) } @@ -123,12 +124,12 @@ func TestStringTree_Remove(t *testing.T) { f.Append(DataTreeRootID, "5", "five") f.Append(DataTreeRootID, "3", "three") f.Append("5", "53", "fifty three") - assert.Equal(t, 2, len(f.ChildIDs(DataTreeRootID))) - assert.Equal(t, 1, len(f.ChildIDs("5"))) + assert.Len(t, f.ChildIDs(DataTreeRootID), 2) + assert.Len(t, f.ChildIDs("5"), 1) f.Remove("5") - assert.Equal(t, 1, len(f.ChildIDs(DataTreeRootID))) - assert.Equal(t, 0, len(f.ChildIDs("5"))) + assert.Len(t, f.ChildIDs(DataTreeRootID), 1) + assert.Empty(t, f.ChildIDs("5")) } func TestFloatTree_Set(t *testing.T) { @@ -136,41 +137,41 @@ func TestFloatTree_Set(t *testing.T) { m := map[string]float64{"1": 1.0, "2": 5.0, "3": 2.3} f := BindFloatTree(&ids, &m) i, err := f.GetItem("2") - assert.Nil(t, err) + require.NoError(t, err) data := i.(Float) - assert.Equal(t, 2, len(f.ChildIDs(""))) + assert.Len(t, f.ChildIDs(""), 2) v, err := f.GetValue("2") - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 5.0, v) v, err = data.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 5.0, v) ids = map[string][]string{"": {"1", "2"}, "1": {"3", "4"}} m = map[string]float64{"1": 1.2, "2": 5.2, "3": 2.2, "4": 4.2} err = f.Set(ids, m) - assert.Nil(t, err) + require.NoError(t, err) - assert.Equal(t, 2, len(f.ChildIDs("1"))) + assert.Len(t, f.ChildIDs("1"), 2) v, err = f.GetValue("2") - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 5.2, v) v, err = data.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 5.2, v) ids = map[string][]string{"": {"1", "2"}} m = map[string]float64{"1": 1.3, "2": 5.3} err = f.Set(ids, m) - assert.Nil(t, err) + require.NoError(t, err) - assert.Equal(t, 2, len(f.ChildIDs(""))) + assert.Len(t, f.ChildIDs(""), 2) v, err = f.GetValue("1") - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 1.3, v) v, err = data.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 5.3, v) } diff --git a/data/binding/bool_test.go b/data/binding/bool_test.go index 772eb7541a..6f508ccaf1 100644 --- a/data/binding/bool_test.go +++ b/data/binding/bool_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestNot(t *testing.T) { @@ -17,12 +18,12 @@ func TestNot(t *testing.T) { assert.NotNil(t, notbb) notb, err := notbb.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, !b, notb) assert.False(t, notb) err = notbb.Set(true) - assert.Nil(t, err) + require.NoError(t, err) assert.False(t, b) } @@ -59,7 +60,7 @@ func TestAnd(t *testing.T) { } andb, err := andbb.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, a, andb) } for _, v := range b { @@ -100,7 +101,7 @@ func TestOr(t *testing.T) { } andb, err := andbb.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, a, andb) } for _, v := range b { diff --git a/data/binding/convert_helper_test.go b/data/binding/convert_helper_test.go index 2b0e1ae505..ca3c5d4cbe 100644 --- a/data/binding/convert_helper_test.go +++ b/data/binding/convert_helper_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "fyne.io/fyne/v2/storage" ) @@ -28,7 +29,7 @@ func TestURIFromStringHelper(t *testing.T) { str := "file:///tmp/test.txt" u, err := uriFromString(str) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, str, u.String()) } @@ -36,10 +37,10 @@ func TestURIToStringHelper(t *testing.T) { u := storage.NewFileURI("/tmp/test.txt") str, err := uriToString(u) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, u.String(), str) str, err = uriToString(nil) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "", str) } diff --git a/data/binding/convert_test.go b/data/binding/convert_test.go index bd7dfa7a9a..290c6146b6 100644 --- a/data/binding/convert_test.go +++ b/data/binding/convert_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "fyne.io/fyne/v2/storage" ) @@ -12,74 +13,74 @@ func TestBoolToString(t *testing.T) { b := NewBool() s := BoolToString(b) v, err := s.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "false", v) err = b.Set(true) - assert.Nil(t, err) + require.NoError(t, err) v, err = s.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "true", v) err = s.Set("trap") // bug in fmt.SScanf means "wrong" parses as "false" - assert.NotNil(t, err) + require.Error(t, err) _, err = b.Get() - assert.Nil(t, err) + require.NoError(t, err) err = s.Set("false") - assert.Nil(t, err) + require.NoError(t, err) v2, err := b.Get() - assert.Nil(t, err) - assert.Equal(t, false, v2) + require.NoError(t, err) + assert.False(t, v2) } func TestBoolToStringWithFormat(t *testing.T) { b := NewBool() s := BoolToStringWithFormat(b, "%tly") v, err := s.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "falsely", v) err = b.Set(true) - assert.Nil(t, err) + require.NoError(t, err) v, err = s.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "truely", v) err = s.Set("true") // valid bool but not valid format - assert.NotNil(t, err) + require.Error(t, err) _, err = b.Get() - assert.Nil(t, err) + require.NoError(t, err) err = s.Set("falsely") - assert.Nil(t, err) + require.NoError(t, err) v2, err := b.Get() - assert.Nil(t, err) - assert.Equal(t, false, v2) + require.NoError(t, err) + assert.False(t, v2) } func TestFloatToString(t *testing.T) { f := NewFloat() s := FloatToString(f) v, err := s.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "0.000000", v) err = f.Set(0.3) - assert.Nil(t, err) + require.NoError(t, err) v, err = s.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "0.300000", v) err = s.Set("wrong") - assert.NotNil(t, err) + require.Error(t, err) _, err = f.Get() - assert.Nil(t, err) + require.NoError(t, err) err = s.Set("5.00") - assert.Nil(t, err) + require.NoError(t, err) v2, err := f.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 5.0, v2) } @@ -87,24 +88,24 @@ func TestFloatToStringWithFormat(t *testing.T) { f := NewFloat() s := FloatToStringWithFormat(f, "%.2f%%") v, err := s.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "0.00%", v) err = f.Set(0.3) - assert.Nil(t, err) + require.NoError(t, err) v, err = s.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "0.30%", v) err = s.Set("4.3") // valid float64 but not valid format - assert.NotNil(t, err) + require.Error(t, err) _, err = f.Get() - assert.Nil(t, err) + require.NoError(t, err) err = s.Set("5.00%") - assert.Nil(t, err) + require.NoError(t, err) v2, err := f.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 5.0, v2) } @@ -112,24 +113,24 @@ func TestIntToString(t *testing.T) { i := NewInt() s := IntToString(i) v, err := s.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "0", v) err = i.Set(3) - assert.Nil(t, err) + require.NoError(t, err) v, err = s.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "3", v) err = s.Set("wrong") - assert.NotNil(t, err) + require.Error(t, err) _, err = i.Get() - assert.Nil(t, err) + require.NoError(t, err) err = s.Set("5") - assert.Nil(t, err) + require.NoError(t, err) v2, err := i.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 5, v2) } @@ -137,24 +138,24 @@ func TestIntToStringWithFormat(t *testing.T) { i := NewInt() s := IntToStringWithFormat(i, "num%d") v, err := s.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "num0", v) err = i.Set(3) - assert.Nil(t, err) + require.NoError(t, err) v, err = s.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "num3", v) err = s.Set("4") // valid int but not valid format - assert.NotNil(t, err) + require.Error(t, err) _, err = i.Get() - assert.Nil(t, err) + require.NoError(t, err) err = s.Set("num5") - assert.Nil(t, err) + require.NoError(t, err) v2, err := i.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 5, v2) } @@ -162,24 +163,24 @@ func TestStringToBool(t *testing.T) { s := NewString() b := StringToBool(s) v, err := b.Get() - assert.Nil(t, err) - assert.Equal(t, false, v) + require.NoError(t, err) + assert.False(t, v) err = s.Set("true") - assert.Nil(t, err) + require.NoError(t, err) v, err = b.Get() - assert.Nil(t, err) - assert.Equal(t, true, v) + require.NoError(t, err) + assert.True(t, v) err = s.Set("trap") // bug in fmt.SScanf means "wrong" parses as "false" - assert.Nil(t, err) + require.NoError(t, err) _, err = b.Get() - assert.NotNil(t, err) + require.Error(t, err) err = b.Set(false) - assert.Nil(t, err) + require.NoError(t, err) v2, err := s.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "false", v2) } @@ -188,24 +189,24 @@ func TestStringToBoolWithFormat(t *testing.T) { s := BindString(&start) b := StringToBoolWithFormat(s, "%tly") v, err := b.Get() - assert.Nil(t, err) - assert.Equal(t, false, v) + require.NoError(t, err) + assert.False(t, v) err = s.Set("truely") - assert.Nil(t, err) + require.NoError(t, err) v, err = b.Get() - assert.Nil(t, err) - assert.Equal(t, true, v) + require.NoError(t, err) + assert.True(t, v) err = s.Set("true") // valid bool but not valid format - assert.Nil(t, err) + require.NoError(t, err) _, err = b.Get() - assert.NotNil(t, err) + require.Error(t, err) err = b.Set(false) - assert.Nil(t, err) + require.NoError(t, err) v2, err := s.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "falsely", v2) } @@ -213,24 +214,24 @@ func TestStringToFloat(t *testing.T) { s := NewString() f := StringToFloat(s) v, err := f.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 0.0, v) err = s.Set("3") - assert.Nil(t, err) + require.NoError(t, err) v, err = f.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 3.0, v) err = s.Set("wrong") - assert.Nil(t, err) + require.NoError(t, err) _, err = f.Get() - assert.NotNil(t, err) + require.Error(t, err) err = f.Set(5) - assert.Nil(t, err) + require.NoError(t, err) v2, err := s.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "5.000000", v2) } @@ -239,24 +240,24 @@ func TestStringToFloatWithFormat(t *testing.T) { s := BindString(&start) f := StringToFloatWithFormat(s, "%f%%") v, err := f.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 0.0, v) err = s.Set("3.000000%") - assert.Nil(t, err) + require.NoError(t, err) v, err = f.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 3.0, v) err = s.Set("4.3") // valid float64 but not valid format - assert.Nil(t, err) + require.NoError(t, err) _, err = f.Get() - assert.NotNil(t, err) + require.Error(t, err) err = f.Set(5) - assert.Nil(t, err) + require.NoError(t, err) v2, err := s.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "5.000000%", v2) } @@ -264,24 +265,24 @@ func TestStringToInt(t *testing.T) { s := NewString() i := StringToInt(s) v, err := i.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 0, v) err = s.Set("3") - assert.Nil(t, err) + require.NoError(t, err) v, err = i.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 3, v) err = s.Set("wrong") - assert.Nil(t, err) + require.NoError(t, err) _, err = i.Get() - assert.NotNil(t, err) + require.Error(t, err) err = i.Set(5) - assert.Nil(t, err) + require.NoError(t, err) v2, err := s.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "5", v2) } @@ -290,24 +291,24 @@ func TestStringToIntWithFormat(t *testing.T) { s := BindString(&start) i := StringToIntWithFormat(s, "num%d") v, err := i.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 0, v) err = s.Set("num3") - assert.Nil(t, err) + require.NoError(t, err) v, err = i.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 3, v) err = s.Set("4") // valid int but not valid format - assert.Nil(t, err) + require.NoError(t, err) _, err = i.Get() - assert.NotNil(t, err) + require.Error(t, err) err = i.Set(5) - assert.Nil(t, err) + require.NoError(t, err) v2, err := s.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "num5", v2) } @@ -315,13 +316,13 @@ func TestStringToURI(t *testing.T) { s := NewString() u := StringToURI(s) v, err := u.Get() - assert.Nil(t, err) - assert.Equal(t, nil, v) + require.NoError(t, err) + assert.Nil(t, v) err = s.Set("file:///tmp/test.txt") - assert.Nil(t, err) + require.NoError(t, err) v, err = u.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "file:///tmp/test.txt", v.String()) // TODO fix issue in URI parser whereby "wrong" is a valid URI @@ -332,9 +333,9 @@ func TestStringToURI(t *testing.T) { uri := storage.NewFileURI("/mydir/") err = u.Set(uri) - assert.Nil(t, err) + require.NoError(t, err) v2, err := s.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "file:///mydir/", v2) } @@ -342,13 +343,13 @@ func TestURIToString(t *testing.T) { u := NewURI() s := URIToString(u) v, err := s.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "", v) err = u.Set(storage.NewFileURI("/tmp/test.txt")) - assert.Nil(t, err) + require.NoError(t, err) v, err = s.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "file:///tmp/test.txt", v) // TODO fix issue in URI parser whereby "wrong" is a valid URI @@ -358,9 +359,9 @@ func TestURIToString(t *testing.T) { //assert.Nil(t, err) err = s.Set("file:///tmp/test.txt") - assert.Nil(t, err) + require.NoError(t, err) v2, err := u.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "file:///tmp/test.txt", v2.String()) } @@ -368,19 +369,19 @@ func TestFloatToInt(t *testing.T) { f := NewFloat() i := FloatToInt(f) v, err := i.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 0, v) err = f.Set(0.3) - assert.Nil(t, err) + require.NoError(t, err) v, err = i.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 0, v) err = i.Set(5) - assert.Nil(t, err) + require.NoError(t, err) v2, err := f.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 5.0, v2) } @@ -388,18 +389,18 @@ func TestIntToFloat(t *testing.T) { i := NewInt() f := IntToFloat(i) v, err := f.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 0.0, v) err = i.Set(3) - assert.Nil(t, err) + require.NoError(t, err) v, err = f.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 3.0, v) err = f.Set(5) - assert.Nil(t, err) + require.NoError(t, err) v2, err := i.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 5, v2) } diff --git a/data/binding/listbinding_test.go b/data/binding/listbinding_test.go index a67081e0f4..e6b58f6518 100644 --- a/data/binding/listbinding_test.go +++ b/data/binding/listbinding_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) type simpleList struct { @@ -29,16 +30,16 @@ func TestListBase_GetItem(t *testing.T) { data := &simpleList{} f := 0.5 data.appendItem(BindFloat(&f)) - assert.Equal(t, 1, len(data.items)) + assert.Len(t, data.items, 1) item, err := data.GetItem(0) - assert.Nil(t, err) + require.NoError(t, err) val, err := item.(Float).Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, f, val) _, err = data.GetItem(5) - assert.NotNil(t, err) + assert.Error(t, err) } func TestListBase_Length(t *testing.T) { diff --git a/data/binding/mapbinding_test.go b/data/binding/mapbinding_test.go index 5caa3694f8..20a24f99bc 100644 --- a/data/binding/mapbinding_test.go +++ b/data/binding/mapbinding_test.go @@ -5,34 +5,35 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestBindReflectInt(t *testing.T) { i := 5 b := bindReflectInt(reflect.ValueOf(&i).Elem()) v, err := b.(Int).Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 5, v) err = b.(Int).Set(4) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 4, i) s := "hi" b = bindReflectInt(reflect.ValueOf(&s).Elem()) _, err = b.(Int).Get() - assert.NotNil(t, err) // don't crash + require.Error(t, err) // don't crash } func TestBindReflectString(t *testing.T) { s := "Hi" b := bindReflectString(reflect.ValueOf(&s).Elem()) v, err := b.(String).Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "Hi", v) err = b.(String).Set("New") - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "New", s) } @@ -49,21 +50,21 @@ func TestBindStruct(t *testing.T) { b := BindStruct(&s) - assert.Equal(t, 3, len(b.Keys())) + assert.Len(t, b.Keys(), 3) item, err := b.GetItem("Foo") - assert.Nil(t, err) + require.NoError(t, err) v, err := item.(String).Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "bar", v) err = item.(String).Set("Content") - assert.Nil(t, err) + require.NoError(t, err) v, err = item.(String).Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "Content", v) _, err = b.GetItem("Missing") - assert.NotNil(t, err) + require.Error(t, err) } func TestBindStruct_Reload(t *testing.T) { s := struct { @@ -78,15 +79,15 @@ func TestBindStruct_Reload(t *testing.T) { b := BindStruct(&s) - assert.Equal(t, 3, len(b.Keys())) + assert.Len(t, b.Keys(), 3) v, err := b.GetValue("Foo") - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "bar", v) item, err := b.GetItem("Foo") - assert.Nil(t, err) + require.NoError(t, err) v, err = item.(String).Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "bar", v) calledMap, calledItem := false, false @@ -113,22 +114,22 @@ func TestBindStruct_Reload(t *testing.T) { calledMap, calledItem = false, false b.Reload() v, err = b.GetValue("Foo") - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "bas", v) assert.False(t, calledMap) v, err = item.(String).Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "bas", v) assert.True(t, calledItem) calledMap, calledItem = false, false b.Reload() v, err = b.GetValue("Foo") - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "bas", v) assert.False(t, calledMap) v, err = item.(String).Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "bas", v) assert.False(t, calledItem) } @@ -142,24 +143,24 @@ func TestBindUntypedMap(t *testing.T) { b := BindUntypedMap(&m) - assert.Equal(t, 3, len(b.Keys())) + assert.Len(t, b.Keys(), 3) v, err := b.GetValue("foo") - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "bar", v) err = b.SetValue("Extra", "Content") - assert.Nil(t, err) + require.NoError(t, err) v, err = b.GetValue("Extra") - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "Content", v) err = b.SetValue("foo", "new") - assert.Nil(t, err) + require.NoError(t, err) v, err = b.GetValue("foo") - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "new", v) v, err = b.GetValue("Extra") - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "Content", v) } @@ -172,9 +173,9 @@ func TestExternalUntypedMap_Reload(t *testing.T) { b := BindUntypedMap(&m) - assert.Equal(t, 3, len(b.Keys())) + assert.Len(t, b.Keys(), 3) v, err := b.GetValue("foo") - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "bar", v) calledMap, calledChild := false, false @@ -184,7 +185,7 @@ func TestExternalUntypedMap_Reload(t *testing.T) { assert.True(t, calledMap) child, err := b.GetItem("foo") - assert.Nil(t, err) + require.NoError(t, err) child.AddListener(NewDataListener(func() { calledChild = true })) @@ -194,7 +195,7 @@ func TestExternalUntypedMap_Reload(t *testing.T) { m["foo"] = "boo" b.Reload() v, err = b.GetValue("foo") - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "boo", v) assert.False(t, calledMap) assert.True(t, calledChild) @@ -206,7 +207,7 @@ func TestExternalUntypedMap_Reload(t *testing.T) { } b.Reload() v, err = b.GetValue("foo") - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "bar", v) assert.True(t, calledMap) assert.True(t, calledChild) @@ -219,7 +220,7 @@ func TestExternalUntypedMap_Reload(t *testing.T) { } b.Reload() v, err = b.GetValue("foo") - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "bar", v) assert.True(t, calledMap) assert.False(t, calledChild) @@ -233,21 +234,21 @@ func TestUntypedMap_Delete(t *testing.T) { b := BindUntypedMap(&m) - assert.Equal(t, 2, len(b.Keys())) + assert.Len(t, b.Keys(), 2) v, err := b.GetValue("foo") - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "bar", v) v, err = b.GetValue("val") - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 5, v) b.Delete("foo") - assert.Equal(t, 1, len(b.Keys())) + assert.Len(t, b.Keys(), 1) v, err = b.GetValue("foo") - assert.NotNil(t, err) - assert.Equal(t, nil, v) + require.Error(t, err) + assert.Nil(t, v) v, err = b.GetValue("val") - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 5, v) } @@ -259,15 +260,15 @@ func TestUntypedMap_Set(t *testing.T) { b := BindUntypedMap(&m) i, err := b.GetItem("val") - assert.Nil(t, err) + require.NoError(t, err) data := i.(reflectUntyped) - assert.Equal(t, 2, len(b.Keys())) + assert.Len(t, b.Keys(), 2) v, err := b.GetValue("foo") - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "bar", v) v, err = data.get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 5, v) m = map[string]any{ @@ -276,27 +277,27 @@ func TestUntypedMap_Set(t *testing.T) { "val": 7, } err = b.Set(m) - assert.Nil(t, err) + require.NoError(t, err) - assert.Equal(t, 3, len(b.Keys())) + assert.Len(t, b.Keys(), 3) v, err = b.GetValue("foo") - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "new", v) v, err = data.get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 7, v) m = map[string]any{ "val": 9, } err = b.Set(m) - assert.Nil(t, err) + require.NoError(t, err) - assert.Equal(t, 1, len(b.Keys())) + assert.Len(t, b.Keys(), 1) v, err = b.GetValue("val") - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 9, v) v, err = data.get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 9, v) } diff --git a/data/binding/preference_test.go b/data/binding/preference_test.go index 49852d5c14..449e6a938f 100644 --- a/data/binding/preference_test.go +++ b/data/binding/preference_test.go @@ -7,6 +7,7 @@ import ( "fyne.io/fyne/v2/test" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestBindPreference_DataRace(t *testing.T) { @@ -41,13 +42,13 @@ func TestBindPreferenceBool(t *testing.T) { p.SetBool(key, true) bind := BindPreferenceBool(key, p) v, err := bind.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.True(t, v) err = bind.Set(false) - assert.Nil(t, err) + require.NoError(t, err) v, err = bind.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.False(t, v) assert.False(t, p.Bool(key)) } @@ -60,13 +61,13 @@ func TestBindPreferenceFloat(t *testing.T) { p.SetFloat(key, 1.3) bind := BindPreferenceFloat(key, p) v, err := bind.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 1.3, v) err = bind.Set(2.5) - assert.Nil(t, err) + require.NoError(t, err) v, err = bind.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 2.5, v) assert.Equal(t, 2.5, p.Float(key)) } @@ -79,13 +80,13 @@ func TestBindPreferenceInt(t *testing.T) { p.SetInt(key, 4) bind := BindPreferenceInt(key, p) v, err := bind.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 4, v) err = bind.Set(7) - assert.Nil(t, err) + require.NoError(t, err) v, err = bind.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 7, v) assert.Equal(t, 7, p.Int(key)) } @@ -98,13 +99,13 @@ func TestBindPreferenceString(t *testing.T) { p.SetString(key, "aString") bind := BindPreferenceString(key, p) v, err := bind.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "aString", v) err = bind.Set("overwritten") - assert.Nil(t, err) + require.NoError(t, err) v, err = bind.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "overwritten", v) assert.Equal(t, "overwritten", p.String(key)) } @@ -118,17 +119,17 @@ func TestPreferenceBindingCopies(t *testing.T) { bind1 := BindPreferenceString(key, p) bind2 := BindPreferenceString(key, p) v1, err := bind1.Get() - assert.Nil(t, err) + require.NoError(t, err) v2, err := bind2.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, v2, v1) err = bind1.Set("overwritten") - assert.Nil(t, err) + require.NoError(t, err) v1, err = bind1.Get() - assert.Nil(t, err) + require.NoError(t, err) v2, err = bind2.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, v2, v1) } @@ -154,7 +155,7 @@ func TestPreferenceBindingTriggers(t *testing.T) { } err := bind2.Set("overwritten") // write on a different listener, preferences should trigger all - assert.Nil(t, err) + require.NoError(t, err) select { case <-ch: // bind1 triggered by bind2 changing the same key case <-time.After(time.Millisecond * 100): diff --git a/data/binding/sprintf_test.go b/data/binding/sprintf_test.go index 05a0dbb4b8..335f190477 100644 --- a/data/binding/sprintf_test.go +++ b/data/binding/sprintf_test.go @@ -7,6 +7,7 @@ import ( "fyne.io/fyne/v2" "fyne.io/fyne/v2/storage" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestSprintfConversionRead(t *testing.T) { @@ -30,7 +31,7 @@ func TestSprintfConversionRead(t *testing.T) { assert.NotNil(t, sp) sGenerated, err := sp.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.NotNil(t, sGenerated) assert.Equal(t, expected, sGenerated) @@ -43,7 +44,7 @@ func TestSprintfConversionRead(t *testing.T) { expectedChange := fmt.Sprintf(format, b, f, i, r, s, u) sChange, err := sp.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.NotNil(t, sChange) assert.Equal(t, expectedChange, sChange) assert.NotEqual(t, sGenerated, sChange) @@ -70,25 +71,25 @@ func TestSprintfConversionReadWrite(t *testing.T) { assert.NotNil(t, sp) sGenerated, err := sp.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.NotNil(t, sGenerated) assert.Equal(t, expected, sGenerated) err = sp.Set("Bool false , Float 7.000000 , Int 42 , Rune 67 , String nospacestring , URI file:///var/") - assert.Nil(t, err) + require.NoError(t, err) - assert.Equal(t, b, false) - assert.Equal(t, f, float64(7)) - assert.Equal(t, i, 42) - assert.Equal(t, r, 'C') - assert.Equal(t, s, "nospacestring") - assert.Equal(t, u.String(), "file:///var/") + assert.False(t, b) + assert.Equal(t, float64(7), f) + assert.Equal(t, 42, i) + assert.Equal(t, 'C', r) + assert.Equal(t, "nospacestring", s) + assert.Equal(t, "file:///var/", u.String()) expectedChange := fmt.Sprintf(format, b, f, i, r, s, u) sChange, err := sp.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.NotNil(t, sChange) assert.Equal(t, expectedChange, sChange) assert.NotEqual(t, sGenerated, sChange) @@ -104,17 +105,17 @@ func TestNewStringWithFormat(t *testing.T) { assert.NotNil(t, sp) sGenerated, err := sp.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.NotNil(t, sGenerated) assert.Equal(t, expected, sGenerated) err = sp.Set("String nospacestring") - assert.Nil(t, err) + require.NoError(t, err) - assert.Equal(t, s, "nospacestring") + assert.Equal(t, "nospacestring", s) expectedChange := fmt.Sprintf(format, s) sChange, err := sp.Get() - assert.Nil(t, err) + require.NoError(t, err) assert.NotNil(t, sChange) assert.Equal(t, expectedChange, sChange) assert.NotEqual(t, sGenerated, sChange) diff --git a/data/binding/treebinding_test.go b/data/binding/treebinding_test.go index eba1739224..533b32a094 100644 --- a/data/binding/treebinding_test.go +++ b/data/binding/treebinding_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestTreeBase_AddListener(t *testing.T) { @@ -25,24 +26,24 @@ func TestTreeBase_GetItem(t *testing.T) { data := newSimpleTree() f := 0.5 data.appendItem(BindFloat(&f), "f", "") - assert.Equal(t, 1, len(data.items)) + assert.Len(t, data.items, 1) item, err := data.GetItem("f") - assert.Nil(t, err) + require.NoError(t, err) val, err := item.(Float).Get() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, f, val) _, err = data.GetItem("g") - assert.NotNil(t, err) + assert.Error(t, err) } func TestListBase_IDs(t *testing.T) { data := newSimpleTree() - assert.Equal(t, 0, len(data.ChildIDs(""))) + assert.Empty(t, data.ChildIDs("")) data.appendItem(NewFloat(), "1", "") - assert.Equal(t, 1, len(data.ChildIDs(""))) + assert.Len(t, data.ChildIDs(""), 1) assert.Equal(t, "1", data.ChildIDs("")[0]) } diff --git a/data/validation/all_test.go b/data/validation/all_test.go index d93e615005..a1629f0159 100644 --- a/data/validation/all_test.go +++ b/data/validation/all_test.go @@ -4,8 +4,7 @@ import ( "testing" "fyne.io/fyne/v2/data/validation" - - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestNewAllStrings(t *testing.T) { @@ -14,6 +13,6 @@ func TestNewAllStrings(t *testing.T) { validation.NewRegexp(`1\d{3}-\d{2}-\d{2}`, "Only years before 2000 are allowed"), ) - assert.NoError(t, validate("1988-02-21")) - assert.Error(t, validate("2005-02-21")) + require.NoError(t, validate("1988-02-21")) + require.Error(t, validate("2005-02-21")) } diff --git a/data/validation/regexp_test.go b/data/validation/regexp_test.go index f55d971715..697e3525df 100644 --- a/data/validation/regexp_test.go +++ b/data/validation/regexp_test.go @@ -6,15 +6,16 @@ import ( "fyne.io/fyne/v2/data/validation" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestValidator_Regexp(t *testing.T) { r := validation.NewRegexp(``, "Input is not valid") - assert.NoError(t, r("nothing")) // Nothing to validate with, same as no validator. + require.NoError(t, r("nothing")) // Nothing to validate with, same as no validator. r = validation.NewRegexp(`^\d{2}-\w{4}$`, "Input is not valid") - assert.NoError(t, r("10-fyne")) + require.NoError(t, r("10-fyne")) assert.EqualError(t, r("100-fynedesk"), "Input is not valid") } diff --git a/data/validation/time_test.go b/data/validation/time_test.go index 7a54788019..2a2c3063fe 100644 --- a/data/validation/time_test.go +++ b/data/validation/time_test.go @@ -6,16 +6,17 @@ import ( "fyne.io/fyne/v2/data/validation" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestTime(t *testing.T) { validate := validation.NewTime("2006-01-02") - assert.NoError(t, validate("2021-02-21")) - assert.Error(t, validate("21/02-2021")) + require.NoError(t, validate("2021-02-21")) + require.Error(t, validate("21/02-2021")) validate = validation.NewTime("15:04") - assert.NoError(t, validate("12:30")) + require.NoError(t, validate("12:30")) assert.Error(t, validate("25:77")) } diff --git a/dialog/color_test.go b/dialog/color_test.go index b74808d242..a7a74a01b1 100644 --- a/dialog/color_test.go +++ b/dialog/color_test.go @@ -10,6 +10,7 @@ import ( "fyne.io/fyne/v2/test" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestColorDialog_Resize(t *testing.T) { @@ -310,7 +311,7 @@ func Test_stringToColor(t *testing.T) { for name, tt := range rgbhslMap { t.Run(name, func(t *testing.T) { c, err := stringToColor(tt.hex) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, tt.hex, colorToString(c)) }) } diff --git a/dialog/file_test.go b/dialog/file_test.go index 39583f0ee6..0ac2752cac 100644 --- a/dialog/file_test.go +++ b/dialog/file_test.go @@ -10,6 +10,7 @@ import ( intWidget "fyne.io/fyne/v2/internal/widget" "fyne.io/fyne/v2/lang" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "fyne.io/fyne/v2" "fyne.io/fyne/v2/container" @@ -109,7 +110,7 @@ func TestEffectiveStartingDir(t *testing.T) { func TestFileDialogStartRemember(t *testing.T) { testPath, err := filepath.Abs("./testdata") - assert.Nil(t, err) + require.NoError(t, err) start, err := storage.ListerForURI(storage.NewFileURI(testPath)) if err != nil { t.Skipf("could not get lister for working directory: %s", err) @@ -223,7 +224,7 @@ func TestShowFileOpen(t *testing.T) { breadcrumb := ui.Objects[0].(*container.Split).Trailing.(*fyne.Container).Objects[0].(*container.Scroll).Content.(*fyne.Container).Objects[0].(*fyne.Container) assert.NotEmpty(t, breadcrumb.Objects) - assert.NoError(t, err) + require.NoError(t, err) components := strings.Split(testData.String()[7:], "/") if components[0] == "" { // Splitting a unix path will give a "" at the beginning, but we actually want the path bar to show "/". @@ -260,12 +261,12 @@ func TestShowFileOpen(t *testing.T) { test.Tap(open) assert.Nil(t, win.Canvas().Overlays().Top()) - assert.NoError(t, openErr) + require.NoError(t, openErr) assert.Equal(t, target.location.String(), chosen.URI().String()) err = chosen.Close() - assert.NoError(t, err) + require.NoError(t, err) } func TestHiddenFiles(t *testing.T) { @@ -393,7 +394,7 @@ func TestShowFileSave(t *testing.T) { test.Type(nameEntry, "v2_") test.Tap(save) assert.Nil(t, win.Canvas().Overlays().Top()) - assert.NoError(t, saveErr) + require.NoError(t, saveErr) targetParent, err := storage.Parent(target.location) if err != nil { t.Error(err) @@ -402,10 +403,10 @@ func TestShowFileSave(t *testing.T) { assert.Equal(t, expectedPath.String(), chosen.URI().String()) err = chosen.Close() - assert.NoError(t, err) + require.NoError(t, err) pathString := expectedPath.String()[len(expectedPath.Scheme())+3:] err = os.Remove(pathString) - assert.NoError(t, err) + require.NoError(t, err) } func TestFileFilters(t *testing.T) { @@ -475,7 +476,7 @@ func TestView(t *testing.T) { win := test.NewTempWindow(t, widget.NewLabel("Content")) dlg := NewFileOpen(func(reader fyne.URIReadCloser, err error) { - assert.NoError(t, err) + require.NoError(t, err) assert.Nil(t, reader) }, win) @@ -537,7 +538,7 @@ func TestSetView(t *testing.T) { fyne.CurrentApp().Preferences().SetInt(viewLayoutKey, int(defaultView)) dlg := NewFileOpen(func(reader fyne.URIReadCloser, err error) { - assert.NoError(t, err) + require.NoError(t, err) assert.Nil(t, reader) }, win) @@ -593,7 +594,7 @@ func TestSetViewPreferences(t *testing.T) { prefs.SetInt(viewLayoutKey, int(GridView)) dlg := NewFileOpen(func(reader fyne.URIReadCloser, err error) { - assert.NoError(t, err) + require.NoError(t, err) assert.Nil(t, reader) }, win) @@ -627,7 +628,7 @@ func TestViewPreferences(t *testing.T) { prefs.SetInt(viewLayoutKey, -1) dlg := NewFileOpen(func(reader fyne.URIReadCloser, err error) { - assert.NoError(t, err) + require.NoError(t, err) assert.Nil(t, reader) }, win) @@ -664,7 +665,7 @@ func TestFileFavorites(t *testing.T) { win := test.NewTempWindow(t, widget.NewLabel("Content")) dlg := NewFileOpen(func(reader fyne.URIReadCloser, err error) { - assert.NoError(t, err) + require.NoError(t, err) assert.Nil(t, reader) }, win) @@ -698,7 +699,7 @@ func TestFileFavorites(t *testing.T) { } ok, err := storage.Exists(dlg.dialog.dir) - assert.NoError(t, err) + require.NoError(t, err) assert.True(t, ok) } @@ -760,7 +761,7 @@ func TestCreateNewFolderInDir(t *testing.T) { win := test.NewTempWindow(t, widget.NewLabel("Content")) folderDialog := NewFolderOpen(func(lu fyne.ListableURI, err error) { - assert.NoError(t, err) + require.NoError(t, err) }, win) folderDialog.SetConfirmText("Choose") folderDialog.SetDismissText("Cancel") diff --git a/dialog/file_xdg_test.go b/dialog/file_xdg_test.go index 73fc8d038e..976926651d 100644 --- a/dialog/file_xdg_test.go +++ b/dialog/file_xdg_test.go @@ -8,6 +8,7 @@ import ( "fyne.io/fyne/v2/storage" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestFavoriteLocations(t *testing.T) { @@ -22,7 +23,7 @@ func TestFavoriteLocations(t *testing.T) { } homeDir, err := os.UserHomeDir() - assert.NoError(t, err) + require.NoError(t, err) homeURI := storage.NewFileURI(homeDir) for name, subdir := range expected { diff --git a/dialog/folder_test.go b/dialog/folder_test.go index acf3906658..3c1a488de5 100644 --- a/dialog/folder_test.go +++ b/dialog/folder_test.go @@ -6,6 +6,7 @@ import ( "fyne.io/fyne/v2/lang" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "fyne.io/fyne/v2" "fyne.io/fyne/v2/container" @@ -69,7 +70,7 @@ func TestShowFolderOpen(t *testing.T) { test.Tap(open) assert.Nil(t, win.Canvas().Overlays().Top()) - assert.NoError(t, openErr) + require.NoError(t, openErr) assert.Equal(t, (*target).String(), chosen.String()) } diff --git a/driver/native_test.go b/driver/native_test.go index d1be55131c..188be5fa55 100644 --- a/driver/native_test.go +++ b/driver/native_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestRunNative(t *testing.T) { @@ -16,5 +17,5 @@ func TestRunNative(t *testing.T) { return nil }) - assert.Nil(t, err) + require.NoError(t, err) } diff --git a/internal/animation/animation_test.go b/internal/animation/animation_test.go index b3f64b049c..e1c7e00038 100644 --- a/internal/animation/animation_test.go +++ b/internal/animation/animation_test.go @@ -55,7 +55,7 @@ func TestGLDriver_StopAnimation(t *testing.T) { } run.Stop(a) run.animationMutex.RLock() - assert.Zero(t, len(run.animations)) + assert.Empty(t, run.animations) run.animationMutex.RUnlock() } @@ -108,6 +108,6 @@ func TestGLDriver_StopAnimationImmediatelyAndInsideTick(t *testing.T) { // animations stopped inside tick are really stopped in the next runner cycle time.Sleep(time.Second/60 + 100*time.Millisecond) run.animationMutex.RLock() - assert.Zero(t, len(run.animations)) + assert.Empty(t, run.animations) run.animationMutex.RUnlock() } diff --git a/internal/async/goroutine_test.go b/internal/async/goroutine_test.go index dedadb7679..196d5452c3 100644 --- a/internal/async/goroutine_test.go +++ b/internal/async/goroutine_test.go @@ -32,8 +32,8 @@ func TestGoroutineID(t *testing.T) { testID2 := goroutineID() assert.Equal(t, testID1, testID2) - assert.Greater(t, childID1, uint64(0)) + assert.Positive(t, childID1) assert.NotEqual(t, testID1, childID1) - assert.Greater(t, childID2, uint64(0)) + assert.Positive(t, childID2) assert.NotEqual(t, childID1, childID2) } diff --git a/internal/cache/base_test.go b/internal/cache/base_test.go index 3dc99ef4e6..eed5269619 100644 --- a/internal/cache/base_test.go +++ b/internal/cache/base_test.go @@ -35,7 +35,7 @@ func TestCacheClean(t *testing.T) { t.Run("no_expired_objects", func(t *testing.T) { lastClean = tm.createTime(10, 20) Clean(false) - assert.Equal(t, svgs.Len(), 40) + assert.Equal(t, 40, svgs.Len()) assert.Equal(t, 40, renderers.Len()) assert.Len(t, canvases, 40) assert.Zero(t, destroyedRenderersCnt) @@ -43,7 +43,7 @@ func TestCacheClean(t *testing.T) { tm.setTime(10, 30) Clean(true) - assert.Equal(t, svgs.Len(), 40) + assert.Equal(t, 40, svgs.Len()) assert.Equal(t, 40, renderers.Len()) assert.Len(t, canvases, 40) assert.Zero(t, destroyedRenderersCnt) @@ -71,7 +71,7 @@ func TestCacheClean(t *testing.T) { Clean(true) assert.Equal(t, tm.now, lastClean) - assert.Equal(t, svgs.Len(), 40) + assert.Equal(t, 40, svgs.Len()) assert.Equal(t, 40, renderers.Len()) assert.Len(t, canvases, 40) assert.Zero(t, destroyedRenderersCnt) @@ -81,14 +81,14 @@ func TestCacheClean(t *testing.T) { lastClean = tm.createTime(10, 11) tm.setTime(11, 12) Clean(false) - assert.Equal(t, svgs.Len(), 20) + assert.Equal(t, 20, svgs.Len()) assert.Equal(t, 40, renderers.Len()) assert.Len(t, canvases, 40) assert.Zero(t, destroyedRenderersCnt) tm.setTime(11, 42) Clean(false) - assert.Equal(t, svgs.Len(), 0) + assert.Equal(t, 0, svgs.Len()) assert.Equal(t, 40, renderers.Len()) assert.Len(t, canvases, 40) assert.Zero(t, destroyedRenderersCnt) @@ -98,16 +98,16 @@ func TestCacheClean(t *testing.T) { lastClean = tm.createTime(10, 11) tm.setTime(11, 11) Clean(true) - assert.Equal(t, svgs.Len(), 0) + assert.Equal(t, 0, svgs.Len()) assert.Equal(t, 20, renderers.Len()) assert.Len(t, canvases, 20) assert.Equal(t, 20, destroyedRenderersCnt) tm.setTime(11, 22) Clean(true) - assert.Equal(t, svgs.Len(), 0) + assert.Equal(t, 0, svgs.Len()) assert.Equal(t, 0, renderers.Len()) - assert.Len(t, canvases, 0) + assert.Empty(t, canvases) assert.Equal(t, 40, destroyedRenderersCnt) }) @@ -171,7 +171,7 @@ func TestCleanCanvas(t *testing.T) { CleanCanvas(dcanvas2) assert.Equal(t, 0, renderers.Len()) - assert.Len(t, canvases, 0) + assert.Empty(t, canvases) assert.Equal(t, 42, destroyedRenderersCnt) } diff --git a/internal/cache/text_test.go b/internal/cache/text_test.go index b597d65173..721cac6376 100644 --- a/internal/cache/text_test.go +++ b/internal/cache/text_test.go @@ -9,7 +9,7 @@ import ( func TestTextCacheGet(t *testing.T) { ResetThemeCaches() - assert.Equal(t, 0, fontSizeCache.Len()) + assert.Empty(t, fontSizeCache) bound, base := GetFontMetrics("hi", 10, fyne.TextStyle{}, nil) assert.True(t, bound.IsZero()) diff --git a/internal/docs_test.go b/internal/docs_test.go index 20b3c421ea..9ca5c53ac6 100644 --- a/internal/docs_test.go +++ b/internal/docs_test.go @@ -8,21 +8,22 @@ import ( "fyne.io/fyne/v2/storage/repository" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestDocs_Create(t *testing.T) { repository.Register("file", intRepo.NewInMemoryRepository("file")) docs := &Docs{storage.NewFileURI("/tmp/docs/create")} exist, err := storage.Exists(docs.RootDocURI) - assert.NoError(t, err) + require.NoError(t, err) assert.False(t, exist) w, err := docs.Create("test") - assert.NoError(t, err) + require.NoError(t, err) _ = w.Close() exist, err = storage.Exists(docs.RootDocURI) - assert.NoError(t, err) + require.NoError(t, err) assert.True(t, exist) } @@ -30,11 +31,11 @@ func TestDocs_Create_ErrAlreadyExists(t *testing.T) { repository.Register("file", intRepo.NewInMemoryRepository("file")) docs := &Docs{storage.NewFileURI("/tmp/docs/create")} exist, err := storage.Exists(docs.RootDocURI) - assert.NoError(t, err) + require.NoError(t, err) assert.False(t, exist) w, err := docs.Create("test") - assert.NoError(t, err) + require.NoError(t, err) _, _ = w.Write([]byte{}) _ = w.Close() _, err = docs.Create("test") @@ -63,22 +64,22 @@ func TestDocs_Save(t *testing.T) { repository.Register("file", r) docs := &Docs{storage.NewFileURI("/tmp/docs/save")} w, err := docs.Create("save.txt") - assert.NoError(t, err) + require.NoError(t, err) _, _ = w.Write([]byte{}) _ = w.Close() u := w.URI() exist, err := r.Exists(u) - assert.NoError(t, err) + require.NoError(t, err) assert.True(t, exist) w, err = docs.Save("save.txt") - assert.NoError(t, err) + require.NoError(t, err) n, err := w.Write([]byte("save")) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, 4, n) err = w.Close() - assert.NoError(t, err) + require.NoError(t, err) } func TestDocs_Save_ErrNotExists(t *testing.T) { diff --git a/internal/driver/common/canvas_test.go b/internal/driver/common/canvas_test.go index 38999b184f..86b19d48d5 100644 --- a/internal/driver/common/canvas_test.go +++ b/internal/driver/common/canvas_test.go @@ -370,7 +370,7 @@ func TestCanvas_OverlayStack(t *testing.T) { o.Remove(c) assert.Equal(t, 2, len(o.List())) o.Remove(a) - assert.Equal(t, 0, len(o.List())) + assert.Empty(t, o.List()) } func deleteAt(c *fyne.Container, index int) { diff --git a/internal/driver/glfw/device_test.go b/internal/driver/glfw/device_test.go index 11e3cb2049..1744918554 100644 --- a/internal/driver/glfw/device_test.go +++ b/internal/driver/glfw/device_test.go @@ -12,8 +12,8 @@ import ( func Test_Device(t *testing.T) { dev := &glDevice{} - assert.Equal(t, false, dev.IsMobile()) + assert.False(t, dev.IsMobile()) assert.Equal(t, fyne.OrientationHorizontalLeft, dev.Orientation()) - assert.Equal(t, true, dev.HasKeyboard()) - assert.Equal(t, false, dev.IsBrowser()) + assert.True(t, dev.HasKeyboard()) + assert.False(t, dev.IsBrowser()) } diff --git a/internal/driver/glfw/menu_test.go b/internal/driver/glfw/menu_test.go index 1ffd6e61e4..2d0c02236d 100644 --- a/internal/driver/glfw/menu_test.go +++ b/internal/driver/glfw/menu_test.go @@ -23,8 +23,8 @@ func Test_Menu_AddsQuit(t *testing.T) { mainMenu := fyne.NewMainMenu(fyne.NewMenu("File")) bar := buildMenuOverlay(mainMenu, w.window) assert.NotNil(t, bar) - assert.Equal(t, 1, len(mainMenu.Items)) - assert.Equal(t, 2, len(mainMenu.Items[0].Items)) // separator+quit inserted + assert.Len(t, mainMenu.Items, 1) + assert.Len(t, mainMenu.Items[0].Items, 2) // separator+quit inserted assert.True(t, mainMenu.Items[0].Items[1].IsQuit) } @@ -34,7 +34,7 @@ func Test_Menu_LeaveQuit(t *testing.T) { mainMenu := fyne.NewMainMenu(fyne.NewMenu("File", fyne.NewMenuItem(lang.L("Quit"), quitFunc))) bar := buildMenuOverlay(mainMenu, w.window) assert.NotNil(t, bar) - assert.Equal(t, 1, len(mainMenu.Items[0].Items)) // no separator added + assert.Len(t, mainMenu.Items[0].Items, 1) // no separator added assert.Equal(t, reflect.ValueOf(quitFunc).Pointer(), reflect.ValueOf(mainMenu.Items[0].Items[0].Action).Pointer()) } func Test_Menu_LeaveQuit_AddAction(t *testing.T) { @@ -42,7 +42,7 @@ func Test_Menu_LeaveQuit_AddAction(t *testing.T) { mainMenu := fyne.NewMainMenu(fyne.NewMenu("File", fyne.NewMenuItem(lang.L("Quit"), nil))) bar := buildMenuOverlay(mainMenu, w.window) assert.NotNil(t, bar) - assert.Equal(t, 1, len(mainMenu.Items[0].Items)) // no separator added + assert.Len(t, mainMenu.Items[0].Items, 1) // no separator added assert.NotNil(t, mainMenu.Items[0].Items[0].Action) // quit action was added } @@ -57,7 +57,7 @@ func Test_Menu_CustomQuit(t *testing.T) { bar := buildMenuOverlay(mainMenu, w.window) assert.NotNil(t, bar) - assert.Equal(t, 1, len(mainMenu.Items[0].Items)) // no separator added + assert.Len(t, mainMenu.Items[0].Items, 1) // no separator added assert.Equal(t, reflect.ValueOf(quitFunc).Pointer(), reflect.ValueOf(mainMenu.Items[0].Items[0].Action).Pointer()) } @@ -69,6 +69,6 @@ func Test_Menu_CustomQuit_NoAction(t *testing.T) { bar := buildMenuOverlay(mainMenu, w.window) assert.NotNil(t, bar) - assert.Equal(t, 1, len(mainMenu.Items[0].Items)) // no separator added + assert.Len(t, mainMenu.Items[0].Items, 1) // no separator added assert.NotNil(t, mainMenu.Items[0].Items[0].Action) // quit action was added } diff --git a/internal/driver/glfw/window_test.go b/internal/driver/glfw/window_test.go index 831392ce55..12864b15ad 100644 --- a/internal/driver/glfw/window_test.go +++ b/internal/driver/glfw/window_test.go @@ -67,7 +67,7 @@ func TestGLDriver_CreateWindow(t *testing.T) { func TestGLDriver_CreateWindow_EmptyTitle(t *testing.T) { w := createWindow("") - assert.Equal(t, w.Title(), "Fyne Application") + assert.Equal(t, "Fyne Application", w.Title()) } func TestGLDriver_CreateSplashWindow(t *testing.T) { @@ -1575,7 +1575,7 @@ func TestWindow_TabWithModifierToTriggersShortcut(t *testing.T) { w.keyPressed(nil, glfw.KeyTab, 0, glfw.Press, 0) w.keyPressed(nil, glfw.KeyTab, 0, glfw.Release, 0) - assert.Equal(t, 0, len(content.capturedShortcuts)) + assert.Empty(t, content.capturedShortcuts) // Tab with ctrl or alt is not passed w.keyPressed(nil, glfw.KeyTab, 0, glfw.Press, glfw.ModControl) diff --git a/internal/driver/mobile/device_test.go b/internal/driver/mobile/device_test.go index 6dc88b2a04..24e95e5049 100644 --- a/internal/driver/mobile/device_test.go +++ b/internal/driver/mobile/device_test.go @@ -9,7 +9,7 @@ import ( func Test_Device(t *testing.T) { dev := &device{} - assert.Equal(t, true, dev.IsMobile()) - assert.Equal(t, false, dev.IsBrowser()) - assert.Equal(t, false, dev.HasKeyboard()) + assert.True(t, dev.IsMobile()) + assert.False(t, dev.IsBrowser()) + assert.False(t, dev.HasKeyboard()) } diff --git a/internal/driver/mobile/file_test.go b/internal/driver/mobile/file_test.go index f4bf5aaed2..0e3e58b63c 100644 --- a/internal/driver/mobile/file_test.go +++ b/internal/driver/mobile/file_test.go @@ -10,14 +10,14 @@ import ( func TestMobileFilter(t *testing.T) { f := mobileFilter(nil) - assert.Equal(t, 0, len(f.Extensions)) - assert.Equal(t, 0, len(f.MimeTypes)) + assert.Empty(t, f.Extensions) + assert.Empty(t, f.MimeTypes) f = mobileFilter(storage.NewExtensionFileFilter([]string{".png"})) - assert.Equal(t, 1, len(f.Extensions)) - assert.Equal(t, 0, len(f.MimeTypes)) + assert.Len(t, f.Extensions, 1) + assert.Empty(t, f.MimeTypes) f = mobileFilter(storage.NewMimeTypeFileFilter([]string{"text/plain"})) - assert.Equal(t, 0, len(f.Extensions)) - assert.Equal(t, 1, len(f.MimeTypes)) + assert.Empty(t, f.Extensions) + assert.Len(t, f.MimeTypes, 1) } diff --git a/internal/driver/mobile/menu_test.go b/internal/driver/mobile/menu_test.go index 7d78a52036..798f745fa9 100644 --- a/internal/driver/mobile/menu_test.go +++ b/internal/driver/mobile/menu_test.go @@ -58,7 +58,7 @@ func TestMobileCanvas_Menu(t *testing.T) { c.showMenu(menu) menuObjects := c.menu.(*fyne.Container).Objects[1].(*fyne.Container) - assert.Equal(t, 3, len(menuObjects.Objects)) + assert.Len(t, menuObjects.Objects, 3) header, ok := menuObjects.Objects[0].(*fyne.Container) assert.True(t, ok) closed, ok := header.Objects[0].(*widget.Button) diff --git a/internal/driver/mobile/repository_test.go b/internal/driver/mobile/repository_test.go index 794a11ec57..a65d691d02 100644 --- a/internal/driver/mobile/repository_test.go +++ b/internal/driver/mobile/repository_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "fyne.io/fyne/v2/storage" "fyne.io/fyne/v2/storage/repository" @@ -21,7 +22,7 @@ func TestFileRepositoryChild(t *testing.T) { uri, _ := storage.ParseURI("content://thing") p, err := storage.Child(uri, "new") - assert.NotNil(t, err) + require.Error(t, err) assert.Nil(t, p) } @@ -37,6 +38,6 @@ func TestFileRepositoryParent(t *testing.T) { uri, _ := storage.ParseURI("content://thing") p, err := storage.Parent(uri) - assert.NotNil(t, err) + require.Error(t, err) assert.Nil(t, p) } diff --git a/internal/metadata/icon_test.go b/internal/metadata/icon_test.go index bb19941d13..2133ec269b 100644 --- a/internal/metadata/icon_test.go +++ b/internal/metadata/icon_test.go @@ -6,23 +6,24 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "fyne.io/fyne/v2" ) func TestScaleIcon(t *testing.T) { data, err := fyne.LoadResourceFromPath("./testdata/fyne.png") - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "fyne.png", data.Name()) img, err := png.Decode(bytes.NewReader(data.Content())) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 512, img.Bounds().Dx()) smallData := ScaleIcon(data, 256) assert.Equal(t, "fyne-256.png", smallData.Name()) img, err = png.Decode(bytes.NewReader(smallData.Content())) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 256, img.Bounds().Dx()) } diff --git a/internal/metadata/load_test.go b/internal/metadata/load_test.go index d3e8b6d10d..a129ca4ff3 100644 --- a/internal/metadata/load_test.go +++ b/internal/metadata/load_test.go @@ -5,27 +5,28 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestLoadAppMetadata(t *testing.T) { r, err := os.Open("./testdata/FyneApp.toml") - assert.Nil(t, err) + require.NoError(t, err) defer r.Close() data, err := Load(r) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "https://apps.fyne.io", data.Website) assert.Equal(t, "io.fyne.fyne", data.Details.ID) assert.Equal(t, "1.0.0", data.Details.Version) assert.Equal(t, 1, data.Details.Build) - assert.Equal(t, data.Release["Test"], "Value1") - assert.Equal(t, data.Release["InReleaseOnly"], "Value3") + assert.Equal(t, "Value1", data.Release["Test"]) + assert.Equal(t, "Value3", data.Release["InReleaseOnly"]) assert.NotContains(t, data.Release, "InDevelopmentOnly") - assert.Equal(t, data.Development["Test"], "Value2") - assert.Equal(t, data.Development["InDevelopmentOnly"], "Value4") + assert.Equal(t, "Value2", data.Development["Test"]) + assert.Equal(t, "Value4", data.Development["InDevelopmentOnly"]) assert.NotContains(t, data.Development, "InReleaseOnly") assert.NotNil(t, data.Source) - assert.Equal(t, data.Source.Repo, "https://github.com/fyne-io/fyne") - assert.Equal(t, data.Source.Dir, "internal/metadata/testdata") + assert.Equal(t, "https://github.com/fyne-io/fyne", data.Source.Repo) + assert.Equal(t, "internal/metadata/testdata", data.Source.Dir) } diff --git a/internal/metadata/save_test.go b/internal/metadata/save_test.go index b1d476580e..5b5fc5ad57 100644 --- a/internal/metadata/save_test.go +++ b/internal/metadata/save_test.go @@ -5,33 +5,34 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestSaveAppMetadata(t *testing.T) { r, err := os.Open("./testdata/FyneApp.toml") - assert.Nil(t, err) + require.NoError(t, err) data, err := Load(r) _ = r.Close() - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 1, data.Details.Build) data.Details.Build++ versionPath := "./testdata/Version.toml" w, err := os.Create(versionPath) - assert.Nil(t, err) + require.NoError(t, err) err = Save(data, w) - assert.Nil(t, err) + require.NoError(t, err) defer func() { os.Remove(versionPath) }() _ = w.Close() r, err = os.Open(versionPath) - assert.Nil(t, err) + require.NoError(t, err) defer r.Close() data2, err := Load(r) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 2, data2.Details.Build) } diff --git a/internal/painter/font_internal_test.go b/internal/painter/font_internal_test.go index 2692434c86..1a5f1bf0b4 100644 --- a/internal/painter/font_internal_test.go +++ b/internal/painter/font_internal_test.go @@ -13,7 +13,7 @@ import "github.com/go-text/typesetting/fontscan" // chosen := &mockFace{CloseFunc: func() error { return nil }} // fallback := &mockFace{CloseFunc: func() error { return nil }} // c := newFontWithFallback(chosen, fallback, chosenFont, fallbackFont) -// if assert.NoError(t, c.Close()) { +// if require.NoError(t, c.Close()) { // assert.True(t, chosen.CloseInvoked) // assert.True(t, fallback.CloseInvoked) // } diff --git a/internal/repository/file_test.go b/internal/repository/file_test.go index 9f4d257664..1709d9a057 100644 --- a/internal/repository/file_test.go +++ b/internal/repository/file_test.go @@ -12,9 +12,10 @@ import ( "fyne.io/fyne/v2/storage/repository" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) -func checkExistance(path string) bool { +func checkExistence(path string) bool { _, err := os.Stat(path) if err == nil { return true @@ -32,11 +33,11 @@ func TestFileRepositoryRegistration(t *testing.T) { // this should never fail, and we assume it doesn't in other tests here // for brevity foo, err := storage.ParseURI("file:///foo") - assert.Nil(t, err) + require.NoError(t, err) // make sure we get the same repo back repo, err := repository.ForURI(foo) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, f, repo) } @@ -52,11 +53,11 @@ func TestFileRepositoryExists(t *testing.T) { } ex, err := storage.Exists(storage.NewFileURI(existsPath)) - assert.Nil(t, err) + require.NoError(t, err) assert.True(t, ex) ex, err = storage.Exists(storage.NewFileURI(notExistsPath)) - assert.Nil(t, err) + require.NoError(t, err) assert.False(t, ex) } @@ -87,37 +88,37 @@ func TestFileRepositoryReader(t *testing.T) { // Make sure we can read the empty file. fooReader, err := storage.Reader(foo) - assert.Nil(t, err) + require.NoError(t, err) fooData, err := io.ReadAll(fooReader) assert.Equal(t, []byte{}, fooData) - assert.Nil(t, err) + require.NoError(t, err) fooReader.Close() // Make sure we can read the file with data. barReader, err := storage.Reader(bar) - assert.Nil(t, err) + require.NoError(t, err) barData, err := io.ReadAll(barReader) assert.Equal(t, []byte{1, 2, 3}, barData) - assert.Nil(t, err) + require.NoError(t, err) barReader.Close() // Make sure we get an error if the file doesn't exist. bazReader, err := storage.Reader(baz) - assert.NotNil(t, err) + require.Error(t, err) bazReader.Close() // Also test that CanRead returns the expected results. fooCanRead, err := storage.CanRead(foo) assert.True(t, fooCanRead) - assert.Nil(t, err) + require.NoError(t, err) barCanRead, err := storage.CanRead(bar) assert.True(t, barCanRead) - assert.Nil(t, err) + require.NoError(t, err) bazCanRead, err := storage.CanRead(baz) assert.False(t, bazCanRead) - assert.Nil(t, err) + require.NoError(t, err) } func TestFileRepositoryWriter(t *testing.T) { @@ -150,7 +151,7 @@ func TestFileRepositoryWriter(t *testing.T) { // Make sure that spamHam errors, since writing to a non-existent // parent directory should be an error. spamHamWriter, err := storage.Writer(spamHam) - assert.NotNil(t, err) + require.Error(t, err) if err == nil { // Keep this from bodging up the Windows tests if this is // created in error, and then we try to delete it while there @@ -160,27 +161,27 @@ func TestFileRepositoryWriter(t *testing.T) { // write some data and assert there are no errors fooWriter, err := storage.Writer(foo) - assert.Nil(t, err) + require.NoError(t, err) assert.NotNil(t, fooWriter) barWriter, err := storage.Writer(bar) - assert.Nil(t, err) + require.NoError(t, err) assert.NotNil(t, barWriter) bazWriter, err := storage.Writer(baz) - assert.Nil(t, err) + require.NoError(t, err) assert.NotNil(t, bazWriter) n, err := fooWriter.Write([]byte{1, 2, 3, 4, 5}) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 5, n) n, err = barWriter.Write([]byte{6, 7, 8, 9}) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 4, n) n, err = bazWriter.Write([]byte{5, 4, 3, 2, 1, 0}) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 6, n) fooWriter.Close() @@ -188,31 +189,31 @@ func TestFileRepositoryWriter(t *testing.T) { bazWriter.Close() bazAppender, err := storage.Appender(baz) - assert.Nil(t, err) + require.NoError(t, err) n, err = bazAppender.Write([]byte{1, 2, 3, 4, 5}) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 5, n) bazAppender.Close() // now make sure we can read the data back correctly fooReader, err := storage.Reader(foo) - assert.Nil(t, err) + require.NoError(t, err) fooData, err := io.ReadAll(fooReader) assert.Equal(t, []byte{1, 2, 3, 4, 5}, fooData) - assert.Nil(t, err) + require.NoError(t, err) barReader, err := storage.Reader(bar) - assert.Nil(t, err) + require.NoError(t, err) barData, err := io.ReadAll(barReader) assert.Equal(t, []byte{6, 7, 8, 9}, barData) - assert.Nil(t, err) + require.NoError(t, err) bazReader, err := storage.Reader(baz) - assert.Nil(t, err) + require.NoError(t, err) bazData, err := io.ReadAll(bazReader) assert.Equal(t, []byte{5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5}, bazData) - assert.Nil(t, err) + require.NoError(t, err) // close the readers, since Windows won't let us delete things with // open handles to them @@ -222,25 +223,25 @@ func TestFileRepositoryWriter(t *testing.T) { // now let's test deletion err = storage.Delete(foo) - assert.Nil(t, err) + require.NoError(t, err) err = storage.Delete(bar) - assert.Nil(t, err) + require.NoError(t, err) err = storage.Delete(baz) - assert.Nil(t, err) + require.NoError(t, err) fooExists, err := storage.Exists(foo) assert.False(t, fooExists) - assert.Nil(t, err) + require.NoError(t, err) barExists, err := storage.Exists(bar) assert.False(t, barExists) - assert.Nil(t, err) + require.NoError(t, err) bazExists, err := storage.Exists(baz) assert.False(t, bazExists) - assert.Nil(t, err) + require.NoError(t, err) } func TestFileRepositoryCanWrite(t *testing.T) { @@ -270,15 +271,15 @@ func TestFileRepositoryCanWrite(t *testing.T) { fooCanWrite, err := storage.CanWrite(foo) assert.True(t, fooCanWrite) - assert.Nil(t, err) + require.NoError(t, err) barCanWrite, err := storage.CanWrite(bar) assert.True(t, barCanWrite) - assert.Nil(t, err) + require.NoError(t, err) bazCanWrite, err := storage.CanWrite(baz) assert.True(t, bazCanWrite) - assert.Nil(t, err) + require.NoError(t, err) } func TestFileRepositoryParent(t *testing.T) { @@ -290,15 +291,15 @@ func TestFileRepositoryParent(t *testing.T) { // directory parent, err := storage.Parent(storage.NewFileURI("/foo/bar/baz")) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "file:///foo/bar/", parent.String()) parent, err = storage.Parent(storage.NewFileURI("/foo/bar/baz/")) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "file:///foo/bar/", parent.String()) parent, err = storage.Parent(storage.NewFileURI("C:/foo/bar/baz/")) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "file://C:/foo/bar/", parent.String()) if runtime.GOOS == "windows" { @@ -310,7 +311,7 @@ func TestFileRepositoryParent(t *testing.T) { assert.Equal(t, "file://C:/foo/bar/baz/", uri.String()) parent, err = storage.Parent(uri) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "file://C:/foo/bar/", parent.String()) } @@ -330,7 +331,7 @@ func TestFileRepositoryParent(t *testing.T) { // Windows supports UNIX-style paths. /C:/ is also a valid path. parent, err = storage.Parent(storage.NewFileURI("/C:/")) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "file:///", parent.String()) } @@ -371,13 +372,13 @@ func TestFileRepositoryCopy(t *testing.T) { bar := storage.NewFileURI(barPath) err = storage.Copy(foo, bar) - assert.Nil(t, err) + require.NoError(t, err) fooData, err := os.ReadFile(fooPath) - assert.Nil(t, err) + require.NoError(t, err) barData, err := os.ReadFile(barPath) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, fooData, barData) } @@ -397,16 +398,16 @@ func TestFileRepositoryMove(t *testing.T) { bar := storage.NewFileURI(barPath) err = storage.Move(foo, bar) - assert.Nil(t, err) + require.NoError(t, err) barData, err := os.ReadFile(barPath) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, []byte{1, 2, 3, 4, 5}, barData) // Make sure that the source doesn't exist anymore. ex, err := storage.Exists(foo) - assert.Nil(t, err) + require.NoError(t, err) assert.False(t, ex) } @@ -423,18 +424,18 @@ func TestFileRepositoryListing(t *testing.T) { foo := storage.NewFileURI(fooPath) canList, err := storage.CanList(foo) - assert.Nil(t, err) + require.NoError(t, err) assert.True(t, canList) // also check the empty dir childDir := storage.NewFileURI(path.Join(fooPath, "baz", "quux")) canList, err = storage.CanList(childDir) - assert.Nil(t, err) + require.NoError(t, err) assert.True(t, canList) listing, err := storage.List(foo) - assert.Nil(t, err) - assert.Equal(t, 2, len(listing)) + require.NoError(t, err) + assert.Len(t, listing, 2) stringListing := []string{} for _, u := range listing { stringListing = append(stringListing, u.String()) @@ -455,17 +456,17 @@ func TestFileRepositoryCreateListable(t *testing.T) { // Creating a dir with no parent should fail err := storage.CreateListable(fooBar) - assert.NotNil(t, err) + require.Error(t, err) // Creating foo should work though err = storage.CreateListable(foo) - assert.Nil(t, err) + require.NoError(t, err) // and now we should be able to create fooBar err = storage.CreateListable(fooBar) - assert.Nil(t, err) + require.NoError(t, err) // make sure the OS thinks these dirs really exist - assert.True(t, checkExistance(fooPath)) - assert.True(t, checkExistance(fooBarPath)) + assert.True(t, checkExistence(fooPath)) + assert.True(t, checkExistence(fooBarPath)) } diff --git a/internal/repository/http_test.go b/internal/repository/http_test.go index 65e93b3d60..90c8009ccf 100644 --- a/internal/repository/http_test.go +++ b/internal/repository/http_test.go @@ -10,6 +10,7 @@ import ( "fyne.io/fyne/v2/storage/repository" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) // helper function to register the HTTP and HTTPS repositories @@ -27,18 +28,18 @@ func TestHTTPRepositoryRegistration(t *testing.T) { // Test HTTPRespository registration for http scheme httpurl, err := storage.ParseURI("http://foo.com/bar") - assert.Nil(t, err) + require.NoError(t, err) httpRepo, err := repository.ForURI(httpurl) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, http, httpRepo) // test HTTPRepository registration for https scheme httpsurl, err := storage.ParseURI("https://foo.com/bar") - assert.Nil(t, err) + require.NoError(t, err) httpsRepo, err := repository.ForURI(httpsurl) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, https, httpsRepo) } @@ -62,27 +63,27 @@ func TestHTTPRepositoryExists(t *testing.T) { // test a valid url resExists, err := storage.ParseURI(validHost) - assert.Nil(t, err) + require.NoError(t, err) exists, err := storage.Exists(resExists) - assert.Nil(t, err) - assert.Equal(t, true, exists) + require.NoError(t, err) + assert.True(t, exists) // test a valid host with an invalid path resNotExists, err := storage.ParseURI(validHost + invalidPath) - assert.Nil(t, err) + require.NoError(t, err) exists, err = storage.Exists(resNotExists) - assert.Nil(t, err) - assert.Equal(t, false, exists) + require.NoError(t, err) + assert.False(t, exists) // test an invalid host resInvalid, err := storage.ParseURI(invalidHost + invalidPath) - assert.Nil(t, err) + require.NoError(t, err) exists, err = storage.Exists(resInvalid) - assert.NotNil(t, err) - assert.Equal(t, false, exists) + require.Error(t, err) + assert.False(t, exists) } func TestHTTPRepositoryReader(t *testing.T) { @@ -108,12 +109,12 @@ func TestHTTPRepositoryReader(t *testing.T) { // test a valid url returning a valid response body resExists, err := storage.ParseURI(validHost) - assert.Nil(t, err) + require.NoError(t, err) data := make([]byte, len(testData)) // the reader should be obtained without an error reader, err := storage.Reader(resExists) - assert.Nil(t, err) + require.NoError(t, err) // data read from the reader should be equal to testData n, err := reader.Read(data) @@ -123,16 +124,16 @@ func TestHTTPRepositoryReader(t *testing.T) { // test a invalid url returning an error resInvalid, err := storage.ParseURI(invalidHost) - assert.Nil(t, err) + require.NoError(t, err) data = make([]byte, len(testData)) // the reader should not have any data and an error should be obtained reader, err = storage.Reader(resInvalid) - assert.NotNil(t, err) + require.Error(t, err) // no data should be read from the reader n, err = reader.Read(data) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 0, n) } @@ -156,25 +157,25 @@ func TestHTTPRepositoryCanRead(t *testing.T) { // test a valid url returning a valid response body resExists, err := storage.ParseURI(validHost) - assert.Nil(t, err) + require.NoError(t, err) canRead, err := storage.CanRead(resExists) - assert.Nil(t, err) - assert.Equal(t, true, canRead) + require.NoError(t, err) + assert.True(t, canRead) // test a invalid url for a valid host resNotExists, err := storage.ParseURI(validHost + invalidPath) - assert.Nil(t, err) + require.NoError(t, err) canRead, err = storage.CanRead(resNotExists) - assert.NotNil(t, err) - assert.Equal(t, false, canRead) + require.Error(t, err) + assert.False(t, canRead) // test a invalid host resInvalid, err := storage.ParseURI(invalidHost) - assert.Nil(t, err) + require.NoError(t, err) canRead, err = storage.CanRead(resInvalid) - assert.NotNil(t, err) - assert.Equal(t, false, canRead) + require.Error(t, err) + assert.False(t, canRead) } diff --git a/internal/repository/memory_test.go b/internal/repository/memory_test.go index a55927c3b4..856264fa7d 100644 --- a/internal/repository/memory_test.go +++ b/internal/repository/memory_test.go @@ -8,6 +8,7 @@ import ( "fyne.io/fyne/v2/storage/repository" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestInMemoryRepositoryRegistration(t *testing.T) { @@ -17,19 +18,19 @@ func TestInMemoryRepositoryRegistration(t *testing.T) { // this should never fail, and we assume it doesn't in other tests here // for brevity foo, err := storage.ParseURI("mem://foo") - assert.Nil(t, err) + require.NoError(t, err) // make sure we get the same repo back repo, err := repository.ForURI(foo) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, m, repo) // test that re-registration also works m2 := NewInMemoryRepository("mem") repository.Register("mem", m2) - assert.False(t, m == m2) // this is explicitly intended to be pointer comparison + assert.NotSame(t, m, m2) // this is explicitly intended to be pointer comparison repo, err = repository.ForURI(foo) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, m2, repo) } @@ -38,15 +39,15 @@ func TestInMemoryRepositoryParsingWithEmptyList(t *testing.T) { repository.Register("dht", m) foo, err := storage.ParseURI("dht:?00000") - assert.Nil(t, err) + require.NoError(t, err) canList, err := storage.CanList(foo) - assert.NotNil(t, err) - assert.Equal(t, canList, false) + require.Error(t, err) + assert.False(t, canList) listing, err := storage.List(foo) - assert.Nil(t, err) - assert.Equal(t, len(listing), 0) + require.NoError(t, err) + assert.Empty(t, listing) } func TestInMemoryRepositoryParsing(t *testing.T) { @@ -58,19 +59,19 @@ func TestInMemoryRepositoryParsing(t *testing.T) { // without error, lets also explicitly test to make sure foo, err := storage.ParseURI("mem:///foo") - assert.Nil(t, err) + require.NoError(t, err) assert.NotNil(t, foo) bar, err := storage.ParseURI("mem:///bar") - assert.Nil(t, err) + require.NoError(t, err) assert.NotNil(t, bar) baz, _ := storage.ParseURI("mem:///baz") - assert.Nil(t, err) + require.NoError(t, err) assert.NotNil(t, baz) empty, _ := storage.ParseURI("mem:") - assert.Nil(t, err) + require.NoError(t, err) assert.NotNil(t, empty) } @@ -88,15 +89,15 @@ func TestInMemoryRepositoryExists(t *testing.T) { fooExists, err := storage.Exists(foo) assert.True(t, fooExists) - assert.Nil(t, err) + require.NoError(t, err) barExists, err := storage.Exists(bar) assert.True(t, barExists) - assert.Nil(t, err) + require.NoError(t, err) bazExists, err := storage.Exists(baz) assert.False(t, bazExists) - assert.Nil(t, err) + require.NoError(t, err) } func TestInMemoryRepositoryReader(t *testing.T) { @@ -112,20 +113,20 @@ func TestInMemoryRepositoryReader(t *testing.T) { baz, _ := storage.ParseURI("mem:///baz") fooReader, err := storage.Reader(foo) - assert.Nil(t, err) + require.NoError(t, err) fooData, err := io.ReadAll(fooReader) assert.Equal(t, []byte{}, fooData) - assert.Nil(t, err) + require.NoError(t, err) barReader, err := storage.Reader(bar) - assert.Nil(t, err) + require.NoError(t, err) barData, err := io.ReadAll(barReader) assert.Equal(t, []byte{1, 2, 3}, barData) - assert.Nil(t, err) + require.NoError(t, err) bazReader, err := storage.Reader(baz) assert.Nil(t, bazReader) - assert.NotNil(t, err) + require.Error(t, err) } func TestInMemoryRepositoryCanRead(t *testing.T) { @@ -142,15 +143,15 @@ func TestInMemoryRepositoryCanRead(t *testing.T) { fooCanRead, err := storage.CanRead(foo) assert.True(t, fooCanRead) - assert.Nil(t, err) + require.NoError(t, err) barCanRead, err := storage.CanRead(bar) assert.True(t, barCanRead) - assert.Nil(t, err) + require.NoError(t, err) bazCanRead, err := storage.CanRead(baz) assert.False(t, bazCanRead) - assert.Nil(t, err) + require.NoError(t, err) } func TestInMemoryRepositoryWriter(t *testing.T) { @@ -167,27 +168,27 @@ func TestInMemoryRepositoryWriter(t *testing.T) { // write some data and assert there are no errors fooWriter, err := storage.Writer(foo) - assert.Nil(t, err) + require.NoError(t, err) assert.NotNil(t, fooWriter) barWriter, err := storage.Writer(bar) - assert.Nil(t, err) + require.NoError(t, err) assert.NotNil(t, barWriter) bazWriter, err := storage.Writer(baz) - assert.Nil(t, err) + require.NoError(t, err) assert.NotNil(t, bazWriter) n, err := fooWriter.Write([]byte{1, 2, 3, 4, 5}) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 5, n) n, err = barWriter.Write([]byte{6, 7, 8, 9}) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 4, n) n, err = bazWriter.Write([]byte{5, 4, 3, 2, 1, 0}) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 6, n) fooWriter.Close() @@ -195,53 +196,53 @@ func TestInMemoryRepositoryWriter(t *testing.T) { bazWriter.Close() bazAppender, err := storage.Appender(baz) - assert.Nil(t, err) + require.NoError(t, err) n, err = bazAppender.Write([]byte{1, 2, 3, 4, 5}) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, 5, n) bazAppender.Close() // now make sure we can read the data back correctly fooReader, err := storage.Reader(foo) - assert.Nil(t, err) + require.NoError(t, err) fooData, err := io.ReadAll(fooReader) assert.Equal(t, []byte{1, 2, 3, 4, 5}, fooData) - assert.Nil(t, err) + require.NoError(t, err) barReader, err := storage.Reader(bar) - assert.Nil(t, err) + require.NoError(t, err) barData, err := io.ReadAll(barReader) assert.Equal(t, []byte{6, 7, 8, 9}, barData) - assert.Nil(t, err) + require.NoError(t, err) bazReader, err := storage.Reader(baz) - assert.Nil(t, err) + require.NoError(t, err) bazData, err := io.ReadAll(bazReader) assert.Equal(t, []byte{5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5}, bazData) - assert.Nil(t, err) + require.NoError(t, err) // now let's test deletion err = storage.Delete(foo) - assert.Nil(t, err) + require.NoError(t, err) err = storage.Delete(bar) - assert.Nil(t, err) + require.NoError(t, err) err = storage.Delete(baz) - assert.Nil(t, err) + require.NoError(t, err) fooExists, err := storage.Exists(foo) assert.False(t, fooExists) - assert.Nil(t, err) + require.NoError(t, err) barExists, err := storage.Exists(bar) assert.False(t, barExists) - assert.Nil(t, err) + require.NoError(t, err) bazExists, err := storage.Exists(baz) assert.False(t, bazExists) - assert.Nil(t, err) + require.NoError(t, err) } @@ -259,15 +260,15 @@ func TestInMemoryRepositoryCanWrite(t *testing.T) { fooCanWrite, err := storage.CanWrite(foo) assert.True(t, fooCanWrite) - assert.Nil(t, err) + require.NoError(t, err) barCanWrite, err := storage.CanWrite(bar) assert.True(t, barCanWrite) - assert.Nil(t, err) + require.NoError(t, err) bazCanWrite, err := storage.CanWrite(baz) assert.True(t, bazCanWrite) - assert.Nil(t, err) + require.NoError(t, err) } func TestInMemoryRepositoryParent(t *testing.T) { @@ -281,10 +282,10 @@ func TestInMemoryRepositoryParent(t *testing.T) { fooExpectedParent, _ := storage.ParseURI("mem:///foo/bar") fooExists, err := storage.Exists(foo) assert.True(t, fooExists) - assert.Nil(t, err) + require.NoError(t, err) fooParent, err := storage.Parent(foo) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, fooExpectedParent.String(), fooParent.String()) } @@ -298,7 +299,7 @@ func TestInMemoryRepositoryChild(t *testing.T) { fooExpectedChild, _ := storage.ParseURI("mem:///foo/bar/baz/quux") fooChild, err := storage.Child(foo, "quux") - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, fooExpectedChild.String(), fooChild.String()) } @@ -312,7 +313,7 @@ func TestInMemoryRepositoryCopy(t *testing.T) { bar, _ := storage.ParseURI("mem:///bar") err := storage.Copy(foo, bar) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, m.Data["/foo"], m.Data["/bar"]) } @@ -327,12 +328,12 @@ func TestInMemoryRepositoryMove(t *testing.T) { bar, _ := storage.ParseURI("mem:///bar") err := storage.Move(foo, bar) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, []byte{1, 2, 3}, m.Data["/bar"]) exists, err := m.Exists(foo) - assert.Nil(t, err) + require.NoError(t, err) assert.False(t, exists) } @@ -349,11 +350,11 @@ func TestInMemoryRepositoryListing(t *testing.T) { foo, _ := storage.ParseURI("mem:///foo") canList, err := storage.CanList(foo) - assert.Nil(t, err) + require.NoError(t, err) assert.True(t, canList) listing, err := storage.List(foo) - assert.Nil(t, err) + require.NoError(t, err) stringListing := []string{} for _, u := range listing { stringListing = append(stringListing, u.String()) @@ -362,7 +363,7 @@ func TestInMemoryRepositoryListing(t *testing.T) { empty, _ := storage.ParseURI("mem:") // invalid path canList, err = storage.CanList(empty) - assert.NotNil(t, err) + require.Error(t, err) assert.False(t, canList) } @@ -374,13 +375,13 @@ func TestInMemoryRepositoryCreateListable(t *testing.T) { foo, _ := storage.ParseURI("mem:///foo") err := storage.CreateListable(foo) - assert.Nil(t, err) + require.NoError(t, err) - assert.Equal(t, m.Data["/foo"], []byte{}) + assert.Equal(t, []byte{}, m.Data["/foo"]) // trying to create something we already created should fail err = storage.CreateListable(foo) - assert.NotNil(t, err) + require.Error(t, err) // NOTE: creating an InMemoryRepository path with a non-extant parent // is specifically not an error, so that case is not tested. diff --git a/internal/svg/is_svg_test.go b/internal/svg/is_svg_test.go index 8c7a78f1f3..abcafb43ba 100644 --- a/internal/svg/is_svg_test.go +++ b/internal/svg/is_svg_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "fyne.io/fyne/v2" ) @@ -17,7 +18,7 @@ func TestIsFileSVG(t *testing.T) { func TestIsResourceSVG(t *testing.T) { res, err := fyne.LoadResourceFromPath("./testdata/circles.svg") - assert.Nil(t, err) + require.NoError(t, err) assert.True(t, IsResourceSVG(res)) res.(*fyne.StaticResource).StaticName = "stroke" diff --git a/internal/svg/svg_test.go b/internal/svg/svg_test.go index 0a2eb73dea..5c0e137547 100644 --- a/internal/svg/svg_test.go +++ b/internal/svg/svg_test.go @@ -7,7 +7,6 @@ import ( "image/color" "os" "path/filepath" - "strings" "testing" "github.com/srwiley/oksvg" @@ -170,7 +169,7 @@ func TestSVG_ReplaceFillColor(t *testing.T) { t.Fatal(err) } assert.NotEqual(t, string(src), string(res)) - assert.True(t, strings.Contains(string(res), "#ff0000")) + assert.Contains(t, string(res), "#ff0000") } func TestSVG_ReplaceFillColor_Ellipse(t *testing.T) { @@ -192,7 +191,7 @@ func TestSVG_ReplaceFillColor_Ellipse(t *testing.T) { t.Fatal(err) } assert.NotEqual(t, string(src), string(res)) - assert.True(t, strings.Contains(string(res), "#ff0000")) + assert.Contains(t, string(res), "#ff0000") } func helperDrawSVG(t *testing.T, data []byte) image.Image { diff --git a/internal/test/util_test.go b/internal/test/util_test.go index 14e7dd20a6..c3eea285c3 100644 --- a/internal/test/util_test.go +++ b/internal/test/util_test.go @@ -2,7 +2,6 @@ package test_test import ( "bytes" - "fmt" "image" "image/color" "image/draw" @@ -26,7 +25,7 @@ func TestAssertImageMatches(t *testing.T) { txtImg := image.NewNRGBA(bounds) face, err := font.ParseTTF(bytes.NewReader(theme.TextFont().Content())) - assert.Nil(t, err) + require.NoError(t, err) painter.DrawString(txtImg, "Hello!", color.Black, &test.FontMap{face}, 25, 1, fyne.TextStyle{TabWidth: 4}) draw.Draw(img, bounds, txtImg, image.Point{}, draw.Over) @@ -66,7 +65,7 @@ func TestNewCheckedImage(t *testing.T) { } for y, xv := range expectedColorValues { for x, v := range xv { - assert.Equal(t, color.NRGBA{R: v, G: v, B: v, A: 0xff}, img.At(x, y), fmt.Sprintf("color value at %d,%d", x, y)) + assert.Equal(t, color.NRGBA{R: v, G: v, B: v, A: 0xff}, img.At(x, y), "color value at %d,%d", x, y) } } } diff --git a/storage/repository/generic_test.go b/storage/repository/generic_test.go index a23f3e30a8..afe6294f95 100644 --- a/storage/repository/generic_test.go +++ b/storage/repository/generic_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestGenericParent(t *testing.T) { @@ -21,7 +22,7 @@ func TestGenericParent(t *testing.T) { t.Logf("case %d, input='%s', expect='%s', err='%v'\n", i, c.input, c.expect, c.err) u, err := ParseURI(c.input) - assert.NoError(t, err) + require.NoError(t, err) res, err := GenericParent(u) assert.Equal(t, c.err, err) @@ -51,7 +52,7 @@ func TestGenericChild(t *testing.T) { t.Logf("case %d, input='%s', component='%s', expect='%s', err='%v'\n", i, c.input, c.component, c.expect, c.err) u, err := ParseURI(c.input) - assert.NoError(t, err) + require.NoError(t, err) res, err := GenericChild(u, c.component) assert.Equal(t, c.err, err) diff --git a/storage/repository/parse_test.go b/storage/repository/parse_test.go index 4f8d3c5ba3..c4627e27d1 100644 --- a/storage/repository/parse_test.go +++ b/storage/repository/parse_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestNewFileURI(t *testing.T) { @@ -13,40 +14,40 @@ func TestNewFileURI(t *testing.T) { func TestParseURI(t *testing.T) { uri, err := ParseURI("file:///tmp/foo.txt") - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "file:///tmp/foo.txt", uri.String()) uri, err = ParseURI("file:/tmp/foo.txt") - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "file:///tmp/foo.txt", uri.String()) uri, err = ParseURI("file://C:/tmp/foo.txt") - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "file://C:/tmp/foo.txt", uri.String()) } func TestParseInvalidURI(t *testing.T) { uri, err := ParseURI("/tmp/foo.txt") - assert.Error(t, err) + require.Error(t, err) assert.Nil(t, uri) uri, err = ParseURI("file") - assert.Error(t, err) + require.Error(t, err) assert.Nil(t, uri) uri, err = ParseURI("file:") - assert.Error(t, err) + require.Error(t, err) assert.Nil(t, uri) uri, err = ParseURI("file://") - assert.Error(t, err) + require.Error(t, err) assert.Nil(t, uri) uri, err = ParseURI(":foo") - assert.Error(t, err) + require.Error(t, err) assert.Nil(t, uri) uri, err = ParseURI("scheme://0[]/invalid") - assert.Error(t, err) + require.Error(t, err) assert.Nil(t, uri) } diff --git a/storage/resource_test.go b/storage/resource_test.go index 30b045d1a7..9eb23f7f99 100644 --- a/storage/resource_test.go +++ b/storage/resource_test.go @@ -5,16 +5,17 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestLoadResourceFromURI(t *testing.T) { path := filepath.Join("testdata", "test.txt") abs, err := filepath.Abs(path) - assert.NoError(t, err) + require.NoError(t, err) uri := NewFileURI(abs) res, err := LoadResourceFromURI(uri) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "test.txt", res.Name()) assert.Equal(t, []byte("Text content"), res.Content()) } diff --git a/storage/uri_test.go b/storage/uri_test.go index 56b027d1fe..d9242f3b56 100644 --- a/storage/uri_test.go +++ b/storage/uri_test.go @@ -13,19 +13,20 @@ import ( _ "fyne.io/fyne/v2/test" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestURIAuthority(t *testing.T) { // from IETF RFC 3986 s := "foo://example.com:8042/over/there?name=ferret#nose" u, err := storage.ParseURI(s) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "example.com:8042", u.Authority()) // from IETF RFC 3986 s = "urn:example:animal:ferret:nose" u, err = storage.ParseURI(s) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "", u.Authority()) } @@ -33,12 +34,12 @@ func TestURIPath(t *testing.T) { // from IETF RFC 3986 s := "foo://example.com:8042/over/there?name=ferret#nose" u, err := storage.ParseURI(s) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "/over/there", u.Path()) s = "foo:///over/there" u, err = storage.ParseURI(s) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "/over/there", u.Path()) // NOTE: if net/url supported RFC3986, this would pass @@ -50,7 +51,7 @@ func TestURIPath(t *testing.T) { // from IETF RFC 3986 s = "urn:example:animal:ferret:nose" u, err = storage.ParseURI(s) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "example:animal:ferret:nose", u.Path()) } @@ -58,13 +59,13 @@ func TestURIQuery(t *testing.T) { // from IETF RFC 3986 s := "foo://example.com:8042/over/there?name=ferret#nose" u, err := storage.ParseURI(s) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "name=ferret", u.Query()) // from IETF RFC 3986 s = "urn:example:animal:ferret:nose" u, err = storage.ParseURI(s) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "", u.Query()) } @@ -72,13 +73,13 @@ func TestURIFragment(t *testing.T) { // from IETF RFC 3986 s := "foo://example.com:8042/over/there?name=ferret#nose" u, err := storage.ParseURI(s) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "nose", u.Fragment()) // from IETF RFC 3986 s = "urn:example:animal:ferret:nose" u, err = storage.ParseURI(s) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "", u.Fragment()) } @@ -123,15 +124,15 @@ func TestURI_Parent(t *testing.T) { // directory parent, err := storage.Parent(storage.NewURI("file:///foo/bar/baz")) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "file:///foo/bar/", parent.String()) parent, err = storage.Parent(storage.NewFileURI("/foo/bar/baz/")) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "file:///foo/bar/", parent.String()) parent, err = storage.Parent(storage.NewURI("file://C:/foo/bar/baz/")) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "file://C:/foo/bar/", parent.String()) // TODO hook in an http/https handler @@ -162,7 +163,7 @@ func TestURI_Parent(t *testing.T) { assert.Equal(t, "file://C:/foo/bar/baz/", uri.String()) parent, err = storage.Parent(uri) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "file://C:/foo/bar/", parent.String()) } @@ -182,7 +183,7 @@ func TestURI_Parent(t *testing.T) { // Windows supports UNIX-style paths. /C:/ is also a valid path. parent, err = storage.Parent(storage.NewURI("file:///C:/")) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "file:///", parent.String()) } @@ -221,10 +222,10 @@ func TestExists(t *testing.T) { fooExpectedParent, _ := storage.ParseURI("uritest:///foo/bar") fooExists, err := storage.Exists(foo) assert.True(t, fooExists) - assert.NoError(t, err) + require.NoError(t, err) fooParent, err := storage.Parent(foo) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, fooExpectedParent.String(), fooParent.String()) } @@ -265,27 +266,27 @@ func TestWriteAndDelete(t *testing.T) { // write some data and assert there are no errors fooWriter, err := storage.Writer(foo) - assert.NoError(t, err) + require.NoError(t, err) assert.NotNil(t, fooWriter) barWriter, err := storage.Writer(bar) - assert.NoError(t, err) + require.NoError(t, err) assert.NotNil(t, barWriter) bazWriter, err := storage.Writer(baz) - assert.NoError(t, err) + require.NoError(t, err) assert.NotNil(t, bazWriter) n, err := fooWriter.Write([]byte{1, 2, 3, 4, 5}) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, 5, n) n, err = barWriter.Write([]byte{6, 7, 8, 9}) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, 4, n) n, err = bazWriter.Write([]byte{5, 4, 3, 2, 1, 0}) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, 6, n) fooWriter.Close() @@ -293,53 +294,53 @@ func TestWriteAndDelete(t *testing.T) { bazWriter.Close() bazAppender, err := storage.Appender(baz) - assert.NoError(t, err) + require.NoError(t, err) n, err = bazAppender.Write([]byte{1, 2, 3, 4, 5}) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, 5, n) bazAppender.Close() // now make sure we can read the data back correctly fooReader, err := storage.Reader(foo) - assert.NoError(t, err) + require.NoError(t, err) fooData, err := io.ReadAll(fooReader) assert.Equal(t, []byte{1, 2, 3, 4, 5}, fooData) - assert.NoError(t, err) + require.NoError(t, err) barReader, err := storage.Reader(bar) - assert.NoError(t, err) + require.NoError(t, err) barData, err := io.ReadAll(barReader) assert.Equal(t, []byte{6, 7, 8, 9}, barData) - assert.NoError(t, err) + require.NoError(t, err) bazReader, err := storage.Reader(baz) - assert.NoError(t, err) + require.NoError(t, err) bazData, err := io.ReadAll(bazReader) assert.Equal(t, []byte{5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5}, bazData) - assert.NoError(t, err) + require.NoError(t, err) // now let's test deletion err = storage.Delete(foo) - assert.NoError(t, err) + require.NoError(t, err) err = storage.Delete(bar) - assert.NoError(t, err) + require.NoError(t, err) err = storage.Delete(baz) - assert.NoError(t, err) + require.NoError(t, err) fooExists, err := storage.Exists(foo) assert.False(t, fooExists) - assert.NoError(t, err) + require.NoError(t, err) barExists, err := storage.Exists(bar) assert.False(t, barExists) - assert.NoError(t, err) + require.NoError(t, err) bazExists, err := storage.Exists(baz) assert.False(t, bazExists) - assert.NoError(t, err) + require.NoError(t, err) } func TestCanWrite(t *testing.T) { @@ -356,15 +357,15 @@ func TestCanWrite(t *testing.T) { fooCanWrite, err := storage.CanWrite(foo) assert.True(t, fooCanWrite) - assert.NoError(t, err) + require.NoError(t, err) barCanWrite, err := storage.CanWrite(bar) assert.True(t, barCanWrite) - assert.NoError(t, err) + require.NoError(t, err) bazCanWrite, err := storage.CanWrite(baz) assert.True(t, bazCanWrite) - assert.NoError(t, err) + require.NoError(t, err) } func TestCanRead(t *testing.T) { @@ -381,15 +382,15 @@ func TestCanRead(t *testing.T) { fooCanRead, err := storage.CanRead(foo) assert.True(t, fooCanRead) - assert.NoError(t, err) + require.NoError(t, err) barCanRead, err := storage.CanRead(bar) assert.True(t, barCanRead) - assert.NoError(t, err) + require.NoError(t, err) bazCanRead, err := storage.CanRead(baz) assert.False(t, bazCanRead) - assert.NoError(t, err) + require.NoError(t, err) } func TestCopy(t *testing.T) { @@ -402,7 +403,7 @@ func TestCopy(t *testing.T) { bar, _ := storage.ParseURI("uritest:///bar") err := storage.Copy(foo, bar) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, m.Data["/foo"], m.Data["/bar"]) } @@ -417,12 +418,12 @@ func TestRepositoryMove(t *testing.T) { bar, _ := storage.ParseURI("uritest:///bar") err := storage.Move(foo, bar) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, []byte{1, 2, 3}, m.Data["/bar"]) exists, err := m.Exists(foo) - assert.NoError(t, err) + require.NoError(t, err) assert.False(t, exists) } @@ -438,11 +439,11 @@ func TestRepositoryListing(t *testing.T) { foo, _ := storage.ParseURI("uritest:///foo") canList, err := storage.CanList(foo) - assert.NoError(t, err) + require.NoError(t, err) assert.True(t, canList) listing, err := storage.List(foo) - assert.NoError(t, err) + require.NoError(t, err) stringListing := []string{} for _, u := range listing { stringListing = append(stringListing, u.String()) @@ -458,7 +459,7 @@ func TestCreateListable(t *testing.T) { foo, _ := storage.ParseURI("uritest:///foo") err := storage.CreateListable(foo) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, []byte{}, m.Data["/foo"]) diff --git a/test/test_test.go b/test/test_test.go index eb464ce796..34b0ec809e 100644 --- a/test/test_test.go +++ b/test/test_test.go @@ -70,7 +70,7 @@ func TestAssertRendersToImage(t *testing.T) { assert.False(t, test.AssertRendersToImage(tt, "non_existing_master.png", c), "non existing master is not equal to rendered image") assert.True(t, tt.Failed(), "test failed") _, err := os.Stat("testdata/failed/non_existing_master.png") - assert.NoError(t, err) + require.NoError(t, err) }) t.Run("matching master", func(t *testing.T) { @@ -88,7 +88,7 @@ func TestAssertRendersToImage(t *testing.T) { assert.False(t, test.AssertRendersToImage(tt, "image_diffing_master.png", c), "existing master is not equal to rendered image") assert.True(t, tt.Failed(), "test should fail") _, err := os.Stat("testdata/failed/image_diffing_master.png") - assert.NoError(t, err) + require.NoError(t, err) }) if !t.Failed() { diff --git a/theme/json_test.go b/theme/json_test.go index b97f640a7d..4216fe17f9 100644 --- a/theme/json_test.go +++ b/theme/json_test.go @@ -9,6 +9,7 @@ import ( "fyne.io/fyne/v2/storage/repository" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestFromJSON(t *testing.T) { @@ -21,7 +22,7 @@ func TestFromJSON(t *testing.T) { "Icons": {"cancel": "file://./testdata/cancel_Paths.svg"} }`) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, &color.NRGBA{R: 0xc0, G: 0xc0, B: 0xc0, A: 0xff}, th.Color(ColorNameBackground, VariantDark)) assert.Equal(t, &color.NRGBA{R: 0xc0, G: 0xc0, B: 0xc0, A: 0xff}, th.Color(ColorNameBackground, VariantLight)) assert.Equal(t, &color.NRGBA{R: 0xff, G: 0xff, B: 0xff, A: 0xff}, th.Color(ColorNameForeground, VariantLight)) @@ -36,10 +37,10 @@ func TestFromJSON(t *testing.T) { func TestFromTOML_Resource(t *testing.T) { r, err := fyne.LoadResourceFromPath("./testdata/theme.json") - assert.NoError(t, err) + require.NoError(t, err) th, err := FromJSON(string(r.Content())) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, &color.NRGBA{R: 0x30, G: 0x30, B: 0x30, A: 0xff}, th.Color(ColorNameBackground, VariantLight)) assert.Equal(t, &color.NRGBA{R: 0xff, G: 0xff, B: 0xff, A: 0xff}, th.Color(ColorNameForeground, VariantDark)) assert.Equal(t, &color.NRGBA{R: 0xc0, G: 0xc0, B: 0xc0, A: 0xff}, th.Color(ColorNameForeground, VariantLight)) @@ -48,25 +49,25 @@ func TestFromTOML_Resource(t *testing.T) { func TestHexColor(t *testing.T) { c, err := hexColor("#abc").color() - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, &color.NRGBA{R: 0xaa, G: 0xbb, B: 0xcc, A: 0xff}, c) c, err = hexColor("abc").color() - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, &color.NRGBA{R: 0xaa, G: 0xbb, B: 0xcc, A: 0xff}, c) c, err = hexColor("#abcd").color() - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, &color.NRGBA{R: 0xaa, G: 0xbb, B: 0xcc, A: 0xdd}, c) c, err = hexColor("#a1b2c3").color() - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, &color.NRGBA{R: 0xa1, G: 0xb2, B: 0xc3, A: 0xff}, c) c, err = hexColor("a1b2c3").color() - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, &color.NRGBA{R: 0xa1, G: 0xb2, B: 0xc3, A: 0xff}, c) c, err = hexColor("#a1b2c3f4").color() - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, &color.NRGBA{R: 0xa1, G: 0xb2, B: 0xc3, A: 0xf4}, c) c, err = hexColor("a1b2c3f4").color() - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, &color.NRGBA{R: 0xa1, G: 0xb2, B: 0xc3, A: 0xf4}, c) } diff --git a/tools/playground/playground_test.go b/tools/playground/playground_test.go index 612cc54515..6c8de9a19f 100644 --- a/tools/playground/playground_test.go +++ b/tools/playground/playground_test.go @@ -12,6 +12,7 @@ import ( "fyne.io/fyne/v2/theme" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestRender(t *testing.T) { @@ -22,10 +23,10 @@ func TestRender(t *testing.T) { assert.NotNil(t, img) enc, err := encodeImage(img) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAIAAAACUFjqAAAAFElEQVR4nGJiwAtGpbECQAAAAP//DogAFaNSFa8AAAAASUVORK5CYII=", enc) bytes, err := base64.StdEncoding.DecodeString(enc) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "PNG", string(bytes)[1:4]) } diff --git a/widget/bind_helper_test.go b/widget/bind_helper_test.go index 8e1f585ce9..aef7309d7a 100644 --- a/widget/bind_helper_test.go +++ b/widget/bind_helper_test.go @@ -5,6 +5,7 @@ import ( "fyne.io/fyne/v2/data/binding" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestBasicBinder(t *testing.T) { @@ -15,7 +16,7 @@ func TestBasicBinder(t *testing.T) { callback := func(data binding.DataItem) { val, err := data.(binding.Int).Get() - assert.NoError(t, err) + require.NoError(t, err) value = val } binder.SetCallback(callback) diff --git a/widget/check_test.go b/widget/check_test.go index fa71d72c1b..cb74053ce2 100644 --- a/widget/check_test.go +++ b/widget/check_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "fyne.io/fyne/v2" "fyne.io/fyne/v2/data/binding" @@ -23,13 +24,13 @@ func TestCheck_Binding(t *testing.T) { assert.False(t, c.Checked) err := val.Set(true) - assert.NoError(t, err) + require.NoError(t, err) waitForBinding() assert.True(t, c.Checked) c.SetChecked(false) v, err := val.Get() - assert.NoError(t, err) + require.NoError(t, err) assert.False(t, v) c.Unbind() @@ -82,7 +83,7 @@ func TestCheck_Layout(t *testing.T) { func TestNewCheckWithData(t *testing.T) { val := binding.NewBool() err := val.Set(true) - assert.NoError(t, err) + require.NoError(t, err) c := widget.NewCheckWithData("", val) waitForBinding() @@ -90,7 +91,7 @@ func TestNewCheckWithData(t *testing.T) { c.SetChecked(false) v, err := val.Get() - assert.NoError(t, err) + require.NoError(t, err) assert.False(t, v) } diff --git a/widget/entry_validation_test.go b/widget/entry_validation_test.go index aba09a7ce1..7f6e27f4ee 100644 --- a/widget/entry_validation_test.go +++ b/widget/entry_validation_test.go @@ -9,6 +9,7 @@ import ( "fyne.io/fyne/v2/widget" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) var validator = validation.NewRegexp(`^\d{4}-\d{2}-\d{2}$`, "Input is not a valid date") @@ -33,12 +34,12 @@ func TestEntry_ValidatedEntry(t *testing.T) { test.AssertRendersToMarkup(t, "entry/validate_initial.xml", c) test.Type(entry, "2020-02") - assert.Error(t, r(entry.Text)) + require.Error(t, r(entry.Text)) entry.FocusLost() test.AssertRendersToMarkup(t, "entry/validate_invalid.xml", c) test.Type(entry, "-12") - assert.NoError(t, r(entry.Text)) + require.NoError(t, r(entry.Text)) test.AssertRendersToMarkup(t, "entry/validate_valid.xml", c) } @@ -47,15 +48,15 @@ func TestEntry_Validate(t *testing.T) { entry.Validator = validator test.Type(entry, "2020-02") - assert.Error(t, entry.Validate()) + require.Error(t, entry.Validate()) assert.Equal(t, entry.Validate(), entry.Validator(entry.Text)) test.Type(entry, "-12") - assert.NoError(t, entry.Validate()) + require.NoError(t, entry.Validate()) assert.Equal(t, entry.Validate(), entry.Validator(entry.Text)) entry.SetText("incorrect") - assert.Error(t, entry.Validate()) + require.Error(t, entry.Validate()) assert.Equal(t, entry.Validate(), entry.Validator(entry.Text)) } diff --git a/widget/form_test.go b/widget/form_test.go index c58d93a311..b01e161cea 100644 --- a/widget/form_test.go +++ b/widget/form_test.go @@ -11,6 +11,7 @@ import ( "fyne.io/fyne/v2/theme" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestFormSize(t *testing.T) { @@ -377,7 +378,7 @@ func TestForm_Validate(t *testing.T) { entry2.SetText("not-wrong") err = form.Validate() - assert.NoError(t, err) + require.NoError(t, err) } @@ -399,11 +400,11 @@ func TestForm_SetOnValidationChanged(t *testing.T) { form.CreateRenderer() entry1.SetText("incorrect") - assert.Error(t, form.Validate()) + require.Error(t, form.Validate()) assert.True(t, validationError) entry1.SetText("15-true") - assert.NoError(t, form.Validate()) + require.NoError(t, form.Validate()) assert.False(t, validationError) } diff --git a/widget/hyperlink_test.go b/widget/hyperlink_test.go index 4e099ec008..576f2d145e 100644 --- a/widget/hyperlink_test.go +++ b/widget/hyperlink_test.go @@ -20,7 +20,7 @@ import ( func TestHyperlink_MinSize(t *testing.T) { u, err := url.Parse("https://fyne.io/") - assert.NoError(t, err) + require.NoError(t, err) hyperlink := NewHyperlink("Test", u) hyperlink.CreateRenderer() @@ -43,7 +43,7 @@ func TestHyperlink_Cursor(t *testing.T) { u, err := url.Parse("https://fyne.io/") hyperlink := NewHyperlink("Test", u) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, desktop.DefaultCursor, hyperlink.Cursor()) hyperlink.hovered = true @@ -139,7 +139,7 @@ func TestHyperlink_Resize(t *testing.T) { func TestHyperlink_SetText(t *testing.T) { u, err := url.Parse("https://fyne.io/") - assert.NoError(t, err) + require.NoError(t, err) hyperlink := &Hyperlink{Text: "Test", URL: u} hyperlink.CreateRenderer() @@ -151,7 +151,7 @@ func TestHyperlink_SetText(t *testing.T) { func TestHyperlink_SetUrl(t *testing.T) { sURL, err := url.Parse("https://github.com/fyne-io/fyne") - assert.NoError(t, err) + require.NoError(t, err) // test constructor hyperlink := NewHyperlink("Test", sURL) @@ -159,7 +159,7 @@ func TestHyperlink_SetUrl(t *testing.T) { // test setting functions sURL, err = url.Parse("https://fyne.io") - assert.NoError(t, err) + require.NoError(t, err) hyperlink.SetURL(sURL) assert.Equal(t, sURL, hyperlink.URL) } diff --git a/widget/select_test.go b/widget/select_test.go index f4cbb96db8..24c9a880f6 100644 --- a/widget/select_test.go +++ b/widget/select_test.go @@ -34,7 +34,7 @@ func TestNewSelectWithData(t *testing.T) { assert.Equal(t, "", combo.Selected) err := data.Set("2") - assert.NoError(t, err) + require.NoError(t, err) waitForBinding() assert.Equal(t, "2", combo.Selected) } @@ -78,27 +78,27 @@ func TestSelect_Binding(t *testing.T) { s.Bind(str) waitForBinding() value, err := str.Get() - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "", value) assert.Equal(t, "2", s.Selected) // no match to options, so keep previous value err = str.Set("3") - assert.NoError(t, err) + require.NoError(t, err) waitForBinding() assert.Equal(t, "3", s.Selected) s.Unbind() assert.Nil(t, s.OnChanged) err = str.Set("1") - assert.NoError(t, err) + require.NoError(t, err) val1, err := str.Get() - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "1", val1) assert.Equal(t, "3", s.Selected) s.SetSelected("2") val1, err = str.Get() - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "1", val1) assert.Equal(t, "2", s.Selected) } diff --git a/widget/slider_test.go b/widget/slider_test.go index 48c92ee263..7802065540 100644 --- a/widget/slider_test.go +++ b/widget/slider_test.go @@ -9,12 +9,13 @@ import ( "fyne.io/fyne/v2/theme" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestNewSliderWithData(t *testing.T) { val := binding.NewFloat() err := val.Set(4) - assert.NoError(t, err) + require.NoError(t, err) s := NewSliderWithData(0, 10, val) waitForBinding() @@ -22,7 +23,7 @@ func TestNewSliderWithData(t *testing.T) { s.SetValue(2.0) f, err := val.Get() - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, 2.0, f) } @@ -37,13 +38,13 @@ func TestSlider_Binding(t *testing.T) { assert.Equal(t, 0.0, s.Value) err := val.Set(3) - assert.NoError(t, err) + require.NoError(t, err) waitForBinding() assert.Equal(t, 3.0, s.Value) s.SetValue(5) f, err := val.Get() - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, 5.0, f) s.Unbind()