mirror of
https://github.com/ralsina/tartrazine.git
synced 2025-06-19 06:33:06 -03:00
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
This commit is contained in:
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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)))
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
17
internal/code-generator/generator/linguist-commit.go
Normal file
17
internal/code-generator/generator/linguist-commit.go
Normal file
@ -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())
|
||||
}
|
@ -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 {
|
||||
|
8
internal/code-generator/generator/test_files/commit.gold
Normal file
8
internal/code-generator/generator/test_files/commit.gold
Normal file
@ -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"
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
Reference in New Issue
Block a user