Skip to content

Commit

Permalink
Merge pull request #5364 from deining/testifylint
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacalz authored Jan 6, 2025
2 parents b2c469e + 238ba7c commit 446f2a7
Show file tree
Hide file tree
Showing 72 changed files with 506 additions and 510 deletions.
4 changes: 2 additions & 2 deletions app/cloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ func TestFyneApp_transitionCloud_Storage(t *testing.T) {
a.Storage().Create("nothere")

l := a.Storage().List()
assert.Equal(t, 1, len(l))
assert.Len(t, l, 1)

p := &mockCloud{}
a.SetCloudProvider(p)

l = a.Storage().List()
assert.Equal(t, 0, len(l))
assert.Empty(t, l)
}

type mockCloud struct {
Expand Down
4 changes: 2 additions & 2 deletions app/icon_cache_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ func TestCachedIcon_PATH(t *testing.T) {
}

info, err := os.Stat(path)
assert.Nil(t, err)
assert.NoError(t, err)
assert.Equal(t, "icon.png", info.Name())

assert.Nil(t, err)
assert.NoError(t, err)
}
10 changes: 5 additions & 5 deletions app/preferences_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestPreferences_Remove(t *testing.T) {

p.RemoveValue("keyString")
err := p.saveToFile(p.storagePath())
assert.Nil(t, err)
assert.NoError(t, err)

// check it doesn't write values that were removed
p = loadPreferences("dummy")
Expand All @@ -49,7 +49,7 @@ func TestPreferences_Save(t *testing.T) {
path := p.storagePath()
defer os.Remove(path)
err := p.saveToFile(path)
assert.Nil(t, err)
assert.NoError(t, err)

expected, err := os.ReadFile(filepath.Join("testdata", "preferences.json"))
if err != nil {
Expand All @@ -64,7 +64,7 @@ func TestPreferences_Save(t *testing.T) {
// check it reads the saved output
p = loadPreferences("dummy")
assert.Equal(t, "value", p.String("keyString"))
assert.Equal(t, 3, len(p.StringList("keyStringList")))
assert.Len(t, p.StringList("keyStringList"), 3)
}

func TestPreferences_Save_OverwriteFast(t *testing.T) {
Expand Down Expand Up @@ -96,9 +96,9 @@ func TestPreferences_Load(t *testing.T) {
assert.Equal(t, []int{1, 2, 3}, p.IntList("keyIntList"))
assert.Equal(t, 3.5, p.Float("keyFloat"))
assert.Equal(t, []float64{1.1, 2.2, 3.3}, p.FloatList("keyFloatList"))
assert.Equal(t, true, p.Bool("keyBool"))
assert.True(t, p.Bool("keyBool"))
assert.Equal(t, []bool{true, false, true}, p.BoolList("keyBoolList"))
assert.Equal(t, 0, len(p.StringList("keyEmptyList")))
assert.Empty(t, p.StringList("keyEmptyList"))
}

func TestPreferences_EmptyLoad(t *testing.T) {
Expand Down
12 changes: 6 additions & 6 deletions app/settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,46 +106,46 @@ func TestCustomTheme(t *testing.T) {
set.SetTheme(ctheme)

set.setupTheme()
assert.True(t, set.Theme() == ctheme)
assert.Equal(t, set.Theme(), ctheme)
assert.Equal(t, internalapp.DefaultVariant(), set.ThemeVariant())

err := set.loadFromFile(filepath.Join("testdata", "light-theme.json"))
if err != nil {
t.Error(err)
}
set.setupTheme()
assert.True(t, set.Theme() == ctheme)
assert.Equal(t, set.Theme(), ctheme)
assert.Equal(t, theme.VariantLight, set.ThemeVariant())

err = set.loadFromFile(filepath.Join("testdata", "dark-theme.json"))
if err != nil {
t.Error(err)
}
set.setupTheme()
assert.True(t, set.Theme() == ctheme)
assert.Equal(t, set.Theme(), ctheme)
assert.Equal(t, theme.VariantDark, set.ThemeVariant())

err = os.Setenv("FYNE_THEME", "light")
if err != nil {
t.Error(err)
}
set.setupTheme()
assert.True(t, set.Theme() == ctheme)
assert.Equal(t, set.Theme(), ctheme)
assert.Equal(t, theme.VariantLight, set.ThemeVariant())

err = os.Setenv("FYNE_THEME", "dark")
if err != nil {
t.Error(err)
}
set.setupTheme()
assert.True(t, set.Theme() == ctheme)
assert.Equal(t, set.Theme(), ctheme)
assert.Equal(t, theme.VariantDark, set.ThemeVariant())

err = os.Setenv("FYNE_THEME", "")
if err != nil {
t.Error(err)
}
set.setupTheme()
assert.True(t, set.Theme() == ctheme)
assert.Equal(t, set.Theme(), ctheme)
assert.Equal(t, theme.VariantDark, set.ThemeVariant())
}
6 changes: 3 additions & 3 deletions app/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ func TestStore_RootURI(t *testing.T) {
d := makeStoreDocs(id, &store{a: a})

w, err := d.Create("test")
assert.Nil(t, err)
assert.NoError(t, err)
err = w.Close()
assert.Nil(t, err)
assert.NoError(t, err)
err = d.Remove("test")
assert.Nil(t, err)
assert.NoError(t, err)
}
4 changes: 2 additions & 2 deletions canvas/base_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ func TestBase_MinSize(t *testing.T) {
base := &baseObject{}
min := base.MinSize()

assert.True(t, min.Width > 0)
assert.True(t, min.Height > 0)
assert.Positive(t, min.Width)
assert.Positive(t, min.Height)
}

func TestBase_Move(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions canvas/circle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ func TestCircle_MinSize(t *testing.T) {
circle := canvas.NewCircle(color.Black)
min := circle.MinSize()

assert.True(t, min.Width > 0)
assert.True(t, min.Height > 0)
assert.Positive(t, min.Width)
assert.Positive(t, min.Height)
}

func TestCircle_FillColor(t *testing.T) {
Expand Down Expand Up @@ -44,9 +44,9 @@ func TestCircle_Move(t *testing.T) {
circle.Resize(fyne.NewSize(50, 50))

start := fyne.Position{X: 0, Y: 0}
assert.True(t, circle.Position() == start)
assert.Equal(t, circle.Position(), start)

target := fyne.Position{X: 10, Y: 75}
circle.Move(target)
assert.True(t, circle.Position() == target)
assert.Equal(t, circle.Position(), target)
}
21 changes: 10 additions & 11 deletions canvas/gradient_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package canvas_test

import (
"fmt"
"image"
"image/color"
"image/draw"
Expand All @@ -27,7 +26,7 @@ func TestNewHorizontalGradient(t *testing.T) {
}
for y, xv := range expectedAlphaValues {
for x, v := range xv {
assert.Equal(t, color.NRGBA{0, 0, 0, v}, smallImg.At(x, y), fmt.Sprintf("alpha value at %d,%d", x, y))
assert.Equal(t, color.NRGBA{0, 0, 0, v}, smallImg.At(x, y), "alpha value at %d,%d", x, y)
}
}

Expand All @@ -53,7 +52,7 @@ func TestNewHorizontalGradient_Flipped(t *testing.T) {
}
for y, xv := range expectedAlphaValues {
for x, v := range xv {
assert.Equal(t, color.NRGBA{0, 0, 0, v}, smallImg.At(x, y), fmt.Sprintf("alpha value at %d,%d", x, y))
assert.Equal(t, color.NRGBA{0, 0, 0, v}, smallImg.At(x, y), "alpha value at %d,%d", x, y)
}
}

Expand All @@ -78,7 +77,7 @@ func TestNewVerticalGradient(t *testing.T) {
}
for y, xv := range expectedAlphaValues {
for x, v := range xv {
assert.Equal(t, color.NRGBA{0, 0, 0, v}, smallImg.At(x, y), fmt.Sprintf("alpha value at %d,%d", x, y))
assert.Equal(t, color.NRGBA{0, 0, 0, v}, smallImg.At(x, y), "alpha value at %d,%d", x, y)
}
}

Expand All @@ -104,7 +103,7 @@ func TestNewVerticalGradient_Flipped(t *testing.T) {
}
for y, xv := range expectedAlphaValues {
for x, v := range xv {
assert.Equal(t, color.NRGBA{0, 0, 0, v}, smallImg.At(x, y), fmt.Sprintf("alpha value at %d,%d", x, y))
assert.Equal(t, color.NRGBA{0, 0, 0, v}, smallImg.At(x, y), "alpha value at %d,%d", x, y)
}
}

Expand All @@ -129,7 +128,7 @@ func TestNewLinearGradient_45(t *testing.T) {
}
for y, xv := range expectedAlphaValues {
for x, v := range xv {
assert.Equal(t, color.NRGBA{0, 0, 0, v}, smallImg.At(x, y), fmt.Sprintf("alpha value at %d,%d", x, y))
assert.Equal(t, color.NRGBA{0, 0, 0, v}, smallImg.At(x, y), "alpha value at %d,%d", x, y)
}
}

Expand All @@ -156,7 +155,7 @@ func TestNewLinearGradient_225(t *testing.T) {
}
for y, xv := range expectedAlphaValues {
for x, v := range xv {
assert.Equal(t, color.NRGBA{0, 0, 0, v}, smallImg.At(x, y), fmt.Sprintf("alpha value at %d,%d", x, y))
assert.Equal(t, color.NRGBA{0, 0, 0, v}, smallImg.At(x, y), "alpha value at %d,%d", x, y)
}
}

Expand All @@ -183,7 +182,7 @@ func TestNewLinearGradient_135(t *testing.T) {
}
for y, xv := range expectedAlphaValues {
for x, v := range xv {
assert.Equal(t, color.NRGBA{0, 0, 0, v}, smallImg.At(x, y), fmt.Sprintf("alpha value at %d,%d", x, y))
assert.Equal(t, color.NRGBA{0, 0, 0, v}, smallImg.At(x, y), "alpha value at %d,%d", x, y)
}
}

Expand All @@ -210,7 +209,7 @@ func TestNewLinearGradient_315(t *testing.T) {
}
for y, xv := range expectedAlphaValues {
for x, v := range xv {
assert.Equal(t, color.NRGBA{0, 0, 0, v}, smallImg.At(x, y), fmt.Sprintf("alpha value at %d,%d", x, y))
assert.Equal(t, color.NRGBA{0, 0, 0, v}, smallImg.At(x, y), "alpha value at %d,%d", x, y)
}
}

Expand Down Expand Up @@ -238,7 +237,7 @@ func TestNewRadialGradient(t *testing.T) {
}
for y, xv := range expectedAlphaValues {
for x, v := range xv {
assert.Equal(t, color.NRGBA{0, 0, 0, v}, imgOddDiameter.At(x, y), fmt.Sprintf("alpha value at %d,%d", x, y))
assert.Equal(t, color.NRGBA{0, 0, 0, v}, imgOddDiameter.At(x, y), "alpha value at %d,%d", x, y)
}
}
}
Expand All @@ -255,7 +254,7 @@ func TestNewRadialGradient(t *testing.T) {
}
for y, xv := range expectedAlphaValues {
for x, v := range xv {
assert.Equal(t, color.NRGBA{0, 0, 0, v}, imgEvenDiameter.At(x, y), fmt.Sprintf("alpha value at %d,%d", x, y))
assert.Equal(t, color.NRGBA{0, 0, 0, v}, imgEvenDiameter.At(x, y), "alpha value at %d,%d", x, y)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion canvas/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,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.Nil(t, err)
assert.NoError(t, err)
defer read.Close()

img := canvas.NewImageFromReader(read, "fyne.png")
Expand Down
4 changes: 2 additions & 2 deletions canvas/line_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ func TestLine_MinSize(t *testing.T) {
line := canvas.NewLine(color.Black)
min := line.MinSize()

assert.True(t, min.Width > 0)
assert.True(t, min.Height > 0)
assert.Positive(t, min.Width)
assert.Positive(t, min.Height)
}

func TestLine_Move(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions canvas/rectangle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ func TestRectangle_MinSize(t *testing.T) {
rect := canvas.NewRectangle(color.Black)
min := rect.MinSize()

assert.True(t, min.Width > 0)
assert.True(t, min.Height > 0)
assert.Positive(t, min.Width)
assert.Positive(t, min.Height)
}

func TestRectangle_FillColor(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions canvas/text_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ func TestText_MinSize(t *testing.T) {
text := canvas.NewText("Test", color.NRGBA{0, 0, 0, 0xff})
min := text.MinSize()

assert.True(t, min.Width > 0)
assert.True(t, min.Height > 0)
assert.Positive(t, min.Width)
assert.Positive(t, min.Height)

text = canvas.NewText("Test2", color.NRGBA{0, 0, 0, 0xff})
min2 := text.MinSize()
assert.True(t, min2.Width > min.Width)
assert.Greater(t, min2.Width, min.Width)
}

func TestText_MinSize_NoMultiLine(t *testing.T) {
Expand All @@ -47,7 +47,7 @@ func TestText_MinSize_NoMultiLine(t *testing.T) {

text = canvas.NewText("Bre\nak", color.NRGBA{0, 0, 0, 0xff})
min2 := text.MinSize()
assert.True(t, min2.Width > min.Width)
assert.Greater(t, min2.Width, min.Width)
assert.True(t, min2.Height == min.Height)
}

Expand Down
20 changes: 10 additions & 10 deletions container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ import (
func TestContainer_Add(t *testing.T) {
box := new(dummyObject)
container := NewContainerWithLayout(new(customLayout))
assert.Equal(t, 0, len(container.Objects))
assert.Empty(t, container.Objects)
assert.Equal(t, float32(10), container.MinSize().Width)
assert.Equal(t, float32(0), container.MinSize().Height)

container.Add(box)
assert.Equal(t, 1, len(container.Objects))
assert.Len(t, container.Objects, 1)
assert.Equal(t, float32(10), container.MinSize().Width)
assert.Equal(t, float32(10), container.MinSize().Height)

oldLength := len(container.Objects)
container.Add(nil)
assert.Equal(t, oldLength, len(container.Objects))
assert.Len(t, container.Objects, oldLength)

box2 := new(dummyObject)
container.Add(box2)
assert.Equal(t, 2, len(container.Objects))
assert.Len(t, container.Objects, 2)
assert.Equal(t, float32(10), container.MinSize().Width)
assert.Equal(t, float32(20), container.MinSize().Height)
assert.Equal(t, float32(0), box2.Position().X)
Expand Down Expand Up @@ -95,12 +95,12 @@ func TestContainer_Remove(t *testing.T) {
box1 := new(dummyObject)
box2 := new(dummyObject)
container := NewContainerWithLayout(new(customLayout), box1, box2)
assert.Equal(t, 2, len(container.Objects))
assert.Len(t, container.Objects, 2)
assert.Equal(t, float32(10), container.MinSize().Width)
assert.Equal(t, float32(20), container.MinSize().Height)

container.Remove(box1)
assert.Equal(t, 1, len(container.Objects))
assert.Len(t, container.Objects, 1)
assert.Equal(t, float32(10), container.MinSize().Width)
assert.Equal(t, float32(10), container.MinSize().Height)
assert.Equal(t, float32(0), box2.Position().X)
Expand All @@ -125,7 +125,7 @@ func TestContainer_Remove_Race(t *testing.T) {
}()
}
wg.Wait()
assert.Equal(t, 0, len(container.Objects))
assert.Empty(t, container.Objects)
}

func TestContainer_Add_Race(t *testing.T) {
Expand All @@ -139,17 +139,17 @@ func TestContainer_Add_Race(t *testing.T) {
}()
}
wg.Wait()
assert.Equal(t, 100, len(container.Objects))
assert.Len(t, container.Objects, 100)
}

func TestContainer_RemoveAll(t *testing.T) {
box1 := new(dummyObject)
box2 := new(dummyObject)
container := NewContainerWithLayout(new(customLayout), box1, box2)
assert.Equal(t, 2, len(container.Objects))
assert.Len(t, container.Objects, 2)

container.RemoveAll()
assert.Equal(t, 0, len(container.Objects))
assert.Empty(t, container.Objects)
}

func TestContainer_Show(t *testing.T) {
Expand Down
Loading

0 comments on commit 446f2a7

Please sign in to comment.