github.com/elek/golangci-lint@v1.42.2-0.20211208090441-c05b7fcb3a9a/pkg/config/linters_settings_gocritic_test.go (about)

     1  package config
     2  
     3  import (
     4  	"fmt"
     5  	"sort"
     6  	"testing"
     7  
     8  	"github.com/stretchr/testify/assert"
     9  
    10  	"github.com/elek/golangci-lint/pkg/logutils"
    11  )
    12  
    13  func TestUtils(t *testing.T) {
    14  	s1 := []string{"diagnostic", "experimental", "opinionated"}
    15  	s2 := []string{"opinionated", "experimental"}
    16  	s3 := intersectStringSlice(s1, s2)
    17  	sort.Strings(s3)
    18  	assert.Equal(t, s3, []string{"experimental", "opinionated"})
    19  }
    20  
    21  type tLog struct{}
    22  
    23  func (l *tLog) Fatalf(format string, args ...interface{}) {
    24  	fmt.Printf(fmt.Sprintf(format, args...) + "\n")
    25  }
    26  
    27  func (l *tLog) Panicf(format string, args ...interface{}) {
    28  	fmt.Printf(fmt.Sprintf(format, args...) + "\n")
    29  }
    30  
    31  func (l *tLog) Errorf(format string, args ...interface{}) {
    32  	fmt.Printf(fmt.Sprintf(format, args...) + "\n")
    33  }
    34  
    35  func (l *tLog) Warnf(format string, args ...interface{}) {
    36  	fmt.Printf(fmt.Sprintf(format, args...) + "\n")
    37  }
    38  
    39  func (l *tLog) Infof(format string, args ...interface{}) {
    40  	fmt.Printf(fmt.Sprintf(format, args...) + "\n")
    41  }
    42  
    43  func (l *tLog) Child(name string) logutils.Log { return nil }
    44  
    45  func (l *tLog) SetLevel(level logutils.LogLevel) {}
    46  
    47  func TestFilterByDisableTags(t *testing.T) {
    48  	testLog := &tLog{}
    49  	disabledTags := []string{"experimental", "opinionated"}
    50  	enabledChecks := []string{"appendAssign", "sortSlice", "caseOrder", "dupImport"}
    51  	filterEnabledChecks := filterByDisableTags(enabledChecks, disabledTags, testLog)
    52  	sort.Strings(filterEnabledChecks)
    53  	assert.Equal(t, []string{"appendAssign", "caseOrder"}, filterEnabledChecks)
    54  }