From b7d4be5fdd97de7dc6249619ca33c5bee3c95d5f Mon Sep 17 00:00:00 2001 From: Manuel Carmona Date: Wed, 21 Jun 2017 15:18:27 +0200 Subject: [PATCH] commit against tests run is fixed renamed tmpLinguist to repoLinguist and SimpleLinguistTestSuite to EnryTestSuit in common_test.go changed receiver's name for TestSuites to 's' fixed comments --- commit.go | 8 ++ common.go | 16 ++-- common_test.go | 69 ++++++++++++----- internal/code-generator/assets/commit.go.tmpl | 8 ++ internal/code-generator/generator/aliases.go | 2 +- .../code-generator/generator/documentation.go | 2 +- .../code-generator/generator/extensions.go | 2 +- .../code-generator/generator/filenames.go | 2 +- .../generator/generator_test.go | 74 +++++++++++-------- .../code-generator/generator/heuristics.go | 2 +- .../code-generator/generator/interpreters.go | 2 +- .../generator/linguist-commit.go | 17 +++++ .../code-generator/generator/samplesfreq.go | 2 +- .../generator/test_files/commit.gold | 8 ++ internal/code-generator/generator/types.go | 2 +- internal/code-generator/generator/vendor.go | 2 +- internal/code-generator/main.go | 12 ++- utils_test.go | 8 +- 18 files changed, 163 insertions(+), 75 deletions(-) create mode 100644 commit.go create mode 100644 internal/code-generator/assets/commit.go.tmpl create mode 100644 internal/code-generator/generator/linguist-commit.go create mode 100644 internal/code-generator/generator/test_files/commit.gold diff --git a/commit.go b/commit.go new file mode 100644 index 0000000..5aea131 --- /dev/null +++ b/commit.go @@ -0,0 +1,8 @@ +package enry + +// CODE GENERATED AUTOMATICALLY WITH gopkg.in/src-d/enry.v1/internal/code-generator +// THIS FILE SHOULD NOT BE EDITED BY HAND +// Extracted from github/linguist commit: b6460f8ed6b249281ada099ca28bd8f1230b8892 + +// linguist's commit from which files were generated. +var linguistCommit = "b6460f8ed6b249281ada099ca28bd8f1230b8892" diff --git a/common.go b/common.go index dd6f4b5..b9ecfb3 100644 --- a/common.go +++ b/common.go @@ -125,7 +125,7 @@ func GetLanguages(filename string, content []byte) []string { } // GetLanguagesByModeline returns a slice of possible languages for the given content, filename will be ignored. -// It is comply with the signature to be a Strategy type. +// It complies with the signature to be a Strategy type. func GetLanguagesByModeline(filename string, content []byte, candidates []string) []string { headFoot := getHeaderAndFooter(content) var languages []string @@ -185,7 +185,7 @@ var ( ) // GetLanguagesByEmacsModeline returns a slice of possible languages for the given content, filename and candidates -// will be ignored. It is comply with the signature to be a Strategy type. +// will be ignored. It complies with the signature to be a Strategy type. func GetLanguagesByEmacsModeline(filename string, content []byte, candidates []string) []string { matched := reEmacsModeline.FindAllSubmatch(content, -1) if matched == nil { @@ -211,7 +211,7 @@ func GetLanguagesByEmacsModeline(filename string, content []byte, candidates []s } // GetLanguagesByVimModeline returns a slice of possible languages for the given content, filename and candidates -// will be ignored. It is comply with the signature to be a Strategy type. +// will be ignored. It complies with the signature to be a Strategy type. func GetLanguagesByVimModeline(filename string, content []byte, candidates []string) []string { matched := reVimModeline.FindAllSubmatch(content, -1) if matched == nil { @@ -247,13 +247,13 @@ func GetLanguagesByVimModeline(filename string, content []byte, candidates []str } // GetLanguagesByFilename returns a slice of possible languages for the given filename, content and candidates -// will be ignored. It is comply with the signature to be a Strategy type. +// will be ignored. It complies with the signature to be a Strategy type. func GetLanguagesByFilename(filename string, content []byte, candidates []string) []string { return languagesByFilename[filepath.Base(filename)] } // GetLanguagesByShebang returns a slice of possible languages for the given content, filename and candidates -// will be ignored. It is comply with the signature to be a Strategy type. +// will be ignored. It complies with the signature to be a Strategy type. func GetLanguagesByShebang(filename string, content []byte, candidates []string) (languages []string) { interpreter := getInterpreter(content) return languagesByInterpreter[interpreter] @@ -333,7 +333,7 @@ func lookForMultilineExec(data []byte) string { } // GetLanguagesByExtension returns a slice of possible languages for the given filename, content and candidates -// will be ignored. It is comply with the signature to be a Strategy type. +// will be ignored. It complies with the signature to be a Strategy type. func GetLanguagesByExtension(filename string, content []byte, candidates []string) []string { if !strings.Contains(filename, ".") { return nil @@ -364,7 +364,7 @@ func getDotIndexes(filename string) []int { } // GetLanguagesByContent returns a slice of possible languages for the given content, filename and candidates -// will be ignored. It is comply with the signature to be a Strategy type. +// will be ignored. It complies with the signature to be a Strategy type. func GetLanguagesByContent(filename string, content []byte, candidates []string) []string { ext := strings.ToLower(filepath.Ext(filename)) fnMatcher, ok := contentMatchers[ext] @@ -376,7 +376,7 @@ func GetLanguagesByContent(filename string, content []byte, candidates []string) } // GetLanguagesByClassifier uses DefaultClassifier as a Classifier and returns a sorted slice of possible languages ordered by -// decreasing language's probability. If there are not candidates it returns nil. It is comply with the signature to be a Strategy type. +// decreasing language's probability. If there are not candidates it returns nil. It complies with the signature to be a Strategy type. func GetLanguagesByClassifier(filename string, content []byte, candidates []string) (languages []string) { if len(candidates) == 0 { return nil diff --git a/common_test.go b/common_test.go index 8ae456c..8be53a8 100644 --- a/common_test.go +++ b/common_test.go @@ -4,6 +4,7 @@ import ( "fmt" "io/ioutil" "os" + "os/exec" "path/filepath" "testing" @@ -11,15 +12,46 @@ import ( "github.com/stretchr/testify/suite" ) -type SimpleLinguistTestSuite struct { +const linguistURL = "https://github.com/github/linguist.git" + +type EnryTestSuite struct { suite.Suite + repoLinguist string } -func TestSimpleLinguistTestSuite(t *testing.T) { - suite.Run(t, new(SimpleLinguistTestSuite)) +func TestEnryTestSuite(t *testing.T) { + suite.Run(t, new(EnryTestSuite)) } -func (s *SimpleLinguistTestSuite) TestGetLanguage() { +func (s *EnryTestSuite) SetupSuite() { + var err error + s.repoLinguist, err = ioutil.TempDir("", "linguist-") + assert.NoError(s.T(), err) + + cmd := exec.Command("git", "clone", linguistURL, s.repoLinguist) + err = cmd.Run() + assert.NoError(s.T(), err) + + cwd, err := os.Getwd() + assert.NoError(s.T(), err) + + err = os.Chdir(s.repoLinguist) + assert.NoError(s.T(), err) + + cmd = exec.Command("git", "checkout", linguistCommit) + err = cmd.Run() + assert.NoError(s.T(), err) + + err = os.Chdir(cwd) + assert.NoError(s.T(), err) +} + +func (s *EnryTestSuite) TearDownSuite() { + err := os.RemoveAll(s.repoLinguist) + assert.NoError(s.T(), err) +} + +func (s *EnryTestSuite) TestGetLanguage() { tests := []struct { name string filename string @@ -38,7 +70,7 @@ func (s *SimpleLinguistTestSuite) TestGetLanguage() { } } -func (s *SimpleLinguistTestSuite) TestGetLanguagesByModelineLinguist() { +func (s *EnryTestSuite) TestGetLanguagesByModelineLinguist() { const ( modelinesDir = ".linguist/test/fixtures/Data/Modelines" samplesDir = ".linguist/samples" @@ -95,7 +127,7 @@ func (s *SimpleLinguistTestSuite) TestGetLanguagesByModelineLinguist() { } } -func (s *SimpleLinguistTestSuite) TestGetLanguagesByModeline() { +func (s *EnryTestSuite) TestGetLanguagesByModeline() { const ( wrongVim = `# vim: set syntax=ruby ft =python filetype=perl :` rightVim = `/* vim: set syntax=python ft =python filetype=python */` @@ -120,7 +152,7 @@ func (s *SimpleLinguistTestSuite) TestGetLanguagesByModeline() { } } -func (s *SimpleLinguistTestSuite) TestGetLanguagesByFilename() { +func (s *EnryTestSuite) TestGetLanguagesByFilename() { tests := []struct { name string filename string @@ -144,7 +176,7 @@ func (s *SimpleLinguistTestSuite) TestGetLanguagesByFilename() { } } -func (s *SimpleLinguistTestSuite) TestGetLanguagesByShebang() { +func (s *EnryTestSuite) TestGetLanguagesByShebang() { const ( multilineExecHack = `#!/bin/sh # Next line is comment in Tcl, but not in sh... \ @@ -185,7 +217,7 @@ println("The shell script says ",vm.arglist.concat(" "));` } } -func (s *SimpleLinguistTestSuite) TestGetLanguagesByExtension() { +func (s *EnryTestSuite) TestGetLanguagesByExtension() { tests := []struct { name string filename string @@ -204,7 +236,7 @@ func (s *SimpleLinguistTestSuite) TestGetLanguagesByExtension() { } } -func (s *SimpleLinguistTestSuite) TestGetLanguagesByClassifier() { +func (s *EnryTestSuite) TestGetLanguagesByClassifier() { const samples = `.linguist/samples/` test := []struct { name string @@ -236,7 +268,7 @@ func (s *SimpleLinguistTestSuite) TestGetLanguagesByClassifier() { } } -func (s *SimpleLinguistTestSuite) TestGetLanguagesBySpecificClassifier() { +func (s *EnryTestSuite) TestGetLanguagesBySpecificClassifier() { const samples = `.linguist/samples/` test := []struct { name string @@ -270,7 +302,7 @@ func (s *SimpleLinguistTestSuite) TestGetLanguagesBySpecificClassifier() { } } -func (s *SimpleLinguistTestSuite) TestGetLanguageExtensions() { +func (s *EnryTestSuite) TestGetLanguageExtensions() { tests := []struct { name string language string @@ -287,7 +319,7 @@ func (s *SimpleLinguistTestSuite) TestGetLanguageExtensions() { } } -func (s *SimpleLinguistTestSuite) TestGetLanguageType() { +func (s *EnryTestSuite) TestGetLanguageType() { tests := []struct { name string language string @@ -310,7 +342,7 @@ func (s *SimpleLinguistTestSuite) TestGetLanguageType() { } } -func (s *SimpleLinguistTestSuite) TestGetLanguageByAlias() { +func (s *EnryTestSuite) TestGetLanguageByAlias() { tests := []struct { name string alias string @@ -336,12 +368,9 @@ func (s *SimpleLinguistTestSuite) TestGetLanguageByAlias() { } } -func (s *SimpleLinguistTestSuite) TestLinguistCorpus() { - const ( - samplesDir = ".linguist/samples" - filenamesDir = "filenames" - ) - +func (s *EnryTestSuite) TestLinguistCorpus() { + const filenamesDir = "filenames" + var samplesDir = filepath.Join(s.repoLinguist, "samples") var cornerCases = map[string]bool{ "hello.ms": true, } diff --git a/internal/code-generator/assets/commit.go.tmpl b/internal/code-generator/assets/commit.go.tmpl new file mode 100644 index 0000000..d670c7e --- /dev/null +++ b/internal/code-generator/assets/commit.go.tmpl @@ -0,0 +1,8 @@ +package enry + +// CODE GENERATED AUTOMATICALLY WITH gopkg.in/src-d/enry.v1/internal/code-generator +// THIS FILE SHOULD NOT BE EDITED BY HAND +// Extracted from github/linguist commit: {{ . }} + +// linguist's commit from which files were generated. +var linguistCommit = "{{- . -}}" diff --git a/internal/code-generator/generator/aliases.go b/internal/code-generator/generator/aliases.go index 2f2a968..91d6def 100644 --- a/internal/code-generator/generator/aliases.go +++ b/internal/code-generator/generator/aliases.go @@ -10,7 +10,7 @@ import ( yaml "gopkg.in/yaml.v2" ) -// Aliases reads from fileToParse and builds source file from tmplPath. It's comply with type File signature. +// Aliases reads from fileToParse and builds source file from tmplPath. It complies with type File signature. func Aliases(fileToParse, samplesDir, outPath, tmplPath, tmplName, commit string) error { data, err := ioutil.ReadFile(fileToParse) if err != nil { diff --git a/internal/code-generator/generator/documentation.go b/internal/code-generator/generator/documentation.go index c2436be..2407f6d 100644 --- a/internal/code-generator/generator/documentation.go +++ b/internal/code-generator/generator/documentation.go @@ -9,7 +9,7 @@ import ( yaml "gopkg.in/yaml.v2" ) -// Documentation reads from fileToParse and builds source file from tmplPath. It's comply with type File signature. +// Documentation reads from fileToParse and builds source file from tmplPath. It complies with type File signature. func Documentation(fileToParse, samplesDir, outPath, tmplPath, tmplName, commit string) error { data, err := ioutil.ReadFile(fileToParse) if err != nil { diff --git a/internal/code-generator/generator/extensions.go b/internal/code-generator/generator/extensions.go index d87e1fb..34c34fd 100644 --- a/internal/code-generator/generator/extensions.go +++ b/internal/code-generator/generator/extensions.go @@ -15,7 +15,7 @@ type extensionsInfo struct { ExtensionsByLanguage map[string][]string } -// Extensions reads from fileToParse and builds source file from tmplPath. It's comply with type File signature. +// Extensions reads from fileToParse and builds source file from tmplPath. It complies with type File signature. func Extensions(fileToParse, samplesDir, outPath, tmplPath, tmplName, commit string) error { data, err := ioutil.ReadFile(fileToParse) if err != nil { diff --git a/internal/code-generator/generator/filenames.go b/internal/code-generator/generator/filenames.go index 55de8ef..1508390 100644 --- a/internal/code-generator/generator/filenames.go +++ b/internal/code-generator/generator/filenames.go @@ -12,7 +12,7 @@ import ( yaml "gopkg.in/yaml.v2" ) -// Filenames reads from fileToParse and builds source file from tmplPath. It's comply with type File signature. +// Filenames reads from fileToParse and builds source file from tmplPath. It complies with type File signature. func Filenames(fileToParse, samplesDir, outPath, tmplPath, tmplName, commit string) error { data, err := ioutil.ReadFile(fileToParse) if err != nil { diff --git a/internal/code-generator/generator/generator_test.go b/internal/code-generator/generator/generator_test.go index a326536..b000ca2 100644 --- a/internal/code-generator/generator/generator_test.go +++ b/internal/code-generator/generator/generator_test.go @@ -65,6 +65,11 @@ const ( frequenciesGold = "test_files/frequencies.gold" frequenciesTestTmplPath = "../assets/frequencies.go.tmpl" frequenciesTestTmplName = "frequencies.go.tmpl" + + // commit test + commitGold = "test_files/commit.gold" + commitTestTmplPath = "../assets/commit.go.tmpl" + commitTestTmplName = "commit.go.tmpl" ) type GeneratorTestSuite struct { @@ -76,35 +81,35 @@ func TestGeneratorTestSuite(t *testing.T) { suite.Run(t, new(GeneratorTestSuite)) } -func (g *GeneratorTestSuite) SetupSuite() { - tmpLinguist, err := ioutil.TempDir("", "linguist-") - assert.NoError(g.T(), err) - g.tmpLinguist = tmpLinguist +func (s *GeneratorTestSuite) SetupSuite() { + var err error + s.tmpLinguist, err = ioutil.TempDir("", "linguist-") + assert.NoError(s.T(), err) - cmd := exec.Command("git", "clone", lingustURL, tmpLinguist) + cmd := exec.Command("git", "clone", lingustURL, s.tmpLinguist) err = cmd.Run() - assert.NoError(g.T(), err) + assert.NoError(s.T(), err) cwd, err := os.Getwd() - assert.NoError(g.T(), err) + assert.NoError(s.T(), err) - err = os.Chdir(tmpLinguist) - assert.NoError(g.T(), err) + err = os.Chdir(s.tmpLinguist) + assert.NoError(s.T(), err) cmd = exec.Command("git", "checkout", commit) err = cmd.Run() - assert.NoError(g.T(), err) + assert.NoError(s.T(), err) err = os.Chdir(cwd) - assert.NoError(g.T(), err) + assert.NoError(s.T(), err) } -func (g *GeneratorTestSuite) TearDownSuite() { - err := os.RemoveAll(g.tmpLinguist) - assert.NoError(g.T(), err) +func (s *GeneratorTestSuite) TearDownSuite() { + err := os.RemoveAll(s.tmpLinguist) + assert.NoError(s.T(), err) } -func (g *GeneratorTestSuite) TestGenerationFiles() { +func (s *GeneratorTestSuite) TestGenerationFiles() { tests := []struct { name string fileToParse string @@ -117,7 +122,7 @@ func (g *GeneratorTestSuite) TestGenerationFiles() { }{ { name: "Extensions()", - fileToParse: filepath.Join(g.tmpLinguist, languagesFile), + fileToParse: filepath.Join(s.tmpLinguist, languagesFile), samplesDir: "", tmplPath: extensionTestTmplPath, tmplName: extensionTestTmplName, @@ -127,7 +132,7 @@ func (g *GeneratorTestSuite) TestGenerationFiles() { }, { name: "Heuristics()", - fileToParse: filepath.Join(g.tmpLinguist, heuristicsTestFile), + fileToParse: filepath.Join(s.tmpLinguist, heuristicsTestFile), samplesDir: "", tmplPath: contentTestTmplPath, tmplName: contentTestTmplName, @@ -137,7 +142,7 @@ func (g *GeneratorTestSuite) TestGenerationFiles() { }, { name: "Vendor()", - fileToParse: filepath.Join(g.tmpLinguist, vendorTestFile), + fileToParse: filepath.Join(s.tmpLinguist, vendorTestFile), samplesDir: "", tmplPath: vendorTestTmplPath, tmplName: vendorTestTmplName, @@ -147,7 +152,7 @@ func (g *GeneratorTestSuite) TestGenerationFiles() { }, { name: "Documentation()", - fileToParse: filepath.Join(g.tmpLinguist, documentationTestFile), + fileToParse: filepath.Join(s.tmpLinguist, documentationTestFile), samplesDir: "", tmplPath: documentationTestTmplPath, tmplName: documentationTestTmplName, @@ -157,7 +162,7 @@ func (g *GeneratorTestSuite) TestGenerationFiles() { }, { name: "Types()", - fileToParse: filepath.Join(g.tmpLinguist, languagesFile), + fileToParse: filepath.Join(s.tmpLinguist, languagesFile), samplesDir: "", tmplPath: typeTestTmplPath, tmplName: typeTestTmplName, @@ -167,7 +172,7 @@ func (g *GeneratorTestSuite) TestGenerationFiles() { }, { name: "Interpreters()", - fileToParse: filepath.Join(g.tmpLinguist, languagesFile), + fileToParse: filepath.Join(s.tmpLinguist, languagesFile), samplesDir: "", tmplPath: interpreterTestTmplPath, tmplName: interpreterTestTmplName, @@ -177,8 +182,8 @@ func (g *GeneratorTestSuite) TestGenerationFiles() { }, { name: "Filenames()", - fileToParse: filepath.Join(g.tmpLinguist, languagesFile), - samplesDir: filepath.Join(g.tmpLinguist, samplesDir), + fileToParse: filepath.Join(s.tmpLinguist, languagesFile), + samplesDir: filepath.Join(s.tmpLinguist, samplesDir), tmplPath: filenameTestTmplPath, tmplName: filenameTestTmplName, commit: commit, @@ -187,7 +192,7 @@ func (g *GeneratorTestSuite) TestGenerationFiles() { }, { name: "Aliases()", - fileToParse: filepath.Join(g.tmpLinguist, languagesFile), + fileToParse: filepath.Join(s.tmpLinguist, languagesFile), samplesDir: "", tmplPath: aliasTestTmplPath, tmplName: aliasTestTmplName, @@ -197,27 +202,36 @@ func (g *GeneratorTestSuite) TestGenerationFiles() { }, { name: "Frequencies()", - samplesDir: filepath.Join(g.tmpLinguist, samplesDir), + samplesDir: filepath.Join(s.tmpLinguist, samplesDir), tmplPath: frequenciesTestTmplPath, tmplName: frequenciesTestTmplName, commit: commit, generate: Frequencies, wantOut: frequenciesGold, }, + { + name: "Commit()", + samplesDir: "", + tmplPath: commitTestTmplPath, + tmplName: commitTestTmplName, + commit: commit, + generate: Commit, + wantOut: commitGold, + }, } for _, test := range tests { gold, err := ioutil.ReadFile(test.wantOut) - assert.NoError(g.T(), err) + assert.NoError(s.T(), err) outPath, err := ioutil.TempFile("/tmp", "generator-test-") - assert.NoError(g.T(), err) + assert.NoError(s.T(), err) defer os.Remove(outPath.Name()) err = test.generate(test.fileToParse, test.samplesDir, outPath.Name(), test.tmplPath, test.tmplName, test.commit) - assert.NoError(g.T(), err) + assert.NoError(s.T(), err) out, err := ioutil.ReadFile(outPath.Name()) - assert.NoError(g.T(), err) - assert.EqualValues(g.T(), gold, out, fmt.Sprintf("%v: %v, expected: %v", test.name, string(out), string(gold))) + assert.NoError(s.T(), err) + assert.EqualValues(s.T(), gold, out, fmt.Sprintf("%v: %v, expected: %v", test.name, string(out), string(gold))) } } diff --git a/internal/code-generator/generator/heuristics.go b/internal/code-generator/generator/heuristics.go index e8d517c..068a242 100644 --- a/internal/code-generator/generator/heuristics.go +++ b/internal/code-generator/generator/heuristics.go @@ -12,7 +12,7 @@ import ( "text/template" ) -// Heuristics reads from fileToParse and builds source file from tmplPath. It's comply with type File signature. +// Heuristics reads from fileToParse and builds source file from tmplPath. It complies with type File signature. func Heuristics(fileToParse, samplesDir, outPath, tmplPath, tmplName, commit string) error { data, err := ioutil.ReadFile(fileToParse) if err != nil { diff --git a/internal/code-generator/generator/interpreters.go b/internal/code-generator/generator/interpreters.go index 23c3330..e9b1895 100644 --- a/internal/code-generator/generator/interpreters.go +++ b/internal/code-generator/generator/interpreters.go @@ -10,7 +10,7 @@ import ( "gopkg.in/yaml.v2" ) -// Interpreters reads from fileToParse and builds source file from tmplPath. It's comply with type File signature. +// Interpreters reads from fileToParse and builds source file from tmplPath. It complies with type File signature. func Interpreters(fileToParse, samplesDir, outPath, tmplPath, tmplName, commit string) error { data, err := ioutil.ReadFile(fileToParse) if err != nil { diff --git a/internal/code-generator/generator/linguist-commit.go b/internal/code-generator/generator/linguist-commit.go new file mode 100644 index 0000000..e7d9899 --- /dev/null +++ b/internal/code-generator/generator/linguist-commit.go @@ -0,0 +1,17 @@ +package generator + +import ( + "bytes" + "text/template" +) + +// Commit takes a commit and builds the source file from tmplPath. It complies with type File signature. +func Commit(fileToParse, samplesDir, outPath, tmplPath, tmplName, commit string) error { + buf := &bytes.Buffer{} + t := template.Must(template.New(tmplName).ParseFiles(tmplPath)) + if err := t.Execute(buf, commit); err != nil { + return err + } + + return formatedWrite(outPath, buf.Bytes()) +} diff --git a/internal/code-generator/generator/samplesfreq.go b/internal/code-generator/generator/samplesfreq.go index 7e03caa..e82036f 100644 --- a/internal/code-generator/generator/samplesfreq.go +++ b/internal/code-generator/generator/samplesfreq.go @@ -25,7 +25,7 @@ type samplesFrequencies struct { } // Frequencies reads directories in samplesDir, retrieves information about frequencies of languages and tokens, and write -// the file outPath using tmplName as a template. +// the file outPath using tmplName as a template. It complies with type File signature. func Frequencies(fileToParse, samplesDir, outPath, tmplPath, tmplName, commit string) error { freqs, err := getFrequencies(samplesDir) if err != nil { diff --git a/internal/code-generator/generator/test_files/commit.gold b/internal/code-generator/generator/test_files/commit.gold new file mode 100644 index 0000000..5aea131 --- /dev/null +++ b/internal/code-generator/generator/test_files/commit.gold @@ -0,0 +1,8 @@ +package enry + +// CODE GENERATED AUTOMATICALLY WITH gopkg.in/src-d/enry.v1/internal/code-generator +// THIS FILE SHOULD NOT BE EDITED BY HAND +// Extracted from github/linguist commit: b6460f8ed6b249281ada099ca28bd8f1230b8892 + +// linguist's commit from which files were generated. +var linguistCommit = "b6460f8ed6b249281ada099ca28bd8f1230b8892" diff --git a/internal/code-generator/generator/types.go b/internal/code-generator/generator/types.go index dce3260..47d0b48 100644 --- a/internal/code-generator/generator/types.go +++ b/internal/code-generator/generator/types.go @@ -16,7 +16,7 @@ var typeToTypeConst = map[string]string{ "prose": "Prose", } -// Types reads from fileToParse and builds source file from tmplPath. It's comply with type File signature. +// Types reads from fileToParse and builds source file from tmplPath. It complies with type File signature. func Types(fileToParse, samplesDir, outPath, tmplPath, tmplName, commit string) error { data, err := ioutil.ReadFile(fileToParse) if err != nil { diff --git a/internal/code-generator/generator/vendor.go b/internal/code-generator/generator/vendor.go index 98e0c88..e6d1880 100644 --- a/internal/code-generator/generator/vendor.go +++ b/internal/code-generator/generator/vendor.go @@ -9,7 +9,7 @@ import ( yaml "gopkg.in/yaml.v2" ) -// Vendor reads from fileToParse and builds source file from tmplPath. It's comply with type File signature. +// Vendor reads from fileToParse and builds source file from tmplPath. It complies with type File signature. func Vendor(fileToParse, samplesDir, outPath, tmplPath, tmplName, commit string) error { data, err := ioutil.ReadFile(fileToParse) if err != nil { diff --git a/internal/code-generator/main.go b/internal/code-generator/main.go index 1f26091..7edbebf 100644 --- a/internal/code-generator/main.go +++ b/internal/code-generator/main.go @@ -62,6 +62,11 @@ const ( frequenciesTmplPath = "internal/code-generator/assets/frequencies.go.tmpl" frequenciesTmpl = "frequencies.go.tmpl" + // commit.go generation + commitFile = "commit.go" + commitTmplPath = "internal/code-generator/assets/commit.go.tmpl" + commitTmpl = "commit.go.tmpl" + commitPath = ".linguist/.git/HEAD" ) @@ -91,6 +96,7 @@ func main() { &generatorFiles{generator.Filenames, languagesYAML, samplesDir, filenamesFile, filenamesTmplPath, filenamesTmpl, commit}, &generatorFiles{generator.Aliases, languagesYAML, "", aliasesFile, aliasesTmplPath, aliasesTmpl, commit}, &generatorFiles{generator.Frequencies, "", samplesDir, frequenciesFile, frequenciesTmplPath, frequenciesTmpl, commit}, + &generatorFiles{generator.Commit, "", "", commitFile, commitTmplPath, commitTmpl, commit}, } for _, file := range fileList { @@ -108,13 +114,11 @@ func getCommit(path string) (string, error) { if string(commit) == "ref: refs/heads/master\n" { path = ".linguist/.git/" + string(commit[5:len(commit)-1]) - commit, err := ioutil.ReadFile(path) + commit, err = ioutil.ReadFile(path) if err != nil { return "", err } - - return string(commit), nil } - return string(commit), nil + return string(commit[:len(commit)-1]), nil } diff --git a/utils_test.go b/utils_test.go index 32fa2e6..682c731 100644 --- a/utils_test.go +++ b/utils_test.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/assert" ) -func (s *SimpleLinguistTestSuite) TestIsVendor() { +func (s *EnryTestSuite) TestIsVendor() { tests := []struct { name string path string @@ -31,7 +31,7 @@ func (s *SimpleLinguistTestSuite) TestIsVendor() { } } -func (s *SimpleLinguistTestSuite) TestIsDocumentation() { +func (s *EnryTestSuite) TestIsDocumentation() { tests := []struct { name string path string @@ -47,7 +47,7 @@ func (s *SimpleLinguistTestSuite) TestIsDocumentation() { } } -func (s *SimpleLinguistTestSuite) TestIsConfiguration() { +func (s *EnryTestSuite) TestIsConfiguration() { tests := []struct { name string path string @@ -64,7 +64,7 @@ func (s *SimpleLinguistTestSuite) TestIsConfiguration() { } } -func (s *SimpleLinguistTestSuite) TestIsBinary() { +func (s *EnryTestSuite) TestIsBinary() { tests := []struct { name string data []byte