Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test suite: code linting #5367

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/icon_cache_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"fyne.io/fyne/v2"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

//go:embed testdata/fyne.png
Expand All @@ -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)
}
5 changes: 3 additions & 2 deletions app/preferences_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func loadPreferences(id string) *preferences {
Expand All @@ -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")
Expand All @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions app/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package app
import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestStore_RootURI(t *testing.T) {
Expand All @@ -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)
}
3 changes: 2 additions & 1 deletion canvas/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion canvas/text_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 4 additions & 3 deletions cmd/fyne/internal/commands/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func Test_BuildWasmVersion(t *testing.T) {
Expand All @@ -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()
}

Expand Down Expand Up @@ -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()
}

Expand Down Expand Up @@ -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()
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/fyne/internal/commands/mock_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
2 changes: 1 addition & 1 deletion cmd/fyne/internal/commands/package-darwin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
14 changes: 7 additions & 7 deletions cmd/fyne/internal/commands/package-unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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")
}
31 changes: 16 additions & 15 deletions cmd/fyne/internal/commands/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 5 additions & 4 deletions cmd/fyne/internal/commands/serve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
8 changes: 4 additions & 4 deletions cmd/fyne/internal/util/mobile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
4 changes: 2 additions & 2 deletions cmd/fyne_settings/settings/scale_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions container/apptabs_desktop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions container/apptabs_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Loading
Loading