github.com/vanstinator/golangci-lint@v0.0.0-20240223191551-cc572f00d9d1/test/testshared/directives_test.go (about) 1 package testshared 2 3 import ( 4 "runtime" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 "github.com/stretchr/testify/require" 9 10 "github.com/vanstinator/golangci-lint/pkg/exitcodes" 11 ) 12 13 func TestParseTestDirectives(t *testing.T) { 14 rc := ParseTestDirectives(t, "./testdata/all.go") 15 require.NotNil(t, rc) 16 17 expected := &RunContext{ 18 Args: []string{"-Efoo", "--simple", "--hello=world"}, 19 ConfigPath: "testdata/example.yml", 20 ExpectedLinter: "bar", 21 ExitCode: exitcodes.Success, 22 } 23 assert.Equal(t, expected, rc) 24 } 25 26 func Test_evaluateBuildTags(t *testing.T) { 27 testCases := []struct { 28 desc string 29 tag string 30 assert assert.BoolAssertionFunc 31 }{ 32 { 33 desc: "old build tag syntax, version inside the range", 34 tag: "// +build go1.18", 35 assert: assert.True, 36 }, 37 { 38 desc: "old build tag syntax, version outside the range", 39 tag: "// +build go1.42", 40 assert: assert.False, 41 }, 42 { 43 desc: "version inside the range", 44 tag: "//go:build go1.18", 45 assert: assert.True, 46 }, 47 { 48 desc: "version outside the range", 49 tag: "//go:build go1.42", 50 assert: assert.False, 51 }, 52 { 53 desc: "supported OS", 54 tag: "//go:build " + runtime.GOOS, 55 assert: assert.True, 56 }, 57 { 58 desc: "negate unsupported OS", 59 tag: "//go:build !wondiws", 60 assert: assert.True, 61 }, 62 { 63 desc: "unsupported OS", 64 tag: "//go:build wondiws", 65 assert: assert.False, 66 }, 67 { 68 desc: "version inside the range and supported OS", 69 tag: "//go:build go1.18 && " + runtime.GOOS, 70 assert: assert.True, 71 }, 72 } 73 74 for _, test := range testCases { 75 test := test 76 t.Run(test.desc, func(t *testing.T) { 77 t.Parallel() 78 79 test.assert(t, evaluateBuildTags(t, test.tag)) 80 }) 81 } 82 }