github.com/chenfeining/golangci-lint@v1.0.2-0.20230730162517-14c6c67868df/pkg/golinters/gocritic_test.go (about)

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