github.com/vanstinator/golangci-lint@v0.0.0-20240223191551-cc572f00d9d1/test/testdata/testifylint_config.go (about)

     1  //golangcitest:args -Etestifylint
     2  //golangcitest:config_path testdata/configs/testifylint.yml
     3  package testdata
     4  
     5  import (
     6  	"io"
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/assert"
    10  	"github.com/stretchr/testify/require"
    11  	"github.com/stretchr/testify/suite"
    12  )
    13  
    14  func TestTestifylint(t *testing.T) {
    15  	var (
    16  		predicate   bool
    17  		resultInt   int
    18  		resultFloat float64
    19  		arr         []string
    20  		err         error
    21  	)
    22  
    23  	assert.Equal(t, predicate, true)
    24  	assert.True(t, resultInt == 1)
    25  	assert.Equal(t, len(arr), 0)
    26  	assert.Error(t, err, io.EOF)
    27  	assert.Nil(t, err)
    28  	assert.Equal(t, resultInt, 42)
    29  	assert.Equal(t, resultFloat, 42.42)
    30  	assert.Equal(t, len(arr), 10)
    31  
    32  	assert.True(t, predicate)
    33  	assert.Equal(t, resultInt, 1)
    34  	assert.Empty(t, arr)
    35  	assert.ErrorIs(t, err, io.EOF)
    36  	assert.NoError(t, err) // want "require-error: for error assertions use require"
    37  	assert.Equal(t, 42, resultInt)
    38  	assert.NoErrorf(t, err, "boom!")
    39  	assert.InEpsilon(t, 42.42, resultFloat, 0.0001)
    40  	assert.Len(t, arr, 10)
    41  
    42  	require.ErrorIs(t, err, io.EOF)
    43  	require.NoError(t, err)
    44  
    45  	t.Run("formatted", func(t *testing.T) {
    46  		assert.Equal(t, predicate, true, "message")
    47  		assert.Equal(t, predicate, true, "message %d", 42)
    48  		assert.Equalf(t, predicate, true, "message")
    49  		assert.Equalf(t, predicate, true, "message %d", 42)
    50  	})
    51  
    52  	assert.Equal(t, arr, nil)
    53  	assert.Nil(t, arr)
    54  
    55  	go func() {
    56  		if assert.Error(t, err) {
    57  			require.ErrorIs(t, err, io.EOF)
    58  		}
    59  	}()
    60  }
    61  
    62  type SuiteExample struct {
    63  	suite.Suite
    64  }
    65  
    66  func TestSuiteExample(t *testing.T) {
    67  	suite.Run(t, new(SuiteExample))
    68  }
    69  
    70  func (s *SuiteExample) TestAll() {
    71  	var b bool
    72  	s.Assert().True(b)
    73  }