github.com/vanstinator/golangci-lint@v0.0.0-20240223191551-cc572f00d9d1/pkg/golinters/gocritic_test.go (about)

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