github.com/elek/golangci-lint@v1.42.2-0.20211208090441-c05b7fcb3a9a/pkg/result/processors/autogenerated_exclude_test.go (about) 1 package processors 2 3 import ( 4 "path/filepath" 5 "strings" 6 "testing" 7 8 "github.com/stretchr/testify/assert" 9 ) 10 11 func TestIsAutogeneratedDetection(t *testing.T) { 12 all := ` 13 // generated by stringer -type Pill pill.go; DO NOT EDIT 14 15 // Code generated by "stringer -type Pill pill.go"; DO NOT EDIT 16 17 // Code generated by vfsgen; DO NOT EDIT 18 19 // Created by cgo -godefs - DO NOT EDIT 20 21 /* Created by cgo - DO NOT EDIT. */ 22 23 // Generated by stringer -i a.out.go -o anames.go -p ppc64 24 // Do not edit. 25 26 // DO NOT EDIT 27 // generated by: x86map -fmt=decoder ../x86.csv 28 29 // DO NOT EDIT. 30 // Generate with: go run gen.go -full -output md5block.go 31 32 // generated by "go run gen.go". DO NOT EDIT. 33 34 // DO NOT EDIT. This file is generated by mksyntaxgo from the RE2 distribution. 35 36 // GENERATED BY make_perl_groups.pl; DO NOT EDIT. 37 38 // generated by mknacl.sh - do not edit 39 40 // DO NOT EDIT ** This file was generated with the bake tool ** DO NOT EDIT // 41 42 // Generated by running 43 // maketables --tables=all --data=http://www.unicode.org/Public/8.0.0/ucd/UnicodeData.txt 44 // --casefolding=http://www.unicode.org/Public/8.0.0/ucd/CaseFolding.txt 45 // DO NOT EDIT 46 47 /* 48 * CODE GENERATED AUTOMATICALLY WITH github.com/ernesto-jimenez/gogen/unmarshalmap 49 * THIS FILE SHOULD NOT BE EDITED BY HAND 50 */ 51 52 // AUTOGENERATED FILE: easyjson file.go 53 ` 54 55 generatedCases := strings.Split(all, "\n\n") 56 for _, gc := range generatedCases { 57 isGenerated := isGeneratedFileByComment(gc) 58 assert.True(t, isGenerated) 59 } 60 61 notGeneratedCases := []string{ 62 "code not generated by", 63 "test", 64 } 65 for _, ngc := range notGeneratedCases { 66 isGenerated := isGeneratedFileByComment(ngc) 67 assert.False(t, isGenerated) 68 } 69 } 70 71 func TestGetDoc(t *testing.T) { 72 testCases := []struct { 73 fpath string 74 doc string 75 }{ 76 { 77 fpath: filepath.Join("testdata", "autogen_exclude.go"), 78 doc: `first line 79 second line 80 third line 81 this text also 82 and this text also`, 83 }, 84 { 85 fpath: filepath.Join("testdata", "autogen_exclude_doc.go"), 86 doc: `DO NOT EDIT`, 87 }, 88 { 89 fpath: filepath.Join("testdata", "autogen_exclude_block_comment.go"), 90 doc: `* first line 91 * 92 * second line 93 * third line 94 and this text also 95 this type of block comment also 96 this one line comment also`, 97 }, 98 } 99 100 for _, tc := range testCases { 101 doc, err := getDoc(tc.fpath) 102 assert.NoError(t, err) 103 assert.Equal(t, tc.doc, doc) 104 } 105 } 106 107 // Issue 954: Some lines can be very long, e.g. auto-generated 108 // embedded resources. Reported on file of 86.2KB. 109 func TestGetDocFileWithLongLine(t *testing.T) { 110 fpath := filepath.Join("testdata", "autogen_exclude_long_line.go") 111 _, err := getDoc(fpath) 112 assert.NoError(t, err) 113 }